rewritten to new functions, some parts rewritten to filters
[mailer.git] / inc / extensions / ext-cache.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/11/2004 *
4  * ================                             Last change: 10/11/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
14  *                                                                      *
15  * -------------------------------------------------------------------- *
16  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
17  * For more information visit: http://www.mxchange.org                  *
18  *                                                                      *
19  * This program is free software; you can redistribute it and/or modify *
20  * it under the terms of the GNU General Public License as published by *
21  * the Free Software Foundation; either version 2 of the License, or    *
22  * (at your option) any later version.                                  *
23  *                                                                      *
24  * This program is distributed in the hope that it will be useful,      *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
27  * GNU General Public License for more details.                         *
28  *                                                                      *
29  * You should have received a copy of the GNU General Public License    *
30  * along with this program; if not, write to the Free Software          *
31  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
32  * MA  02110-1301  USA                                                  *
33  ************************************************************************/
34
35 // Some security stuff...
36 if (!defined('__SECURITY')) {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40
41 // Version number
42 EXT_SET_VERSION("0.2.2");
43
44 // Version history array (add more with , "0.1" and so on)
45 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"));
46
47 switch ($EXT_LOAD_MODE)
48 {
49 case "register": // Do stuff when installation is running (modules.php?module=admin&action=login is called)
50         // SQL commands to run
51         ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_update BIGINT(20) UNSIGNED NOT NULL DEFAULT 3600");
52         ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_path VARCHAR(255) NOT NULL DEFAULT 'cache/'");
53         ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_tested TINYINT(1) UNSIGNED NOT NULL DEFAULT 0");
54         ADD_SQL("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('setup','config_cache','Cache-Einstellungen','Update-Interval des Caches usw. k&ouml;nnen Sie hier &auml;ndern.', 9)");
55         break;
56
57 case "remove": // Do stuff when removing extension
58         // SQL commands to run
59         ADD_SQL("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE `what`='config_cache' OR `what`='cache_stats' LIMIT 2");
60
61         // Unregister all filters
62         UNREGISTER_FILTER('extension_update', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
63         UNREGISTER_FILTER('post_extension_installed', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
64         UNREGISTER_FILTER('post_extension_installed', 'CACHE_PURGE_ADMIN_MENU', true, $dry_run);
65         UNREGISTER_FILTER('post_extension_run_sql', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
66         UNREGISTER_FILTER('post_extension_run_sql', 'CACHE_PURGE_ADMIN_MENU', true, $dry_run);
67         UNREGISTER_FILTER('post_admin_added', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
68         UNREGISTER_FILTER('post_admin_edited', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
69         UNREGISTER_FILTER('post_admin_deleted', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
70         UNREGISTER_FILTER('post_admin_reset_pass', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
71         UNREGISTER_FILTER('extension_remove', 'CACHE_DESTROY_ALL', true, $dry_run);
72         break;
73
74 case "activate": // Do stuff when admin activates this extension
75         // SQL commands to run
76         ADD_SQL("");
77         break;
78
79 case "deactivate": // Do stuff when admin deactivates this extension
80         // SQL commands to run
81         ADD_SQL("");
82         break;
83
84 case "update": // Update an extension
85         switch ($EXT_VER)
86         {
87         case "0.0.1": // SQL queries for v0.0.1
88                 // Update notes (these will be set as task text!)
89                 EXT_SET_UPDATE_NOTES("Es wurde die Zeitmarke der Cache-Datei extensions.cache mit ber&uuml;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.");
90                 break;
91
92         case "0.0.2": // SQL queries for v0.0.2
93                 // Update notes (these will be set as task text!)
94                 EXT_SET_UPDATE_NOTES("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.");
95                 break;
96
97         case "0.0.3": // SQL queries for v0.0.3
98                 // Update notes (these will be set as task text!)
99                 EXT_SET_UPDATE_NOTES("Cache-Update repariert.");
100                 break;
101
102         case "0.0.4": // SQL queries for v0.0.4
103                 // Is the cache extension itself there?
104                 if (EXT_IS_ACTIVE("cache")) {
105                         // Check for cache when extension is already installed
106                         if ($GLOBALS['cache_instance']->loadCacheFile("extensions", true)) $GLOBALS['cache_instance']->destroyCacheFile();
107                 } // END - if
108
109                 // Update notes (these will be set as task text!)
110                 EXT_SET_UPDATE_NOTES("Spalte &quot;keep_active&quot; ist hinzugef&uuml;gt. Cache wurde reinitialisiert.");
111                 break;
112
113         case "0.0.5": // SQL queries for v0.0.5
114                 // Update notes (these will be set as task text!)
115                 EXT_SET_UPDATE_NOTES("Registrierung der Cache-Erweiterung repariert");
116                 break;
117
118         case "0.0.6": // SQL queries for v0.0.6
119                 // Update notes (these will be set as task text!)
120                 EXT_SET_UPDATE_NOTES("Validierung der Cache-Datei admins.cache integriert.");
121                 break;
122
123         case "0.0.7": // SQL queries for v0.0.7
124                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD db_hits BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
125                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_hits BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
126                 ADD_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)");
127
128                 // Update notes (these will be set as task text!)
129                 EXT_SET_UPDATE_NOTES("Hits auf den Cache werden gez&auml;hlt.");
130                 break;
131
132         case "0.0.8": // SQL queries for v0.0.8
133                 // Update notes (these will be set as task text!)
134                 EXT_SET_UPDATE_NOTES("Das Umschreiben der Cache-Daten hat eine Fehlermeldung <strong>Falsches Passwort!</strong> im Admin-Bereich verursacht.");
135                 break;
136
137         case "0.0.9": // SQL queries for v0.0.9
138                 // Update notes (these will be set as task text!)
139                 EXT_SET_UPDATE_NOTES("Interne Datenfeld-Management korregiert und Cache-Statistiken korregiert.");
140                 break;
141
142         case "0.1.0": // SQL queries for v0.2.1
143                 // Update notes (these will be set as task text!)
144                 EXT_SET_UPDATE_NOTES("Problem mit fehlender admins-Erweiterung beseitigt.");
145                 break;
146
147         case "0.1.1": // SQL queries for v0.1.1
148                 // Update notes (these will be set as task text!)
149                 EXT_SET_UPDATE_NOTES("Fehler <strong>Division durch 0</strong> repariert in den DB-Cache Statistiken.");
150                 break;
151
152         case "0.1.2": // SQL queries for v0.1.2
153                 // Update notes (these will be set as task text!)
154                 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.");
155                 break;
156
157         case "0.1.3": // SQL queries for v0.1.3
158                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_admins ENUM('Y','N') NOT NULL DEFAULT 'Y'");
159                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_acls ENUM('Y','N') NOT NULL DEFAULT 'Y'");
160                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_exts ENUM('Y','N') NOT NULL DEFAULT 'Y'");
161                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_config ENUM('Y','N') NOT NULL DEFAULT 'Y'");
162                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_modreg ENUM('Y','N') NOT NULL DEFAULT 'Y'");
163                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_refdepth ENUM('Y','N') NOT NULL DEFAULT 'Y'");
164                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_refsys ENUM('Y','N') NOT NULL DEFAULT 'Y'");
165
166                 // Update notes (these will be set as task text!)
167                 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&ouml;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&auml;lt.");
168                 break;
169
170         case "0.1.4": // SQL queries for v0.1.4
171                 // Update notes (these will be set as task text!)
172                 EXT_SET_UPDATE_NOTES("Fehler <strong>Division durch 0</strong> repariert in <strong>inc/load_cache.php</strong>.");
173                 break;
174
175         case "0.1.5": // SQL queries for v0.1.5
176                 // Update notes (these will be set as task text!)
177                 EXT_SET_UPDATE_NOTES("Weitere Fehler im System beseitigt.");
178                 break;
179
180         case "0.1.6": // SQL queries for v0.1.6
181                 // Update notes (these will be set as task text!)
182                 EXT_SET_UPDATE_NOTES("Probleme w&auml;hrend des Installationsvorganges beseitigt.");
183                 break;
184
185         case "0.1.7": // SQL queries for v0.1.7
186                 // Update notes (these will be set as task text!)
187                 EXT_SET_UPDATE_NOTES("CSS-Klassenname gefixt in Templates.");
188                 break;
189
190         case "0.1.8": // SQL queries for v0.1.8
191                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_themes ENUM('Y','N') NOT NULL DEFAULT 'Y'");
192
193                 // Update notes (these will be set as task text!)
194                 EXT_SET_UPDATE_NOTES("Daten von installierten Themes werden nun gecacht.");
195                 break;
196
197         case "0.1.9": // SQL queries for v0.1.9
198                 ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_admin_menu ENUM('Y','N') NOT NULL DEFAULT 'N'");
199
200                 // Update notes (these will be set as task text!)
201                 EXT_SET_UPDATE_NOTES("Administratormen&uuml; experimentell gecacht.");
202                 break;
203
204         case "0.2.0": // SQL queries for v0.2.0
205                 // This update depends on sql_patches
206                 EXT_SET_UPDATE_DEPENDS("sql_patches");
207
208                 // Update notes (these will be set as task text!)
209                 EXT_SET_UPDATE_NOTES("Die Erweiterung h&auml;ngt nun von der <strong>sql_patches</strong> ab.");
210                 break;
211
212         case "0.2.1": // SQL queries for v0.2.1
213                 // Register the new filter
214                 REGISTER_FILTER('extension_update', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
215                 REGISTER_FILTER('post_extension_installed', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
216                 REGISTER_FILTER('post_extension_run_sql', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
217                 REGISTER_FILTER('post_admin_added', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
218                 REGISTER_FILTER('post_admin_edited', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
219                 REGISTER_FILTER('post_admin_deleted', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
220                 REGISTER_FILTER('post_admin_reset_pass', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
221                 REGISTER_FILTER('extension_remove', 'CACHE_DESTROY_ALL', false, true, $dry_run);
222
223                 // Update notes (these will be set as task text!)
224                 EXT_SET_UPDATE_NOTES("Filter f&uuml;r Erweiterungsmanagement hinzugef&uuml;gt.");
225                 break;
226
227         case "0.2.2": // SQL queries for v0.2.2
228                 // Register the new filter
229                 REGISTER_FILTER('post_extension_installed', 'CACHE_PURGE_ADMIN_MENU', false, true, $dry_run);
230                 REGISTER_FILTER('post_extension_run_sql', 'CACHE_PURGE_ADMIN_MENU', false, true, $dry_run);
231
232                 // Update notes (these will be set as task text!)
233                 EXT_SET_UPDATE_NOTES("Weitere Filter hinzugef&uuml;gt.");
234                 break;
235         }
236         break;
237
238 case "test": // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
239         break;
240
241 default: // Do stuff when extension is loaded
242         // Create instance on class
243         if ($GLOBALS['cacheMode'] != "init") {
244                 // Initialize cache system only when it's needed
245                 $GLOBALS['cache_instance'] = new CacheSystem(getConfig('cache_update'), constant('PATH')."inc/".getConfig('cache_path'), getConfig('cache_tested'));
246                 if ($GLOBALS['cache_instance']->getStatus() != "done") {
247                         // Failed to initialize cache sustem
248                         addFatalMessage(__FILE__, __LINE__, "(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_CANNOT_INITIALIZE);
249                 } // END - if
250         } // END - if
251         break;
252 }
253
254 // Keep this extension always active!
255 EXT_SET_ALWAYS_ACTIVE("Y");
256
257 //
258 ?>