2 /************************************************************************
3 * MXChange v0.2.1 Start: 10/11/2004 *
4 * ================ Last change: 10/11/2004 *
6 * -------------------------------------------------------------------- *
7 * File : ext-cache.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Caching system for SQL tables on hard disc *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Caching-System zum Auslagern von SQL-Tabellen *
12 * auf der Festplatte des Servers *
13 * -------------------------------------------------------------------- *
16 * $Tag:: 0.2.1-FINAL $ *
18 * Needs to be in all Files and every File needs "svn propset *
19 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
20 * -------------------------------------------------------------------- *
21 * Copyright (c) 2003 - 2008 by Roland Haeder *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
47 EXT_SET_VERSION("0.2.2");
49 // Version history array (add more with , "0.1" and so on)
50 EXT_SET_VER_HISTORY(array("0.0", "0.0.1", "0.0.2", "0.0.3", "0.0.4", "0.0.5", "0.0.6", "0.0.7", "0.0.8", "0.0.9", "0.1.0", "0.1.1", "0.1.2", "0.1.3", "0.1.4", "0.1.5", "0.1.6", "0.1.7", "0.1.8", "0.1.9", "0.2.0", "0.2.1", "0.2.2"));
52 switch ($EXT_LOAD_MODE)
54 case "register": // Do stuff when installation is running (modules.php?module=admin&action=login is called)
55 // SQL commands to run
56 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_update BIGINT(20) UNSIGNED NOT NULL DEFAULT 3600");
57 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_path VARCHAR(255) NOT NULL DEFAULT 'cache/'");
58 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_tested TINYINT(1) UNSIGNED NOT NULL DEFAULT 0");
59 ADD_EXT_SQL("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('setup','config_cache','Cache-Einstellungen','Update-Interval des Caches usw. können Sie hier ändern.', 9)");
62 case "remove": // Do stuff when removing extension
63 // SQL commands to run
64 ADD_EXT_SQL("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE `what` IN('config_cache','cache_stats')");
66 // Unregister all filters
67 UNREGISTER_FILTER('extension_update', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
68 UNREGISTER_FILTER('post_extension_installed', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
69 UNREGISTER_FILTER('post_extension_installed', 'CACHE_PURGE_ADMIN_MENU', true, $dry_run);
70 UNREGISTER_FILTER('post_extension_run_sql', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
71 UNREGISTER_FILTER('post_extension_run_sql', 'CACHE_PURGE_ADMIN_MENU', true, $dry_run);
72 UNREGISTER_FILTER('post_admin_added', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
73 UNREGISTER_FILTER('post_admin_edited', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
74 UNREGISTER_FILTER('post_admin_deleted', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
75 UNREGISTER_FILTER('post_admin_reset_pass', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
76 UNREGISTER_FILTER('extension_remove', 'CACHE_DESTROY_ALL', true, $dry_run);
79 case "activate": // Do stuff when admin activates this extension
80 // SQL commands to run
84 case "deactivate": // Do stuff when admin deactivates this extension
85 // SQL commands to run
89 case "update": // Update an extension
92 case "0.0.1": // SQL queries for v0.0.1
93 // Update notes (these will be set as task text!)
94 EXT_SET_UPDATE_NOTES("Es wurde die Zeitmarke der Cache-Datei extensions.cache mit berücksichtigt. Dies hatte die Folge, dass wenn bei einem Gast die Datei aktualisiert wurde, nur aktivierte und nicht die deaktivierten mit geladen wurden. Folglich fiehlen einfach ein paar Erweiterungen aus.");
97 case "0.0.2": // SQL queries for v0.0.2
98 // Update notes (these will be set as task text!)
99 EXT_SET_UPDATE_NOTES("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.");
102 case "0.0.3": // SQL queries for v0.0.3
103 // Update notes (these will be set as task text!)
104 EXT_SET_UPDATE_NOTES("Cache-Update repariert.");
107 case "0.0.4": // SQL queries for v0.0.4
108 // Is the cache extension itself there?
109 if (EXT_IS_ACTIVE("cache")) {
110 // Check for cache when extension is already installed
111 if ($GLOBALS['cache_instance']->loadCacheFile("extensions", true)) $GLOBALS['cache_instance']->destroyCacheFile();
114 // Update notes (these will be set as task text!)
115 EXT_SET_UPDATE_NOTES("Spalte "keep_active" ist hinzugefügt. Cache wurde reinitialisiert.");
118 case "0.0.5": // SQL queries for v0.0.5
119 // Update notes (these will be set as task text!)
120 EXT_SET_UPDATE_NOTES("Registrierung der Cache-Erweiterung repariert");
123 case "0.0.6": // SQL queries for v0.0.6
124 // Update notes (these will be set as task text!)
125 EXT_SET_UPDATE_NOTES("Validierung der Cache-Datei admins.cache integriert.");
128 case "0.0.7": // SQL queries for v0.0.7
129 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD db_hits BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
130 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_hits BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
131 ADD_EXT_SQL("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('stats','cache_stats','DB-Cache','Auf Cache und gesamte Datenbank registrierte Anfragen anzeigen.', 4)");
133 // Update notes (these will be set as task text!)
134 EXT_SET_UPDATE_NOTES("Hits auf den Cache werden gezählt.");
137 case "0.0.8": // SQL queries for v0.0.8
138 // Update notes (these will be set as task text!)
139 EXT_SET_UPDATE_NOTES("Das Umschreiben der Cache-Daten hat eine Fehlermeldung <strong>Falsches Passwort!</strong> im Admin-Bereich verursacht.");
142 case "0.0.9": // SQL queries for v0.0.9
143 // Update notes (these will be set as task text!)
144 EXT_SET_UPDATE_NOTES("Interne Datenfeld-Management korregiert und Cache-Statistiken korregiert.");
147 case "0.1.0": // SQL queries for v0.2.1
148 // Update notes (these will be set as task text!)
149 EXT_SET_UPDATE_NOTES("Problem mit fehlender admins-Erweiterung beseitigt.");
152 case "0.1.1": // SQL queries for v0.1.1
153 // Update notes (these will be set as task text!)
154 EXT_SET_UPDATE_NOTES("Fehler <strong>Division durch 0</strong> repariert in den DB-Cache Statistiken.");
157 case "0.1.2": // SQL queries for v0.1.2
158 // Update notes (these will be set as task text!)
159 EXT_SET_UPDATE_NOTES("Die Tabelen <strong>{!_MYSQL_PREFIX!}_config</strong>, <strong>{!_MYSQL_PREFIX!}_refsystem</strong>, <strong>{!_MYSQL_PREFIX!}_refdepths</strong> und <strong>{!_MYSQL_PREFIX!}_mod_reg</strong> werden nun auch ausgelagert.");
162 case "0.1.3": // SQL queries for v0.1.3
163 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_admins ENUM('Y','N') NOT NULL DEFAULT 'Y'");
164 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_acls ENUM('Y','N') NOT NULL DEFAULT 'Y'");
165 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_exts ENUM('Y','N') NOT NULL DEFAULT 'Y'");
166 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_config ENUM('Y','N') NOT NULL DEFAULT 'Y'");
167 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_modreg ENUM('Y','N') NOT NULL DEFAULT 'Y'");
168 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_refdepth ENUM('Y','N') NOT NULL DEFAULT 'Y'");
169 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_refsys ENUM('Y','N') NOT NULL DEFAULT 'Y'");
171 // Update notes (these will be set as task text!)
172 EXT_SET_UPDATE_NOTES("Alle cache-baren Tabellen sind nun einzelnt ein- bzw. ausschaltbar. Falls die eine oder andere ausgelagerte Tabelle also Fehler verursachen sollte, so können Sie diese hier abschalten. Beachten Sie aber bitte, dass dann mehr Abfragen an die Datenbank gestellt wird und dies bedeutend mehr Zeit braucht, als nur die Daten aus einem Datenfeld zu laden, das sich im Speicher aufhält.");
175 case "0.1.4": // SQL queries for v0.1.4
176 // Update notes (these will be set as task text!)
177 EXT_SET_UPDATE_NOTES("Fehler <strong>Division durch 0</strong> repariert in <strong>inc/load_cache.php</strong>.");
180 case "0.1.5": // SQL queries for v0.1.5
181 // Update notes (these will be set as task text!)
182 EXT_SET_UPDATE_NOTES("Weitere Fehler im System beseitigt.");
185 case "0.1.6": // SQL queries for v0.1.6
186 // Update notes (these will be set as task text!)
187 EXT_SET_UPDATE_NOTES("Probleme während des Installationsvorganges beseitigt.");
190 case "0.1.7": // SQL queries for v0.1.7
191 // Update notes (these will be set as task text!)
192 EXT_SET_UPDATE_NOTES("CSS-Klassenname gefixt in Templates.");
195 case "0.1.8": // SQL queries for v0.1.8
196 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_themes ENUM('Y','N') NOT NULL DEFAULT 'Y'");
198 // Update notes (these will be set as task text!)
199 EXT_SET_UPDATE_NOTES("Daten von installierten Themes werden nun gecacht.");
202 case "0.1.9": // SQL queries for v0.1.9
203 ADD_EXT_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_admin_menu ENUM('Y','N') NOT NULL DEFAULT 'N'");
205 // Update notes (these will be set as task text!)
206 EXT_SET_UPDATE_NOTES("Administratormenü experimentell gecacht.");
209 case "0.2.0": // SQL queries for v0.2.0
210 // This update depends on sql_patches
211 EXT_ADD_UPDATE_DEPENDS("sql_patches");
213 // Update notes (these will be set as task text!)
214 EXT_SET_UPDATE_NOTES("Die Erweiterung hängt nun von der <strong>sql_patches</strong> ab.");
217 case "0.2.1": // SQL queries for v0.2.1
218 // Register the new filter
219 REGISTER_FILTER('extension_update', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
220 REGISTER_FILTER('post_extension_installed', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
221 REGISTER_FILTER('post_extension_run_sql', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
222 REGISTER_FILTER('post_admin_added', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
223 REGISTER_FILTER('post_admin_edited', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
224 REGISTER_FILTER('post_admin_deleted', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
225 REGISTER_FILTER('post_admin_reset_pass', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
226 REGISTER_FILTER('extension_remove', 'CACHE_DESTROY_ALL', false, true, $dry_run);
228 // Update notes (these will be set as task text!)
229 EXT_SET_UPDATE_NOTES("Filter für Erweiterungsmanagement hinzugefügt.");
232 case "0.2.2": // SQL queries for v0.2.2
233 // Register the new filter
234 REGISTER_FILTER('post_extension_installed', 'CACHE_PURGE_ADMIN_MENU', false, true, $dry_run);
235 REGISTER_FILTER('post_extension_run_sql', 'CACHE_PURGE_ADMIN_MENU', false, true, $dry_run);
237 // Update notes (these will be set as task text!)
238 EXT_SET_UPDATE_NOTES("Weitere Filter hinzugefügt.");
243 case "modify": // When the extension got modified
246 case "test": // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
249 default: // Do stuff when extension is loaded
250 // Create instance on class
251 if ($GLOBALS['cache_mode'] != "init") {
252 // Initialize cache system only when it's needed
253 $GLOBALS['cache_instance'] = new CacheSystem(getConfig('cache_update'), "inc/".getConfig('cache_path'), getConfig('cache_tested'));
254 if ($GLOBALS['cache_instance']->getStatus() != "done") {
255 // Failed to initialize cache sustem
256 addFatalMessage(__FILE__, __LINE__, "(<font color=\"#0000aa\">".__LINE__."</font>): ".getMessage('CACHE_CANNOT_INITIALIZE'));
262 // Keep this extension always active!
263 EXT_SET_ALWAYS_ACTIVE("Y");