1ae1bc7d38bf7633fa0f46990cad399630b6d232
[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_VERSION = "0.2.2";
43
44 // Auto-set extension version
45 if (empty($EXT_VER)) $EXT_VER = $EXT_VERSION;
46
47 // Version history array (add more with , "0.1" and so on)
48 $EXT_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");
49
50 switch ($EXT_LOAD_MODE)
51 {
52 case "register": // Do stuff when installation is running (modules.php?module=admin&action=login is called)
53         // SQL commands to run
54         $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_update BIGINT(20) UNSIGNED NOT NULL DEFAULT 3600";
55         $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_path VARCHAR(255) NOT NULL DEFAULT 'cache/'";
56         $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_tested TINYINT(1) UNSIGNED NOT NULL DEFAULT 0";
57         $SQLs[] = "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)";
58         break;
59
60 case "remove": // Do stuff when removing extension
61         // SQL commands to run
62         $SQLs[] = "DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE what='config_cache' OR what='cache_stats' LIMIT 2";
63
64         // Unregister all filters
65         UNREGISTER_FILTER('extension_update', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
66         UNREGISTER_FILTER('post_extension_installed', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
67         UNREGISTER_FILTER('post_extension_installed', 'CACHE_PURGE_ADMIN_MENU', true, $dry_run);
68         UNREGISTER_FILTER('post_extension_run_sql', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
69         UNREGISTER_FILTER('post_extension_run_sql', 'CACHE_PURGE_ADMIN_MENU', true, $dry_run);
70         UNREGISTER_FILTER('post_admin_added', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
71         UNREGISTER_FILTER('post_admin_edited', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
72         UNREGISTER_FILTER('post_admin_deleted', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
73         UNREGISTER_FILTER('post_admin_reset_pass', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
74         UNREGISTER_FILTER('extension_remove', 'CACHE_DESTROY_ALL', true, $dry_run);
75         break;
76
77 case "activate": // Do stuff when admin activates this extension
78         // SQL commands to run
79         $SQLs[] = "";
80         break;
81
82 case "deactivate": // Do stuff when admin deactivates this extension
83         // SQL commands to run
84         $SQLs[] = "";
85         break;
86
87 case "update": // Update an extension
88         switch ($EXT_VER)
89         {
90         case "0.0.1": // SQL queries for v0.0.1
91                 // Update notes (these will be set as task text!)
92                 $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.";
93                 break;
94
95         case "0.0.2": // SQL queries for v0.0.2
96                 // Update notes (these will be set as task text!)
97                 $UPDATE_NOTES = "Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.";
98                 break;
99
100         case "0.0.3": // SQL queries for v0.0.3
101                 // Update notes (these will be set as task text!)
102                 $UPDATE_NOTES = "Cache-Update repariert.";
103                 break;
104
105         case "0.0.4": // SQL queries for v0.0.4
106                 // Is the cache extension itself there?
107                 if (EXT_IS_ACTIVE("cache")) {
108                         // Check for cache when extension is already installed
109                         if ($cacheInstance->loadCacheFile("extensions", true)) $cacheInstance->destroyCacheFile();
110                 } // END - if
111
112                 // Update notes (these will be set as task text!)
113                 $UPDATE_NOTES = "Spalte &quot;keep_active&quot; ist hinzugef&uuml;gt. Cache wurde reinitialisiert.";
114                 break;
115
116         case "0.0.5": // SQL queries for v0.0.5
117                 // Update notes (these will be set as task text!)
118                 $UPDATE_NOTES = "Registrierung der Cache-Erweiterung repariert";
119                 break;
120
121         case "0.0.6": // SQL queries for v0.0.6
122                 // Update notes (these will be set as task text!)
123                 $UPDATE_NOTES = "Validierung der Cache-Datei admins.cache integriert.";
124                 break;
125
126         case "0.0.7": // SQL queries for v0.0.7
127                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD db_hits BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
128                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_hits BIGINT(20) UNSIGNED NOT NULL DEFAULT 0";
129                 $SQLs[] = "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)";
130
131                 // Update notes (these will be set as task text!)
132                 $UPDATE_NOTES = "Hits auf den Cache werden gez&auml;hlt.";
133                 break;
134
135         case "0.0.8": // SQL queries for v0.0.8
136                 // Update notes (these will be set as task text!)
137                 $UPDATE_NOTES = "Das Umschreiben der Cache-Daten hat eine Fehlermeldung <strong>Falsches Passwort!</strong> im Admin-Bereich verursacht.";
138                 break;
139
140         case "0.0.9": // SQL queries for v0.0.9
141                 // Update notes (these will be set as task text!)
142                 $UPDATE_NOTES = "Interne Datenfeld-Management korregiert und Cache-Statistiken korregiert.";
143                 break;
144
145         case "0.1.0": // SQL queries for v0.2.1
146                 // Update notes (these will be set as task text!)
147                 $UPDATE_NOTES = "Problem mit fehlender admins-Erweiterung beseitigt.";
148                 break;
149
150         case "0.1.1": // SQL queries for v0.1.1
151                 // Update notes (these will be set as task text!)
152                 $UPDATE_NOTES = "Fehler <strong>Division durch 0</strong> repariert in den DB-Cache Statistiken.";
153                 break;
154
155         case "0.1.2": // SQL queries for v0.1.2
156                 // Update notes (these will be set as task text!)
157                 $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.";
158                 break;
159
160         case "0.1.3": // SQL queries for v0.1.3
161                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_admins ENUM('Y','N') NOT NULL DEFAULT 'Y'";
162                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_acls ENUM('Y','N') NOT NULL DEFAULT 'Y'";
163                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_exts ENUM('Y','N') NOT NULL DEFAULT 'Y'";
164                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_config ENUM('Y','N') NOT NULL DEFAULT 'Y'";
165                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_modreg ENUM('Y','N') NOT NULL DEFAULT 'Y'";
166                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_refdepth ENUM('Y','N') NOT NULL DEFAULT 'Y'";
167                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_refsys ENUM('Y','N') NOT NULL DEFAULT 'Y'";
168
169                 // Update notes (these will be set as task text!)
170                 $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.";
171                 break;
172
173         case "0.1.4": // SQL queries for v0.1.4
174                 // Update notes (these will be set as task text!)
175                 $UPDATE_NOTES = "Fehler <strong>Division durch 0</strong> repariert in <strong>inc/load_cache.php</strong>.";
176                 break;
177
178         case "0.1.5": // SQL queries for v0.1.5
179                 // Update notes (these will be set as task text!)
180                 $UPDATE_NOTES = "Weitere Fehler im System beseitigt.";
181                 break;
182
183         case "0.1.6": // SQL queries for v0.1.6
184                 // Update notes (these will be set as task text!)
185                 $UPDATE_NOTES = "Probleme w&auml;hrend des Installationsvorganges beseitigt.";
186                 break;
187
188         case "0.1.7": // SQL queries for v0.1.7
189                 // Update notes (these will be set as task text!)
190                 $UPDATE_NOTES = "CSS-Klassenname gefixt in Templates.";
191                 break;
192
193         case "0.1.8": // SQL queries for v0.1.8
194                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_themes ENUM('Y','N') NOT NULL DEFAULT 'Y'";
195
196                 // Update notes (these will be set as task text!)
197                 $UPDATE_NOTES = "Daten von installierten Themes werden nun gecacht.";
198                 break;
199
200         case "0.1.9": // SQL queries for v0.1.9
201                 $SQLs[] = "ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_admin_menu ENUM('Y','N') NOT NULL DEFAULT 'N'";
202
203                 // Update notes (these will be set as task text!)
204                 $UPDATE_NOTES = "Administratormen&uuml; experimentell gecacht.";
205                 break;
206
207         case "0.2.0": // SQL queries for v0.2.0
208                 // This update depends on sql_patches
209                 $EXT_UPDATE_DEPENDS = "sql_patches";
210
211                 // Update notes (these will be set as task text!)
212                 $UPDATE_NOTES = "Die Erweiterung h&auml;ngt nun von der <strong>sql_patches</strong> ab.";
213                 break;
214
215         case "0.2.1": // SQL queries for v0.2.1
216                 // Register the new filter
217                 REGISTER_FILTER('extension_update', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
218                 REGISTER_FILTER('post_extension_installed', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
219                 REGISTER_FILTER('post_extension_run_sql', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
220                 REGISTER_FILTER('post_admin_added', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
221                 REGISTER_FILTER('post_admin_edited', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
222                 REGISTER_FILTER('post_admin_deleted', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
223                 REGISTER_FILTER('post_admin_reset_pass', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
224                 REGISTER_FILTER('extension_remove', 'CACHE_DESTROY_ALL', false, true, $dry_run);
225
226                 // Update notes (these will be set as task text!)
227                 $UPDATE_NOTES = "Filter f&uuml;r Erweiterungsmanagement hinzugef&uuml;gt.";
228                 break;
229
230         case "0.2.2": // SQL queries for v0.2.2
231                 // Register the new filter
232                 REGISTER_FILTER('post_extension_installed', 'CACHE_PURGE_ADMIN_MENU', false, true, $dry_run);
233                 REGISTER_FILTER('post_extension_run_sql', 'CACHE_PURGE_ADMIN_MENU', false, true, $dry_run);
234
235                 // Update notes (these will be set as task text!)
236                 $UPDATE_NOTES = "Weitere Filter hinzugef&uuml;gt.";
237                 break;
238         }
239         break;
240
241 case "test": // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
242         break;
243
244 default: // Do stuff when extension is loaded
245         // Create instance on class
246         if ($cacheMode != "init") {
247                 // Make cacheInstance global
248                 global $cacheInstance;
249
250                 // Initialize cache system only when it's needed
251                 $cacheInstance = new CacheSystem(getConfig('cache_update'), constant('PATH')."inc/".getConfig('cache_path'), getConfig('cache_tested'));
252                 if ($cacheInstance->getStatus() != "done") {
253                         // Failed to initialize cache sustem
254                         addFatalMessage(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_CANNOT_INITIALIZE);
255                 } // END - if
256         } // END - if
257         break;
258 }
259
260 // Keep this extension always active!
261 $EXT_ALWAYS_ACTIVE = "Y";
262
263 //
264 ?>