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