2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/25/2009 *
4 * =================== Last change: 10/25/2009 *
6 * -------------------------------------------------------------------- *
7 * File : extensions-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Extension management *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Erweiterungen-Management *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Load the extension and maybe found language and function files.
44 function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = false) {
45 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_mode=' . $ext_mode . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ' - ENTERED!');
46 // Loading an extension in same mode, but not test/update, twice is not
47 // good, so is the extension $ext_name already loaded in mode $ext_mode?
48 if ((isset($GLOBALS['loaded_extension'][$ext_name][$ext_mode])) && (!in_array($ext_mode, array('update', 'test')))) {
49 // If this happens twice, we need the bug report from you, except for updates/tests
50 reportBug(__FUNCTION__, __LINE__, __FUNCTION__ . '() is called twice: ext_name=' . $ext_name . ', ext_mode='. $ext_mode . ',ext_sqls=' . print_r(getExtensionSqls(), true) . ', ext_register_running=' . print_r($GLOBALS['ext_register_running'], true) . ', ext_running_updates=' . print_r($GLOBALS['ext_running_updates'], true));
53 // Make sure this situation can only happen once
54 $GLOBALS['loaded_extension'][$ext_name][$ext_mode] = true;
57 setExtensionMode($ext_mode);
59 // Set current extension name
60 setCurrentExtensionName($ext_name);
62 // By default all extensions are in productive phase
63 enableExtensionProductive();
65 if (!empty($ext_ver)) {
66 // Set current extension version
67 setCurrentExtensionVersion($ext_ver);
69 // Set it to 0.0 by default
70 setCurrentExtensionVersion('0.0.0');
72 // Is the extension installed?
73 if ((isExtensionInstalled($ext_name)) && ($ext_mode != 'register')) {
74 // Get extension's version
75 setCurrentExtensionVersion(getExtensionVersion($ext_name));
78 // In all but test-mode we need these messages to debug! Please report all (together, e.g.)
79 if (($ext_mode != 'test') && (getCurrentExtensionVersion() == '0.0.0')) {
80 // Abort here, this must now always be set!
81 reportBug(__FUNCTION__, __LINE__, 'Extension version is empty, setting to 0.0. ext_name=' . $ext_name . ', ext_mode=' . $ext_mode . ', dry_run=' . intval($dry_run));
86 enableExtensionDryRun($dry_run);
89 initIncludePool('extension');
91 // Init EXT_UPDATE_DEPENDS if not yet done
92 if (!isExtensionUpdateDependenciesInitialized()) {
94 initExtensionUpdateDependencies();
97 // Init current extension name list
100 // Is the extension already loaded?
101 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Loading extension ' . $ext_name . ', getExtensionMode()=' . getExtensionMode() . ', getCurrentExtensionVersion()=' . getCurrentExtensionVersion());
102 if ((isExtensionLoaded($ext_name)) && (getExtensionMode() == 'init')) {
104 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s already loaded.", $ext_name));
110 // Is the extension file NOT there?
111 if (!isExtensionNameValid($ext_name)) {
113 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Extension %s not found or not readable or the PHP script is deprecated.", $ext_name));
119 // Load extension's own language file if not in test mode
120 if ((getExtensionMode() != 'test') && (ifExtensionHasLanguageFile($ext_name))) {
122 loadLanguageFile($ext_name);
126 if (isExtensionFunctionFileReadable($ext_name)) {
128 if ((($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y') || (!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name]))) && (!isExtensionLibraryLoaded($ext_name))) {
129 // Construct IFN for functions file
130 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
133 markExtensionLibraryAsLoaded($ext_name);
135 // Download functions file
136 loadIncludeOnce($funcsInclude);
138 } elseif ((!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) && (isDebugModeEnabled()) && (isHtmlOutputMode()) && ($ext_name != 'sql_patches') && (substr($ext_name, 0, 10) != 'admintheme') && (getExtensionMode() == 'test')) {
139 // No functions file is not so good...
140 logDebugMessage(__FUNCTION__, __LINE__, sprintf("NOTICE: Extension %s has no own functions file or we cannot read from it. mode=%s",
146 // Load extension's filter library if present
147 loadExtensionFilters($ext_name);
149 // Extensions are not deprecated by default
150 setExtensionDeprecated('N');
152 // Extensions are not always active by default
153 setExtensionAlwaysActive('N');
155 // Include the extension file
156 loadCurrentExtensionInclude();
158 // Is this extension deprecated?
159 if ((isExtensionDeprecated()) && (!in_array(getExtensionMode(), array('test', 'update', 'deactivate'))) && (isExtensionActive($ext_name))) {
160 // Deactivate the extension
161 doDeactivateExtension($ext_name);
164 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension load aborted, ext_name=' . $ext_name . ' - Extension is deprecated.');
168 // Mark it as loaded in normal mode
169 if (getExtensionMode() == '') {
171 markExtensionAsLoaded($ext_name);
175 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension successfully loaded, ext_name=' . $ext_name);
179 // Registers an extension and possible update dependencies
180 function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates = false) {
181 // Set current extension name
182 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . intval($taskId) . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - ENTERED!');
183 setCurrentExtensionName($ext_name);
186 enableExtensionDryRun($dry_run);
188 // By default all extensions are in productive phase
189 enableExtensionProductive();
191 // This shall never do a non-admin user or if the extension is active (already installed)
192 if (((!isAdmin()) && (!isInstallationPhase())) || (isExtensionInstalled($ext_name))) {
193 // Abort here with 'false'
194 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ABORTED: isAdmin()=' . intval(isAdmin()) . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ',isExtensionInstalled()=' . intval(isExtensionInstalled($ext_name)));
198 // When this extension is already in registration/update phase, all is fine
199 if ((isExtensionRegistrationRunning($ext_name)) || ((isExtensionUpdateRunning($ext_name)) && ($ignoreUpdates === false))) {
200 // Then abort here with 'true' becaus it is fine
201 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in registration/update phase, all fine,taskId=' . $taskId . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates));
202 //* BUG: */ reportBug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . $taskId . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - Please investigate!');
206 // This registration is running
207 addExtensionRunningRegistration($ext_name);
209 // Init EXT_UPDATE_DEPENDS if not yet done
210 if (!isExtensionUpdateDependenciesInitialized()) {
212 initExtensionUpdateDependencies();
215 // Is the task id zero? Then we need to auto-fix it here
216 if (($taskId == '0') && (!isInstallationPhase())) {
217 // Try to find the task
218 $taskId = determineExtensionTaskId(getCurrentExtensionName());
220 // Still zero and not in dry-run?
221 if (($taskId == '0') && (!isExtensionDryRun())) {
222 // Now try to create a new task
223 $taskId = createNewExtensionTask(getCurrentExtensionName());
226 if ($taskId == '0') {
227 // Then request a bug report
228 reportBug(__FUNCTION__, __LINE__, sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
230 getCurrentExtensionName()
236 // Init queries and notes
238 initExtensionNotes();
242 $processResult = false;
243 initIncludePool('extension');
245 // By default we have no failures
246 enableExtensionReportingFailure();
248 // Does this extension exists?
249 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - CALLING loadExtension() ...');
250 if (loadExtension(getCurrentExtensionName(), 'register', '0.0.0', isExtensionDryRun())) {
251 // Set current extension name again
252 setCurrentExtensionName($ext_name);
254 // And run possible updates
255 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
256 $history = getExtensionVersionHistory();
257 foreach ($history as $ext_ver) {
258 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $ext_ver);
259 // Load extension in update mode
260 loadExtension(getCurrentExtensionName(), 'update', $ext_ver, isExtensionDryRun());
262 // Add update notes to our output
263 addExtensionNotes($ext_ver);
266 // Does this extension depends on an outstanding update of another update?
267 for ($dmy = getExtensionUpdateIterator(); getExtensionUpdateIterator() < countExtensionUpdateDependencies();) {
269 $ext_update = getExtensionUpdateDependenciesIterator();
271 // Increment here to avoid endless loop
272 incrementExtensionUpdateIterator();
274 // Check if extension is not installed and not already in registration procedure and if loading it wents finally fine...
275 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isExtensionRegistrationRunning(' . $ext_update . ')=' . intval(isExtensionRegistrationRunning($ext_update)));
276 if ((!isExtensionInstalled($ext_update)) && (!isExtensionRegistrationRunning($ext_update)) && (loadExtension($ext_update, 'test', '', isExtensionDryRun()))) {
277 // Set current extension name again
278 setCurrentExtensionName($ext_name);
280 // If versions mismatch update extension first
282 if (isExtensionInstalled($ext_update)) {
283 // Get version only if installed
284 $ext_ver = getExtensionVersion($ext_update);
287 // Extension version set? If empty the extension is not registered
288 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_ver[' . gettype($ext_ver) . ']=' . $ext_ver . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ',currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ' - EMPTY?');
289 if (empty($ext_ver)) {
290 // Extension not registered so far so first load task's id...
291 $taskId = determineExtensionTaskId($ext_update);
294 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'taskId=' . $taskId . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ',currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ' - CHECKING!');
295 if (($taskId > 0) || (isInstallationPhase())) {
296 // Try to register the extension
297 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',taskId=' . $taskId . ',isExtensionDryRun()=' . isExtensionDryRun());
298 $processResult = registerExtension($ext_update, $taskId, isExtensionDryRun(), true);
300 // Reset extension name
301 setCurrentExtensionName($ext_name);
302 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',processResult=' . intval($processResult));
304 } elseif ($ext_ver != getCurrentExtensionVersion()) {
305 // Ok, update this extension now
306 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
307 $GLOBALS['ext_backup_name'][$ext_update][$ext_ver] = getCurrentExtensionName();
308 $GLOBALS['ext_backup_ver'][$ext_update][$ext_ver] = getCurrentExtensionVersion();
309 updateExtension($ext_update, $ext_ver, isExtensionDryRun());
310 setCurrentExtensionName($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
311 setCurrentExtensionVersion($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
312 unset($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
313 unset($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
314 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
317 $processResult = true;
319 // Nothing to register / update before...
320 $processResult = true;
323 // Required file for update does not exists!
324 $processResult = true;
325 // But this is fine for the first time...
328 // Restore the current extension name
329 setCurrentExtensionName($ext_name);
332 // Is there no update?
333 if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
334 // Then test is passed!
335 $processResult = true;
338 // Switch back to register mode
339 setExtensionMode('register');
341 // Remains true if extension registration reports no failures
342 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
343 $processResult = (($processResult === true) && (isExtensionReportingFailure() === false));
344 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
346 // Does everthing before wents ok?
347 if ($processResult === true) {
348 // "Dry-run-mode" activated?
349 if ((isExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
350 // Init SQLs and transfer ext->generic
351 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName());
353 setSqlsArray(getExtensionSqls());
355 // Run installation pre-installation filters
356 runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
358 // Register extension
359 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'insert=' . getCurrentExtensionName() . '/' . getCurrentExtensionVersion() . ' - INSERT!');
360 if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
362 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion() . 'ext_css=' . getExtensionHasCss());
363 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')",
365 getCurrentExtensionName(),
366 getThisExtensionAlwaysActive(),
367 getCurrentExtensionVersion(),
369 ), __FUNCTION__, __LINE__);
372 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion());
373 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`) VALUES ('%s','%s','%s')",
375 getCurrentExtensionName(),
376 getThisExtensionAlwaysActive(),
377 getCurrentExtensionVersion()
378 ), __FUNCTION__, __LINE__);
381 // Use the insert id as extension id and cache it for early usage
382 $GLOBALS['cache_array']['extension']['ext_id'][getCurrentExtensionName()] = SQL_INSERTID();
383 $GLOBALS['cache_array']['extension']['ext_name'][SQL_INSERTID()] = getCurrentExtensionName();
385 // Mark it as installed
386 $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
388 // Remove cache file(s) if extension is active
389 runFilterChain('post_extension_installed', array(
390 'pool' => 'extension',
391 'ext_name' => getCurrentExtensionName(),
395 // Re-init queries and notes
396 initExtensionSqls(true);
397 initExtensionNotes(true);
399 // In normal mode return a true on success
401 } elseif (isExtensionDryRun() === true) {
402 // In "dry-run" mode do always return a true
405 // Extension has been removed for updates, so all is fine!
409 // No, an error occurs while registering extension :-(
410 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
413 } elseif (($taskId > 0) && (getCurrentExtensionName() != '')) {
414 // Remove task from system when id and extension's name is valid
415 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
416 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
417 array(bigintval($taskId)), __FUNCTION__, __LINE__);
420 // @TODO This redirect is still needed to register sql_patches! Please try to avoid it
421 if (($ret === true) && ($dry_run === false) && ($ext_name == 'sql_patches') && (!isInstallationPhase())) {
423 * This is a really dirty hack to prevent an error about a missing
424 * configuration entry which should be there after registration of
427 redirectToRequestUri();
430 // Return status code
431 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',currName=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',processResult=' . intval($processResult) . ',ret=' . intval($ret) . ' - EXIT!');
435 // Run SQL queries for given extension id
436 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
437 function doExtensionSqls ($ext_id, $load_mode) {
438 // This shall never do a non-admin user but installation phase is okay
439 if ((!isAdmin()) && (!isInstallationPhase())) {
440 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_id=' . $ext_id. ',load_mode=' . $load_mode . ',isAdmin()=' . intval(isAdmin()) . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ' - ABORT!');
444 // Get extension's name
445 $ext_name = getExtensionName($ext_id);
447 // Set current SQL name
448 setCurrentExtensionName($ext_name);
450 // Init EXT_UPDATE_DEPENDS
451 if (!isExtensionUpdateDependenciesInitialized()) {
453 initExtensionUpdateDependencies();
457 initExtensionSqls(true);
459 // By default no SQL has been executed
462 // Load extension in detected mode
463 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name[' . $ext_id . ']=' . getCurrentExtensionName() . ',load_mode=' . $load_mode);
464 loadExtension(getCurrentExtensionName(), $load_mode, '0.0.0', false);
468 setSqlsArray(getExtensionSqls());
471 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQLs::count=' . countSqls());
473 // Do we have entries?
475 // Run SQL commands...
476 runFilterChain('run_sqls');
479 // Run any filters depending on the action here
480 runFilterChain('extension_' . $load_mode);
482 // Remove cache file(s) if extension is active
483 if (((isExtensionActive('cache')) && ((!SQL_HASZEROAFFECTED()) || ($sqlRan === true) || ($load_mode == 'activate') || ($load_mode == 'deactivate')))) {
485 runFilterChain('post_extension_run_sql', getCurrentExtensionName());
488 // Is this the sql_patches?
489 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $ext_id . ',currName=' . getCurrentExtensionName() . ',loadMode=' . $load_mode);
490 if ((getCurrentExtensionName() == 'sql_patches') && (($load_mode == 'register') || ($load_mode == 'remove'))) {
491 // Then redirect to logout
492 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ': LOAD!');
493 redirectToUrl('modules.php?module=admin&logout=1&' . $load_mode . '=sql_patches');
497 // Check whether the given extension is installed
498 function isExtensionInstalled ($ext_name) {
499 // We don't like empty extension names here
500 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
501 if (empty($ext_name)) {
502 // Please fix them all
503 reportBug(__FUNCTION__, __LINE__, 'ext_name is empty.');
506 // By default non is installed
507 $isInstalled = false;
509 // Check if there is a cache entry
510 if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
511 // Use cache built from below queries
512 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
513 $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
514 } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
516 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - FOUND!');
520 incrementStatsEntry('cache_hits');
521 } elseif (isInstallationPhase()) {
522 // Extensions are all inactive/not installed during installation
523 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - installation phase detected.');
526 $ext_id = getExtensionId($ext_name);
528 // Do we have a record?
529 $isInstalled = ($ext_id > 0);
532 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_id=' . $ext_id . ',isInstalled=' . intval($isInstalled));
534 // Is it installed, then cache the entry
535 if ($isInstalled === true) {
536 // Dummy call (get is okay here)
537 getExtensionId($ext_name, true);
540 // Remember the status
541 $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
545 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isInstalled=' . intval($isInstalled) . ' - EXIT!');
549 // Check if given extension is active
550 function isExtensionActive ($ext_name) {
551 if (isInstallationPhase()) {
552 // Extensions are all inactive during installation
553 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extensions are always inactive while installation phase. ext_name=' . $ext_name);
555 } elseif (empty($ext_name)) {
556 // Empty extension names must befixed
557 reportBug(__FUNCTION__, __LINE__, 'Empty extension name provided.');
558 } elseif (!isExtensionInstalled($ext_name)) {
559 // Not installed extensions are always inactive
560 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Not installed extensions are always inactive. ext_name=' . $ext_name);
564 // Not active is the default
565 $data['ext_active'] = 'N';
568 if (isset($GLOBALS['cache_array']['extension']['ext_active'][$ext_name])) {
570 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE! ext_name=' . $ext_name);
571 $data['ext_active'] = $GLOBALS['cache_array']['extension']['ext_active'][$ext_name];
574 incrementStatsEntry('cache_hits');
575 } elseif (isExtensionLoaded($ext_name)) {
576 // @TODO Extension is loaded, what next?
577 reportBug(__FUNCTION__, __LINE__, 'LOADED:' . $ext_name);
578 } elseif (($ext_name == 'cache') || (!isExtensionInstalled('cache'))) {
579 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DB! ext_name=' . $ext_name);
580 // Load from database
581 $result = SQL_QUERY_ESC("SELECT `ext_active` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
582 array($ext_name), __FUNCTION__, __LINE__);
585 if (SQL_NUMROWS($result) == 1) {
587 $data = SQL_FETCHARRAY($result);
591 SQL_FREERESULT($result);
594 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . '[DB]: ' . $data['ext_active']);
595 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = $data['ext_active'];
597 // Extension not active!
598 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': Not active!');
599 $GLOBALS['cache_array']['extension']['ext_active'][$ext_name] = 'N';
603 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',active=' . $data['ext_active']);
605 // Is this extension activated? (For admins we always have active extensions...)
606 return ($data['ext_active'] == 'Y');
609 // Get version from extensions
610 function getExtensionVersion ($ext_name, $force = false) {
611 // By default no extension is found
612 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
613 $data['ext_version'] = 'false';
615 // Empty extension name should be fixed!
616 if (empty($ext_name)) {
617 // Please report this bug!
618 reportBug(__FUNCTION__, __LINE__, 'ext_name is empty which is not allowed here.');
621 // Extensions are all inactive during installation
622 if (isInstallationPhase()) {
623 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',force=' . intval($force) . ' - Installation phase detected, returning empty version.');
627 // Is the cache written?
628 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - Checking cache ...');
629 if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
630 // Load data from cache
631 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - CACHE!');
632 $data['ext_version'] = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
635 incrementStatsEntry('cache_hits');
636 } elseif ((!isCacheInstanceValid()) || (isset($GLOBALS['cache_array']['extension'])) || (!isHtmlOutputMode())) {
637 // Load from database
638 $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
639 array($ext_name), __FUNCTION__, __LINE__);
640 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ': DB - '.SQL_NUMROWS($result).'');
642 // Is the extension there?
643 if (SQL_NUMROWS($result) == 1) {
645 $data = SQL_FETCHARRAY($result);
648 $GLOBALS['cache_array']['extension']['ext_version'][$ext_name] = $data['ext_version'];
649 } elseif (isDebugModeEnabled()) {
650 // Not found, may happen while an extension is uninstalled
651 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot find extension %s in database!", $ext_name));
655 SQL_FREERESULT($result);
658 // Extension version should not be invalid
659 if (($data['ext_version'] == 'false') && ($force === false)) {
660 // Please report this trouble
661 reportBug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> has empty version!", $ext_name));
665 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_version=' . $data['ext_version']);
666 return $data['ext_version'];
669 // Updates a given extension with current extension version to latest version
670 function updateExtension ($ext_name, $ext_ver, $dry_run = false, $ignoreDependencies = false) {
671 // Only admins are allowed to update extensions
672 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
673 if ((!isAdmin()) || (empty($ext_name))) {
674 // Called as non-admin or empty extension
675 reportBug(__FUNCTION__, __LINE__, 'Called as non-admin (isAdmin()=' . intval(isAdmin()) . '), or empty extension name. ext_name=' . $ext_name);
678 // Set current SQL name
679 setCurrentExtensionName($ext_name);
681 // Is this extension update already running?
682 if ((isExtensionUpdateRunning($ext_name, $ignoreDependencies)) && ($dry_run === false)) {
683 // This is fine but needs logging ATM
684 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, all fine.');
685 //* BUG: */ reportBug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, please investigate!');
691 initExtensionNotes();
692 initIncludePool('extension');
694 // Load extension in test mode
695 loadExtension($ext_name, 'test', $ext_ver, isExtensionDryRun());
697 // Save version history
698 $history = getExtensionVersionHistory();
700 // Remove old SQLs array to prevent possible bugs
703 // Check if version is updated
704 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, getCurrentExtensionName() . '/' . $ext_name . ':' . getThisExtensionVersion() . '/' . $ext_ver . '/' . intval(is_array($history)));
705 if (((getThisExtensionVersion() != $ext_ver) || (isExtensionDryRun())) && (is_array($history))) {
706 // Search for starting point (-1 for making 0.0 -> 0.0.0 switch work)
708 if ($ext_ver != '0.0') {
709 $start = array_search($ext_ver, $history);
712 // And load SQL queries in order of version history
713 for ($idx = ($start + 1); $idx < count($history); $idx++) {
714 // Set extension version
715 $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
718 loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], isExtensionDryRun());
721 $depencies = getExtensionUpdateDependencies();
724 if (count($depencies) > 0) {
725 // Apply all extension depencies
726 foreach ($depencies as $ext_depend) {
727 // Did we already update/register this?
728 if (!isset($GLOBALS['ext_updated'][$ext_depend])) {
730 setCurrentExtensionName($ext_depend);
732 // Mark it as already updated before we update it
733 $GLOBALS['ext_updated'][$ext_depend] = true;
735 // Is the extension there?
736 if (isExtensionInstalled($ext_depend)) {
737 // Update another extension first!
738 $processResult = updateExtension($ext_depend, getExtensionVersion($ext_depend), isExtensionDryRun(), true);
740 // Register new extension
741 $processResult = registerExtension($ext_depend, 0, isExtensionDryRun());
747 setCurrentExtensionName($ext_name);
749 // Set extension version here
750 setCurrentExtensionVersion($ext_ver);
754 addExtensionNotes($history[$idx]);
757 // In real-mode execute any existing includes
758 if (isExtensionDryRun() === false) {
759 $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
760 runFilterChain('load_includes', 'extension');
761 setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
762 unset($GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
767 setSqlsArray(getExtensionSqls());
770 runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun(), 'enable_codes' => false));
772 if (isExtensionDryRun() === false) {
773 // Run filters on success extension update
774 runFilterChain('extension_update', getCurrentExtensionName());
778 //* DEBUG: */logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - EXIT!');
781 // Output verbose SQL table for extension
782 function addExtensionVerboseSqlTable ($title = '{--ADMIN_SQLS_EXECUTED_ON_REMOVAL--}') {
786 reportBug(__FUNCTION__, __LINE__, 'title is empty.');
792 // Do we have queries?
793 if (isVerboseSqlEnabled()) {
794 // Do we have entries?
795 if (countExtensionSqls() > 0) {
799 foreach (getExtensionSqls() as $sqls) {
800 // New array format is recursive
801 foreach ($sqls as $sql) {
805 // Output command if set
807 // Prepare output for template
810 'sql' => str_replace(array('{', '}'), array('{', '}'), encodeEntities($sql))
814 $OUT .= loadTemplate('admin_extension_sql_row', true, $content);
822 // Prepare content for template
828 // Load main template
829 $OUT = loadTemplate('admin_extension_sql_table', true, $content);
831 // No addional SQL commands to run
832 $OUT = displayMessage('{--ADMIN_EXTENSION_VERBOSE_SQLS_404--}', true);
840 // Get extension name from id
841 function getExtensionName ($ext_id) {
842 // Init extension name
843 $data['ext_name'] = '';
846 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
848 $data['ext_name'] = $GLOBALS['cache_array']['extension']['ext_name'][$ext_id];
851 incrementStatsEntry('cache_hits');
852 } elseif (!isExtensionActive('cache')) {
853 // Load from database
854 $result = SQL_QUERY_ESC("SELECT `ext_name` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `id`=%s LIMIT 1",
855 array(bigintval($ext_id)), __FUNCTION__, __LINE__);
857 // Is the entry there?
858 if (SQL_NUMROWS($result) == 1) {
859 // Get the extension's name from database
860 $data = SQL_FETCHARRAY($result);
864 SQL_FREERESULT($result);
867 // Did we find some extension?
868 if (empty($data['ext_name'])) {
869 // We should fix these all!
870 reportBug(__FUNCTION__, __LINE__, 'ext_name is empty. ext_id=' . $ext_id);
873 // Return the extension name
874 return $data['ext_name'];
877 // Get extension id from name
878 function getExtensionId ($ext_name) {
880 $data['ext_id'] = '0';
883 if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
885 $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name];
888 incrementStatsEntry('cache_hits');
890 // Load from database
891 $result = SQL_QUERY_ESC("SELECT `id` AS `ext_id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
892 array($ext_name), __FUNCTION__, __LINE__);
894 // Is the entry there?
895 if (SQL_NUMROWS($result) == 1) {
896 // Get the extension's id from database
897 $data = SQL_FETCHARRAY($result);
901 SQL_FREERESULT($result);
904 $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $data['ext_id'];
908 return $data['ext_id'];
911 // Determines whether the given extension name is valid
912 function isExtensionNameValid ($ext_name) {
914 if (!isset($GLOBALS['ext_name_valid'][$ext_name])) {
915 // Generate include file name
916 $INC = sprintf("inc/extensions/ext-%s.php", $ext_name);
918 // Is there a file in inc/extensions/ ?
919 $GLOBALS['ext_name_valid'][$ext_name] = isIncludeReadable($INC);
923 return $GLOBALS['ext_name_valid'][$ext_name];
926 // Determines whether the given extension id is valid
927 function isExtensionIdValid ($ext_id) {
928 // Default is nothing valid
931 // Check in cache then in database
932 if (isset($GLOBALS['cache_array']['extension']['ext_name'][$ext_id])) {
937 incrementStatsEntry('cache_hits');
940 $isValid = (countSumTotalData($ext_id, 'extensions', 'id', 'id', true) == 1);
947 // Activate given extension
948 function doActivateExtension ($ext_name) {
949 // Is the extension installed?
950 if (!isExtensionInstalled($ext_name)) {
951 // Non-installed extensions cannot be activated
952 reportBug(__FUNCTION__, __LINE__, 'Tried to activate non-installed extension ' . $ext_name);
955 // Activate the extension
956 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='Y' WHERE `ext_name`='%s' LIMIT 1",
957 array($ext_name), __FUNCTION__, __LINE__);
959 // Then run all queries
960 doExtensionSqls(getExtensionId($ext_name), 'activate');
963 // Deactivate given extension
964 function doDeactivateExtension ($ext_name) {
965 // Is the extension installed?
966 if (!isExtensionInstalled($ext_name)) {
967 // Non-installed extensions cannot be activated
968 reportBug(__FUNCTION__, __LINE__, 'Tried to deactivate non-installed extension ' . $ext_name . ',getExtensionMode()=' . getExtensionMode());
971 // Activate the extension
972 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_extensions` SET `ext_active`='N' WHERE `ext_name`='%s' LIMIT 1",
973 array($ext_name), __FUNCTION__, __LINE__);
975 // Then run all queries
976 doExtensionSqls(getExtensionId($ext_name), 'deactivate');
978 // Create new task (we ignore the task id here)
979 createExtensionDeactivationTask($ext_name);
982 rebuildCache('extension', 'extension');
985 sendAdminNotification(
986 '{--ADMIN_EXTENSION_DEACTIVATED_SUBJECT--}',
987 'admin_extension_deactivated',
988 array('ext_name' => $ext_name)
992 // Checks whether the extension is older than given
993 function isExtensionOlder ($ext_name, $ext_ver) {
994 // Get current extension version
995 $currVersion = getExtensionVersion($ext_name);
997 // Remove all dots from both versions
998 $currVersion = str_replace('.', '', $currVersion);
999 $ext_ver = str_replace('.', '', $ext_ver);
1001 // Now compare both and return the result
1002 return ($currVersion < $ext_ver);
1005 // Creates a new task for updated extension
1006 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
1007 // Create subject line
1008 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXTENSION_SUBJECT--}';
1011 $taskId = determineTaskIdBySubject($subject);
1013 // Is the extension there?
1014 if (isExtensionInstalled($ext_name)) {
1015 // Check if task is not there
1016 if ($taskId == '0') {
1017 // Create extension update-task
1018 $taskId = createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
1021 // Extension not there! :-(
1022 reportBug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> not found but should be updated?", $ext_name));
1029 // Creates a new task for newly installed extension
1030 function createNewExtensionTask ($ext_name) {
1031 // Generate subject line
1032 $subject = sprintf("[%s:]", $ext_name);
1035 $taskId = determineTaskIdBySubject($subject);
1037 // Not installed and do we have created a task for the admin?
1038 if (($taskId == '0') && (!isExtensionInstalled($ext_name))) {
1039 // Set default message if ext-foo is missing
1040 $message = '{%message,ADMIN_EXTENSION_TEXT_FILE_MISSING=' . $ext_name . '%}';
1043 $FQFN = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
1049 // Load text for task if found
1050 if (isFileReadable($FQFN)) {
1051 // Load extension's description template (but do not compile the code)
1052 $message = loadTemplate('ext_' . $ext_name, true, array(), false);
1054 // Write this in debug.log as well
1055 logDebugMessage(__FUNCTION__, __LINE__, $message);
1058 // Task not created so it's a brand-new extension which we need to register and create a task for!
1059 $taskId = createNewTask($subject, $message, 'EXTENSION', 0, getCurrentAdminId(), false);
1066 // Creates a task for automatically deactivated (deprecated) extension
1067 function createExtensionDeactivationTask ($ext_name) {
1068 // Create subject line
1069 $subject = sprintf("[%s:] %s", $ext_name, '{--ADMIN_TASK_EXTENSION_DEACTIVATED_SUBJECT--}');
1072 $taskId = determineTaskIdBySubject($subject);
1074 // Not installed and do we have created a task for the admin?
1075 if (($taskId == '0') && (isExtensionInstalled($ext_name))) {
1076 // Task not created so add it
1077 $taskId = createNewTask($subject, SQL_ESCAPE(loadTemplate('task_EXTENSION_deactivated', true, $ext_name)), 'EXTENSION_DEACTIVATION');
1084 // Determines the task id for given extension
1085 function determineExtensionTaskId ($ext_name) {
1086 // Default is not found
1087 $data['task_id'] = '0';
1089 // Search for extension task's id
1090 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1091 array($ext_name), __FUNCTION__, __LINE__);
1094 if (SQL_NUMROWS($result) == 1) {
1095 // Task found so load task's id and register extension...
1096 $data = SQL_FETCHARRAY($result);
1100 SQL_FREERESULT($result);
1103 return $data['task_id'];
1106 // Determines the task id for given subject
1107 function determineTaskIdBySubject ($subject) {
1108 // Default is not found
1109 $data['task_id'] = '0';
1111 // Search for task id
1112 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1113 array($subject), __FUNCTION__, __LINE__);
1116 if (SQL_NUMROWS($result) == 1) {
1117 // Task found so load task's id and register extension...
1118 $data = SQL_FETCHARRAY($result);
1122 SQL_FREERESULT($result);
1125 return $data['task_id'];
1128 // Add updates notes for given version
1129 function addExtensionNotes ($ext_ver) {
1130 // Init notes/content
1134 // Is do we have verbose output enabled?
1135 if ((!isExtensionActive('sql_patches')) || (isVerboseSqlEnabled())) {
1136 // Update notes found?
1137 if ((isExtensionUpdateNoteSet($ext_ver)) && ($ext_ver != '0.0.0')) {
1138 // Update notes found
1141 'notes' => getExtensionUpdateNotes($ext_ver)
1145 setExtensionUpdateNotes('', $ext_ver);
1146 } elseif ($ext_ver == '0.0.0') {
1147 // Is the extension productive?
1148 if (isExtensionProductive(getCurrentExtensionName())) {
1152 'notes' => '{--INITIAL_RELEASE--}'
1158 'notes' => '{--DEVELOPER_RELEASE--}'
1162 // No update notes found
1165 'notes' => '{--NO_UPDATE_NOTICES--}'
1170 $out = loadTemplate('admin_extension_notes', true, $content);
1174 appendExtensionNotes($out);
1177 // Getter for CSS files array
1178 function getExtensionCssFiles () {
1179 // By default no additional CSS files are found
1180 $cssFiles = array();
1182 // Is the array there?
1183 if (isset($GLOBALS['css_files'])) {
1185 $cssFiles = $GLOBALS['css_files'];
1192 // Init CSS files array
1193 function initExtensionCssFiles () {
1195 $GLOBALS['css_files'] = array();
1199 function addExtensionCssFile ($file) {
1200 // Is the array there?
1201 if (!isset($GLOBALS['css_files'])) {
1202 // Then auto-init them
1203 initExtensionCssFiles();
1207 array_push($GLOBALS['css_files'], $file);
1210 // Setter for EXT_ALWAYS_ACTIVE flag
1211 function setExtensionAlwaysActive ($active) {
1212 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1215 // Getter for EXT_ALWAYS_ACTIVE flag
1216 function getThisExtensionAlwaysActive () {
1217 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1220 // Checks whether the current extension is always active
1221 function isThisExtensionAlwaysActive () {
1222 return (getThisExtensionAlwaysActive() == 'Y');
1225 // Setter for EXT_VERSION flag
1226 function setThisExtensionVersion ($ext_version) {
1227 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $ext_version;
1230 // Getter for EXT_VERSION flag
1231 function getThisExtensionVersion () {
1232 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1235 // Setter for EXT_DEPRECATED flag
1236 function setExtensionDeprecated ($deprecated) {
1237 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1240 // Getter for EXT_DEPRECATED flag
1241 function isExtensionDeprecated ($ext_name = NULL) {
1242 // Default is from current (NULL) extension
1243 $isDeprecated = ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1246 if (!is_null($ext_name)) {
1247 // Then use it instead
1248 $isDeprecated = ((isset($GLOBALS['ext_deprecated'][$ext_name])) && ($GLOBALS['ext_deprecated'][$ext_name] == 'Y'));
1252 return $isDeprecated;
1255 // Setter for EXT_UPDATE_DEPENDS flag
1256 function addExtensionDependency ($updateDepends) {
1257 // Is the update depency empty? (NEED TO BE FIXED!)
1258 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - ENTERED!');
1259 if (empty($updateDepends)) {
1260 // Please report this bug!
1261 reportBug(__FUNCTION__, __LINE__, 'updateDepends is empty: currentExtension=' . getCurrentExtensionName());
1264 // Is it not yet added?
1265 if ((isset($updateDepends, $GLOBALS['ext_running_updates'][getCurrentExtensionName()])) && (in_array($updateDepends, getExtensionUpdatesRunning()))) {
1267 * Double-adding happens when the extension and an update of the same
1268 * extension requires the same other extension again.
1270 logDebugMessage(__FUNCTION__, __LINE__, 'updateDepends=' . $updateDepends . ',extensionMode=' . getExtensionMode() . ',currentExtension=' . getCurrentExtensionName() . ' - called twice.');
1274 // Add it to the list of extension update depencies map
1275 array_push($GLOBALS['ext_update_depends'][getCurrentExtensionName()], $updateDepends);
1277 // Remember it in the list of running updates
1278 array_push($GLOBALS['ext_running_updates'][getCurrentExtensionName()], $updateDepends);
1279 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - EXIT!');
1282 // Getter for running updates
1283 function getExtensionUpdatesRunning () {
1284 return $GLOBALS['ext_running_updates'][getCurrentExtensionName()];
1287 // Checks whether the given extension registration is in progress
1288 function isExtensionRegistrationRunning ($ext_name) {
1290 $isRunning = ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1293 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
1297 // Init EXT_UPDATE_DEPENDS flag
1298 function initExtensionUpdateDependencies () {
1299 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - ENTERED!');
1301 // Init update depency map automatically if not found
1302 if (isExtensionUpdateDependenciesInitialized()) {
1303 // We need these bug reports as well...
1304 reportBug(__FUNCTION__, __LINE__, '() is called twice: currName=' . getCurrentExtensionName());
1307 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1309 // Init running updates array
1310 initExtensionRuningUpdates();
1312 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - EXIT!');
1315 // Adds an extension as "registration in progress"
1316 function addExtensionRunningRegistration ($ext_name) {
1318 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - ENTERED!');
1319 if (isExtensionRegistrationRunning($ext_name)) {
1320 // This is really bad and should not be quietly ignored
1321 reportBug(__FUNCTION__, __LINE__, '() already called! ext_name=' . $ext_name);
1325 array_push($GLOBALS['ext_register_running'], $ext_name);
1326 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - EXIT!');
1329 // Checks whether EXT_UPDATE_DEPENDS is initialized
1330 function isExtensionUpdateDependenciesInitialized () {
1331 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1332 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1335 // Checks whether an update is already running for given extension
1336 function isExtensionUpdateRunning ($ext_name, $ignoreDependencies = false) {
1337 // Current and given extensions means whole array
1338 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
1339 if ($ext_name == getCurrentExtensionName()) {
1340 // Default is not found
1343 // Walk through whole array
1344 foreach ($GLOBALS['ext_running_updates'] as $ext1 => $depends) {
1346 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',depends=' . print_r($depends, true));
1347 if (($ext1 == $ext_name) || ((in_array($ext_name, $depends)) && ($ignoreDependencies === false))) {
1350 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',isRunning=true - FOUND!');
1356 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - ALT-EXIT!');
1361 $isRunning = ((isExtensionUpdateDependenciesInitialized()) && (in_array($ext_name, getExtensionRunningUpdates())));
1364 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - EXIT!');
1368 // Initializes the list of running updates
1369 function initExtensionRuningUpdates () {
1370 // Auto-init ext_running_updates
1371 if (!isset($GLOBALS['ext_running_updates'])) {
1372 $GLOBALS['ext_running_updates'] = array();
1373 $GLOBALS['ext_register_running'] = array();
1377 // Getter for EXT_UPDATE_DEPENDS flag
1378 function getExtensionUpdateDependencies () {
1379 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1380 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1383 // Getter for next iterator depency
1384 function getExtensionUpdateDependenciesIterator () {
1385 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1386 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1389 // Counter for extension update depencies
1390 function countExtensionUpdateDependencies () {
1391 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '=' . count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1392 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1395 // Removes given extension from update denpency list
1396 function removeExtensionDependency ($ext_name) {
1398 $key = array_search($ext_name, getExtensionUpdateDependencies());
1401 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',key[' . gettype($key) . ']=' . $key);
1404 if ($key !== false) {
1406 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1408 // And sort the array
1409 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1413 // Init iterator for update depencies
1414 function initExtensionUpdateIterator () {
1415 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1416 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
1419 // Getter for depency iterator
1420 function getExtensionUpdateIterator () {
1421 // Auto-init iterator
1422 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) {
1423 // Initialize update iterator
1424 initExtensionUpdateIterator();
1428 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '=' . $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1429 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1432 // Increments the update iterator
1433 function incrementExtensionUpdateIterator () {
1434 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1435 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1438 // Setter for EXT_REPORTS_FAILURE flag
1439 function enableExtensionReportingFailure ($reportsFailure = false) {
1440 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1443 // Getter for EXT_REPORTS_FAILURE flag
1444 function isExtensionReportingFailure () {
1445 return $GLOBALS['ext_reports_failure'];
1448 // Setter for EXT_VER_HISTORY flag
1449 function setExtensionVersionHistory ($versionHistory) {
1450 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $versionHistory;
1453 // Getter for EXT_VER_HISTORY array
1454 function getExtensionVersionHistory () {
1456 if (!isset($GLOBALS['ext_ver_history'][getCurrentExtensionName()])) {
1457 // Then abort here to a avoid an ugly "Undefined index" error
1458 reportBug(__FUNCTION__, __LINE__, 'Extension ext-' . getCurrentExtensionName() . ' has no history set! Is this extension empty?');
1461 // Return the history
1462 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1465 // Setter for EXT_UPDATE_NOTICES
1466 function setExtensionUpdateNotes ($updateNotes, $ext_ver = '') {
1468 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ',getExtensionMode()=' . getExtensionMode() . ',ext_ver=' . $ext_ver . '/' . getCurrentExtensionVersion() . ',updateNotes(length)=' . strlen($updateNotes));
1469 if (empty($ext_ver)) {
1470 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1472 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver] = (string) $updateNotes;
1476 // Getter for EXT_UPDATE_NOTICES
1477 function getExtensionUpdateNotes ($ext_ver) {
1478 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver];
1481 // Checks if ext_update_notes is set
1482 function isExtensionUpdateNoteSet ($ext_ver) {
1483 return isset($GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver]);
1486 // Init extension notice
1487 function initExtensionNotes ($force = false) {
1488 // Is it already initialized?
1489 if (($force === false) && (isset($GLOBALS['ext_notes'][getCurrentExtensionName()]))) {
1490 // This is mostly not wanted, so please report it
1491 reportBug(__FUNCTION__, __LINE__, 'ext_notes already set for extension ' . getCurrentExtensionName());
1494 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName());
1495 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1498 // Append extension notice
1499 function appendExtensionNotes ($notes) {
1500 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ', notes(length)=' . strlen($notes));
1501 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1504 // Getter for extension notes
1505 function getExtensionNotes () {
1506 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1509 // Setter for current extension name
1510 function setCurrentExtensionName ($ext_name) {
1511 $GLOBALS['curr_extension_name'] = (string) trim($ext_name);
1514 // Getter for current extension name
1515 function getCurrentExtensionName () {
1516 if (!isset($GLOBALS['curr_extension_name'])) {
1518 reportBug(__FUNCTION__, __LINE__, 'curr_extension_name not initialized. Please execute initExtensionSqls() before calling this function.');
1522 return $GLOBALS['curr_extension_name'];
1525 // Init SQLs array for current extension
1526 function initExtensionSqls ($force = false) {
1527 // Auto-init the array or if forced
1528 if (($force === true) || (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()]))) {
1530 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1532 // Initialize the generic array
1537 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1538 function addExtensionSql ($sql) {
1540 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql);
1541 array_push($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()], $sql);
1544 // Getter for SQLs array for current extension
1545 function getExtensionSqls () {
1546 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1547 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1548 // Not found, should not happen
1549 reportBug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1550 getCurrentExtensionName()
1555 return $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1558 // Count SQLs for current extension
1559 function countExtensionSqls () {
1560 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1561 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1562 // Not found, should not happen
1563 reportBug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1564 getCurrentExtensionName()
1569 return count($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1572 // Removes SQLs for current extension
1573 function unsetExtensionSqls () {
1574 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1577 // Auto-initializes the removal list
1578 function initExtensionRemovalList () {
1579 // Is the remove list there?
1580 if (!isset($GLOBALS['ext_update_remove'])) {
1582 $GLOBALS['ext_update_remove'] = array();
1586 // Checks whether the current extension is on the removal list
1587 function isExtensionOnRemovalList () {
1588 // Init removal list
1589 initExtensionRemovalList();
1592 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1595 // Adds the current extension to the removal list
1596 function addCurrentExtensionToRemovalList () {
1598 array_push($GLOBALS['ext_update_remove'], getCurrentExtensionName());
1601 // Getter for removal list
1602 function getExtensionRemovalList () {
1603 // Return the removal list
1604 return $GLOBALS['ext_update_remove'];
1607 // Redirects if the provided extension is not installed
1608 function redirectOnUninstalledExtension ($ext_name) {
1609 // So is the extension there?
1610 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1611 // Redirect to index
1612 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1616 // Filter for initialization of all extensions by loading them in 'init' mode
1617 function FILTER_INIT_EXTENSIONS () {
1618 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ENTERED!');
1619 // Init notification pool
1620 initIncludePool('notify');
1622 // Do we have some entries?
1623 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1624 // Load all found extensions if found
1625 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - START!');
1626 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1628 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - START');
1629 loadExtension($ext_name, 'init', getExtensionVersion($ext_name));
1630 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - END');
1632 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - END!');
1635 // Run any notifications
1636 runFilterChain('load_includes', 'notify');
1638 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'EXIT!');
1641 // Setter for extension mode
1642 function setExtensionMode ($ext_mode) {
1643 $GLOBALS['ext_mode'] = (string) $ext_mode;
1646 // Getter for extension mode
1647 function getExtensionMode () {
1648 return $GLOBALS['ext_mode'];
1651 // Setter for dry-run
1652 function enableExtensionDryRun ($dry_run = true) {
1653 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()='.getCurrentExtensionName().',dry_run='.intval($dry_run));
1654 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1657 // Getter for dry-run
1658 function isExtensionDryRun () {
1659 return $GLOBALS['ext_dry_run'];
1662 // Setter for current extension version
1663 function setCurrentExtensionVersion ($ext_ver) {
1664 // ext_ver should never be empty in other modes than 'test'
1665 if ((empty($ext_ver)) && (getExtensionMode() != 'test')) {
1666 // Please report all these messages
1667 reportBug(__FUNCTION__, __LINE__, 'ext_ver is empty. Current extension name: ' . getCurrentExtensionName() . ', mode=' . getExtensionMode());
1671 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver[' . gettype($ext_ver) . ']=' . $ext_ver);
1672 $GLOBALS['ext_current_version'][getCurrentExtensionName()] = (string) $ext_ver;
1675 // Getter for current extension version
1676 function getCurrentExtensionVersion () {
1677 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $GLOBALS['ext_current_version'][getCurrentExtensionName()]);
1678 return $GLOBALS['ext_current_version'][getCurrentExtensionName()];
1681 // Remove the extension from cache array
1682 function removeExtensionFromArray () {
1683 // "Cache" this name
1684 $ext_name = getCurrentExtensionName();
1686 // Now loop through the whole cache
1687 foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) {
1688 // Is it an element?
1689 if (isset($cacheArray[$ext_name])) {
1691 unset($cacheArray[$ext_name]);
1692 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1695 $key = array_search($ext_name, $cacheArray);
1698 if ($key !== false) {
1699 // Found, so remove it
1700 unset($cacheArray[$key]);
1701 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1706 // Remove from other caches as well
1707 unset($GLOBALS['ext_is_installed'][$ext_name]);
1708 unset($GLOBALS['loaded_extension'][$ext_name]);
1711 // "Getter" for 'extension has a CSS file' (with same name, of course)
1712 function getExtensionHasCss () {
1713 // Do we have cache?
1714 if (!isset($GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()])) {
1715 // Construct FQFN for check
1716 $FQFN = sprintf("%stheme/%s/css/%s.css",
1719 getCurrentExtensionName()
1723 $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()] = convertBooleanToYesNo(isFileReadable($FQFN));
1727 return $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()];
1730 // Checks whether the given extension has a language file
1731 function ifExtensionHasLanguageFile ($ext_name) {
1732 // Do we have cache?
1733 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1735 incrementStatsEntry('cache_hits');
1737 // Determine it and put it in cache
1738 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = convertBooleanToYesNo(isLanguageIncludeReadable($ext_name));
1742 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1745 // Load current extension's include file
1746 function loadCurrentExtensionInclude () {
1748 if (!isExtensionIncludeReadable()) {
1750 reportBug(__FUNCTION__, __LINE__, 'Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1753 // Generate INC name
1754 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1760 // Checks whether an extension is readable
1761 function isExtensionIncludeReadable ($ext_name = '') {
1762 // If empty, use current
1763 if (empty($ext_name)) {
1764 $ext_name = getCurrentExtensionName();
1768 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1769 // Generate INC name
1770 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1773 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1777 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
1778 return $GLOBALS['ext_inc_readable'][$ext_name];
1781 // Checks if an extension's function file is readable
1782 function isExtensionFunctionFileReadable ($ext_name) {
1784 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name);
1785 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1786 // Just count cache hits
1787 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] .' - CACHE!');
1788 incrementStatsEntry('cache_hits');
1790 // Construct IFN for functions file
1791 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1793 // Is this include there?
1794 $isIncludeFound = ((isFileReadable($funcsInclude)) && (!isExtensionLibraryLoaded($ext_name)) && (getExtensionMode() == 'test'));
1796 // And put in cache, converted
1797 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = convertBooleanToYesNo($isIncludeFound);
1801 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name]);
1802 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1805 // Adds a CREATE TABLE statement if the requested table is not there
1806 function addCreateTableSql ($tableName, $sql, $comment) {
1807 // Is the table not there?
1808 if (!isSqlTableCreated($tableName)) {
1809 // Is not found, so add it
1810 addExtensionSql('CREATE TABLE
1811 `{?_MYSQL_PREFIX?}_' . $tableName . '` (' . $sql . ')
1812 ENGINE = {?_TABLE_TYPE?}
1814 COLLATE utf8_general_ci
1815 COMMENT ' . chr(39) . $comment . chr(39));
1817 // Is already there, which should not happen
1818 reportBug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
1822 // Adds a DROP TABLE statement if the requested tabled is there
1823 function addDropTableSql ($tableName) {
1824 // Is the table there?
1825 if (isSqlTableCreated($tableName)) {
1826 // Then add it, non-existing tables can be ignored because it will
1827 // happen with every newly installed extension.
1828 addExtensionSql('DROP TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '`');
1831 $GLOBALS['isSqlTableCreated'][$tableName] = false;
1835 // Adds an admin menu to the SQL queue of the menu entry is not found
1836 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1837 // Now check if this menu is there
1838 if (!isMenuActionValid('admin', $action, $what)) {
1840 if (is_null($what)) {
1842 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1850 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1859 // Add it to the queue
1860 addExtensionSql($sql);
1861 } elseif (isDebugModeEnabled()) {
1862 // Double menus should be located and fixed!
1863 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1867 // Adds a guest menu to the SQL queue if the menu entry is not found
1868 function addGuestMenuSql ($action, $what, $title, $sort) {
1869 // Now check if this menu is there
1870 if (!isMenuActionValid('guest', $action, $what)) {
1872 if (is_null($what)) {
1874 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1881 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1889 // Add it to the queue
1890 addExtensionSql($sql);
1891 } elseif (isDebugModeEnabled()) {
1892 // Double menus should be located and fixed!
1893 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1897 // Adds a member menu to the SQL queue if the menu entry is not found
1898 function addMemberMenuSql ($action, $what, $title, $sort) {
1899 // Now check if this menu is there
1900 if (!isMenuActionValid('member', $action, $what)) {
1902 if (is_null($what)) {
1904 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1911 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1919 // Add it to the queue
1920 addExtensionSql($sql);
1921 } elseif (isDebugModeEnabled()) {
1922 // Double menus should be located and fixed!
1923 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1927 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1928 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1929 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1930 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1932 if (is_null($what)) {
1934 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1942 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1951 // Add it to the queue
1952 addExtensionSql($sql);
1953 } elseif (isDebugModeEnabled()) {
1954 // Double menus should be located and fixed!
1955 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s,what=%s,title=%s,active=%s detected.", $action, $what, $title, $active));
1959 // Add configuration entry if not found for actual extension
1960 function addConfigAddSql ($columnName, $columnSql) {
1961 // Is the column there?
1962 if (!isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1963 // Not found, so add it
1964 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `' . $columnName . '` ' . $columnSql);
1965 } elseif (isDebugModeEnabled()) {
1967 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' already created. columnSql=' . $columnSql);
1971 // Drop configuration entry if found for actual extension
1972 function addConfigDropSql ($columnName) {
1973 // Is the column there?
1974 if (isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1976 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` DROP `' . $columnName . '`');
1977 } elseif (isDebugModeEnabled()) {
1978 // Add debug line, reportBug() would cause some extenion updates fail
1979 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' not found.');
1983 // Change configuration entry for actual extension
1984 function addConfigChangeSql ($oldColumnName, $newColumnName, $columnSql) {
1985 // Add the SQL statement
1986 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` CHANGE `' . $oldColumnName . '` `' . $newColumnName . '` ' . $columnSql);
1989 // Enables/disables productive mode for current extension (used only while
1991 // @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
1992 function enableExtensionProductive ($isProductive = true) {
1993 // Log debug message
1994 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',isProductive=', intval($isProductive));
1997 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
2000 // Checks whether the extension is in productive phase. If not set, development
2001 // phase (=false) is assumed.
2002 function isExtensionProductive ($ext_name = '') {
2003 // Is the extension name empty? Then use current
2004 if (empty($ext_name)) {
2005 // Get current extension name
2006 $ext_name = getCurrentExtensionName();
2008 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
2010 // Do we have cache?
2011 if (!isset($GLOBALS[__FUNCTION__][$ext_name])) {
2012 // Load extension only if not yet loaded
2013 if (!isset($GLOBALS['ext_productive'][$ext_name])) {
2014 // Load extension in test mode
2015 loadExtension($ext_name, 'test');
2019 $GLOBALS[__FUNCTION__][$ext_name] = ((isset($GLOBALS['ext_productive'][$ext_name])) && ($GLOBALS['ext_productive'][$ext_name] === true));
2023 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isProductive=', intval($GLOBALS[__FUNCTION__][$ext_name]) . ' - EXIT!');
2024 return $GLOBALS[__FUNCTION__][$ext_name];
2027 // Mark extension file as loaded
2028 function markExtensionAsLoaded ($ext_name) {
2029 // Is it already loaded?
2030 if (isExtensionLoaded($ext_name)) {
2032 reportBug(__FUNCTION__, __LINE__, 'Extension ' . $ext_name . ' is already marked as loaded!');
2036 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_loaded=true');
2037 $GLOBALS['ext_loaded']['ext_name'][$ext_name] = true;
2040 // Determine whether the given extension is already loaded
2041 function isExtensionLoaded ($ext_name) {
2043 return ((isset($GLOBALS['ext_loaded']['ext_name'][$ext_name])) && ($GLOBALS['ext_loaded']['ext_name'][$ext_name] === true));
2046 // Mark extension's library file as loaded
2047 function markExtensionLibraryAsLoaded ($ext_name) {
2048 // Is it already loaded?
2049 if (isExtensionLibraryLoaded($ext_name)) {
2051 reportBug(__FUNCTION__, __LINE__, 'Extension library ' . $ext_name . ' is already marked as loaded!');
2055 $GLOBALS['ext_loaded']['library'][$ext_name] = true;
2058 // Determine whether the given extension's library is already loaded
2059 function isExtensionLibraryLoaded ($ext_name) {
2061 return ((isset($GLOBALS['ext_loaded']['library'][$ext_name])) && ($GLOBALS['ext_loaded']['library'][$ext_name] === true));