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, $inRebuild = false) {
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);
981 // Do not rebuild cache if it is already been rebuild
982 if ($inRebuild === false) {
984 rebuildCache('extension', 'extension');
988 sendAdminNotification(
989 '{--ADMIN_EXTENSION_DEACTIVATED_SUBJECT--}',
990 'admin_extension_deactivated',
991 array('ext_name' => $ext_name)
995 // Checks whether the extension is older than given
996 function isExtensionOlder ($ext_name, $ext_ver) {
997 // Get current extension version
998 $currVersion = getExtensionVersion($ext_name);
1000 // Remove all dots from both versions
1001 $currVersion = str_replace('.', '', $currVersion);
1002 $ext_ver = str_replace('.', '', $ext_ver);
1004 // Now compare both and return the result
1005 return ($currVersion < $ext_ver);
1008 // Creates a new task for updated extension
1009 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
1010 // Create subject line
1011 $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXTENSION_SUBJECT--}';
1014 $taskId = determineTaskIdBySubject($subject);
1016 // Is the extension there?
1017 if (isExtensionInstalled($ext_name)) {
1018 // Check if task is not there
1019 if ($taskId == '0') {
1020 // Create extension update-task
1021 $taskId = createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
1024 // Extension not there! :-(
1025 reportBug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> not found but should be updated?", $ext_name));
1032 // Creates a new task for newly installed extension
1033 function createNewExtensionTask ($ext_name) {
1034 // Generate subject line
1035 $subject = sprintf("[%s:]", $ext_name);
1038 $taskId = determineTaskIdBySubject($subject);
1040 // Not installed and do we have created a task for the admin?
1041 if (($taskId == '0') && (!isExtensionInstalled($ext_name))) {
1042 // Set default message if ext-foo is missing
1043 $message = '{%message,ADMIN_EXTENSION_TEXT_FILE_MISSING=' . $ext_name . '%}';
1046 $FQFN = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
1052 // Load text for task if found
1053 if (isFileReadable($FQFN)) {
1054 // Load extension's description template (but do not compile the code)
1055 $message = loadTemplate('ext_' . $ext_name, true, array(), false);
1057 // Write this in debug.log as well
1058 logDebugMessage(__FUNCTION__, __LINE__, $message);
1061 // Task not created so it's a brand-new extension which we need to register and create a task for!
1062 $taskId = createNewTask($subject, $message, 'EXTENSION', 0, getCurrentAdminId(), false);
1069 // Creates a task for automatically deactivated (deprecated) extension
1070 function createExtensionDeactivationTask ($ext_name) {
1071 // Create subject line
1072 $subject = sprintf("[%s:] %s", $ext_name, '{--ADMIN_TASK_EXTENSION_DEACTIVATED_SUBJECT--}');
1075 $taskId = determineTaskIdBySubject($subject);
1077 // Not installed and do we have created a task for the admin?
1078 if (($taskId == '0') && (isExtensionInstalled($ext_name))) {
1079 // Task not created so add it
1080 $taskId = createNewTask($subject, SQL_ESCAPE(loadTemplate('task_EXTENSION_deactivated', true, $ext_name)), 'EXTENSION_DEACTIVATION');
1087 // Determines the task id for given extension
1088 function determineExtensionTaskId ($ext_name) {
1089 // Default is not found
1090 $data['task_id'] = '0';
1092 // Search for extension task's id
1093 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1",
1094 array($ext_name), __FUNCTION__, __LINE__);
1097 if (SQL_NUMROWS($result) == 1) {
1098 // Task found so load task's id and register extension...
1099 $data = SQL_FETCHARRAY($result);
1103 SQL_FREERESULT($result);
1106 return $data['task_id'];
1109 // Determines the task id for given subject
1110 function determineTaskIdBySubject ($subject) {
1111 // Default is not found
1112 $data['task_id'] = '0';
1114 // Search for task id
1115 $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `subject` LIKE '%s%%' LIMIT 1",
1116 array($subject), __FUNCTION__, __LINE__);
1119 if (SQL_NUMROWS($result) == 1) {
1120 // Task found so load task's id and register extension...
1121 $data = SQL_FETCHARRAY($result);
1125 SQL_FREERESULT($result);
1128 return $data['task_id'];
1131 // Add updates notes for given version
1132 function addExtensionNotes ($ext_ver) {
1133 // Init notes/content
1137 // Is do we have verbose output enabled?
1138 if ((!isExtensionActive('sql_patches')) || (isVerboseSqlEnabled())) {
1139 // Update notes found?
1140 if ((isExtensionUpdateNoteSet($ext_ver)) && ($ext_ver != '0.0.0')) {
1141 // Update notes found
1144 'notes' => getExtensionUpdateNotes($ext_ver)
1148 setExtensionUpdateNotes('', $ext_ver);
1149 } elseif ($ext_ver == '0.0.0') {
1150 // Is the extension productive?
1151 if (isExtensionProductive(getCurrentExtensionName())) {
1155 'notes' => '{--INITIAL_RELEASE--}'
1161 'notes' => '{--DEVELOPER_RELEASE--}'
1165 // No update notes found
1168 'notes' => '{--NO_UPDATE_NOTICES--}'
1173 $out = loadTemplate('admin_extension_notes', true, $content);
1177 appendExtensionNotes($out);
1180 // Getter for CSS files array
1181 function getExtensionCssFiles () {
1182 // By default no additional CSS files are found
1183 $cssFiles = array();
1185 // Is the array there?
1186 if (isset($GLOBALS['css_files'])) {
1188 $cssFiles = $GLOBALS['css_files'];
1195 // Init CSS files array
1196 function initExtensionCssFiles () {
1198 $GLOBALS['css_files'] = array();
1202 function addExtensionCssFile ($file) {
1203 // Is the array there?
1204 if (!isset($GLOBALS['css_files'])) {
1205 // Then auto-init them
1206 initExtensionCssFiles();
1210 array_push($GLOBALS['css_files'], $file);
1213 // Setter for EXT_ALWAYS_ACTIVE flag
1214 function setExtensionAlwaysActive ($active) {
1215 $GLOBALS['ext_always_active'][getCurrentExtensionName()] = (string) $active;
1218 // Getter for EXT_ALWAYS_ACTIVE flag
1219 function getThisExtensionAlwaysActive () {
1220 return $GLOBALS['ext_always_active'][getCurrentExtensionName()];
1223 // Checks whether the current extension is always active
1224 function isThisExtensionAlwaysActive () {
1225 return (getThisExtensionAlwaysActive() == 'Y');
1228 // Setter for EXT_VERSION flag
1229 function setThisExtensionVersion ($ext_version) {
1230 $GLOBALS['ext_version'][getCurrentExtensionName()] = (string) $ext_version;
1233 // Getter for EXT_VERSION flag
1234 function getThisExtensionVersion () {
1235 return $GLOBALS['ext_version'][getCurrentExtensionName()];
1238 // Setter for EXT_DEPRECATED flag
1239 function setExtensionDeprecated ($deprecated) {
1240 $GLOBALS['ext_deprecated'][getCurrentExtensionName()] = (string) $deprecated;
1243 // Getter for EXT_DEPRECATED flag
1244 function isExtensionDeprecated ($ext_name = NULL) {
1245 // Default is from current (NULL) extension
1246 $isDeprecated = ($GLOBALS['ext_deprecated'][getCurrentExtensionName()] == 'Y');
1249 if (!is_null($ext_name)) {
1250 // Then use it instead
1251 $isDeprecated = ((isset($GLOBALS['ext_deprecated'][$ext_name])) && ($GLOBALS['ext_deprecated'][$ext_name] == 'Y'));
1255 return $isDeprecated;
1258 // Setter for EXT_UPDATE_DEPENDS flag
1259 function addExtensionDependency ($updateDepends) {
1260 // Is the update depency empty? (NEED TO BE FIXED!)
1261 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - ENTERED!');
1262 if (empty($updateDepends)) {
1263 // Please report this bug!
1264 reportBug(__FUNCTION__, __LINE__, 'updateDepends is empty: currentExtension=' . getCurrentExtensionName());
1267 // Is it not yet added?
1268 if ((isset($updateDepends, $GLOBALS['ext_running_updates'][getCurrentExtensionName()])) && (in_array($updateDepends, getExtensionUpdatesRunning()))) {
1270 * Double-adding happens when the extension and an update of the same
1271 * extension requires the same other extension again.
1273 logDebugMessage(__FUNCTION__, __LINE__, 'updateDepends=' . $updateDepends . ',extensionMode=' . getExtensionMode() . ',currentExtension=' . getCurrentExtensionName() . ' - called twice.');
1277 // Add it to the list of extension update depencies map
1278 array_push($GLOBALS['ext_update_depends'][getCurrentExtensionName()], $updateDepends);
1281 if ((!isset($GLOBALS['ext_running_updates'][getCurrentExtensionName()])) || (!is_array($GLOBALS['ext_running_updates'][getCurrentExtensionName()]))) {
1282 $GLOBALS['ext_running_updates'][getCurrentExtensionName()] = array();
1285 // Remember it in the list of running updates
1286 array_push($GLOBALS['ext_running_updates'][getCurrentExtensionName()], $updateDepends);
1287 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '/' . $updateDepends . ',extensionMode=' . getExtensionMode() . ' - EXIT!');
1290 // Getter for running updates
1291 function getExtensionUpdatesRunning () {
1292 return $GLOBALS['ext_running_updates'][getCurrentExtensionName()];
1295 // Checks whether the given extension registration is in progress
1296 function isExtensionRegistrationRunning ($ext_name) {
1298 $isRunning = ((isset($GLOBALS['ext_register_running'])) && (in_array($ext_name, $GLOBALS['ext_register_running'])));
1301 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
1305 // Init EXT_UPDATE_DEPENDS flag
1306 function initExtensionUpdateDependencies () {
1307 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - ENTERED!');
1309 // Init update depency map automatically if not found
1310 if (isExtensionUpdateDependenciesInitialized()) {
1311 // We need these bug reports as well...
1312 reportBug(__FUNCTION__, __LINE__, '() is called twice: currName=' . getCurrentExtensionName());
1315 $GLOBALS['ext_update_depends'][getCurrentExtensionName()] = array();
1317 // Init running updates array
1318 initExtensionRuningUpdates();
1320 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - EXIT!');
1323 // Adds an extension as "registration in progress"
1324 function addExtensionRunningRegistration ($ext_name) {
1326 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - ENTERED!');
1327 if (isExtensionRegistrationRunning($ext_name)) {
1328 // This is really bad and should not be quietly ignored
1329 reportBug(__FUNCTION__, __LINE__, '() already called! ext_name=' . $ext_name);
1333 array_push($GLOBALS['ext_register_running'], $ext_name);
1334 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Registration in progress: ext_name=' . $ext_name . ' - EXIT!');
1337 // Checks whether EXT_UPDATE_DEPENDS is initialized
1338 function isExtensionUpdateDependenciesInitialized () {
1339 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1340 return (isset($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1343 // Checks whether an update is already running for given extension
1344 function isExtensionUpdateRunning ($ext_name, $ignoreDependencies = false) {
1345 // Current and given extensions means whole array
1346 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!');
1347 if ($ext_name == getCurrentExtensionName()) {
1348 // Default is not found
1351 // Walk through whole array
1352 foreach ($GLOBALS['ext_running_updates'] as $ext1 => $depends) {
1354 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',depends=' . print_r($depends, true));
1355 if (($ext1 == $ext_name) || ((in_array($ext_name, $depends)) && ($ignoreDependencies === false))) {
1358 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',isRunning=true - FOUND!');
1364 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - ALT-EXIT!');
1369 $isRunning = ((isExtensionUpdateDependenciesInitialized()) && (in_array($ext_name, getExtensionRunningUpdates())));
1372 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',ignoreDependencies=' . intval($ignoreDependencies) . ', isRunning=' . intval($isRunning) . ' - EXIT!');
1376 // Initializes the list of running updates
1377 function initExtensionRuningUpdates () {
1378 // Auto-init ext_running_updates
1379 if (!isset($GLOBALS['ext_running_updates'])) {
1380 $GLOBALS['ext_running_updates'] = array();
1381 $GLOBALS['ext_register_running'] = array();
1385 // Getter for EXT_UPDATE_DEPENDS flag
1386 function getExtensionUpdateDependencies () {
1387 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1388 return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
1391 // Getter for next iterator depency
1392 function getExtensionUpdateDependenciesIterator () {
1393 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1394 return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
1397 // Counter for extension update depencies
1398 function countExtensionUpdateDependencies () {
1399 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '=' . count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]));
1400 return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1403 // Removes given extension from update denpency list
1404 function removeExtensionDependency ($ext_name) {
1406 $key = array_search($ext_name, getExtensionUpdateDependencies());
1409 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',key[' . gettype($key) . ']=' . $key);
1412 if ($key !== false) {
1414 unset($GLOBALS['ext_update_depends'][getCurrentExtensionName()][$key]);
1416 // And sort the array
1417 ksort($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
1421 // Init iterator for update depencies
1422 function initExtensionUpdateIterator () {
1423 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1424 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
1427 // Getter for depency iterator
1428 function getExtensionUpdateIterator () {
1429 // Auto-init iterator
1430 if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) {
1431 // Initialize update iterator
1432 initExtensionUpdateIterator();
1436 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . '=' . $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
1437 return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
1440 // Increments the update iterator
1441 function incrementExtensionUpdateIterator () {
1442 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
1443 $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
1446 // Setter for EXT_REPORTS_FAILURE flag
1447 function enableExtensionReportingFailure ($reportsFailure = false) {
1448 $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
1451 // Getter for EXT_REPORTS_FAILURE flag
1452 function isExtensionReportingFailure () {
1453 return $GLOBALS['ext_reports_failure'];
1456 // Setter for EXT_VER_HISTORY flag
1457 function setExtensionVersionHistory ($versionHistory) {
1458 $GLOBALS['ext_ver_history'][getCurrentExtensionName()] = (array) $versionHistory;
1461 // Getter for EXT_VER_HISTORY array
1462 function getExtensionVersionHistory () {
1464 if (!isset($GLOBALS['ext_ver_history'][getCurrentExtensionName()])) {
1465 // Then abort here to a avoid an ugly "Undefined index" error
1466 reportBug(__FUNCTION__, __LINE__, 'Extension ext-' . getCurrentExtensionName() . ' has no history set! Is this extension empty?');
1469 // Return the history
1470 return $GLOBALS['ext_ver_history'][getCurrentExtensionName()];
1473 // Setter for EXT_UPDATE_NOTICES
1474 function setExtensionUpdateNotes ($updateNotes, $ext_ver = '') {
1476 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ',getExtensionMode()=' . getExtensionMode() . ',ext_ver=' . $ext_ver . '/' . getCurrentExtensionVersion() . ',updateNotes(length)=' . strlen($updateNotes));
1477 if (empty($ext_ver)) {
1478 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][getCurrentExtensionVersion()] = (string) $updateNotes;
1480 $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver] = (string) $updateNotes;
1484 // Getter for EXT_UPDATE_NOTICES
1485 function getExtensionUpdateNotes ($ext_ver) {
1486 return $GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver];
1489 // Checks if ext_update_notes is set
1490 function isExtensionUpdateNoteSet ($ext_ver) {
1491 return isset($GLOBALS['ext_update_notes'][getCurrentExtensionName()][$ext_ver]);
1494 // Init extension notice
1495 function initExtensionNotes ($force = false) {
1496 // Is it already initialized?
1497 if (($force === false) && (isset($GLOBALS['ext_notes'][getCurrentExtensionName()]))) {
1498 // This is mostly not wanted, so please report it
1499 reportBug(__FUNCTION__, __LINE__, 'ext_notes already set for extension ' . getCurrentExtensionName());
1502 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName());
1503 $GLOBALS['ext_notes'][getCurrentExtensionName()] = '';
1506 // Append extension notice
1507 function appendExtensionNotes ($notes) {
1508 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()=' . getCurrentExtensionName() . ', notes(length)=' . strlen($notes));
1509 $GLOBALS['ext_notes'][getCurrentExtensionName()] .= (string) trim($notes);
1512 // Getter for extension notes
1513 function getExtensionNotes () {
1514 return $GLOBALS['ext_notes'][getCurrentExtensionName()];
1517 // Setter for current extension name
1518 function setCurrentExtensionName ($ext_name) {
1519 $GLOBALS['curr_extension_name'] = (string) trim($ext_name);
1522 // Getter for current extension name
1523 function getCurrentExtensionName () {
1524 if (!isset($GLOBALS['curr_extension_name'])) {
1526 reportBug(__FUNCTION__, __LINE__, 'curr_extension_name not initialized. Please execute initExtensionSqls() before calling this function.');
1530 return $GLOBALS['curr_extension_name'];
1533 // Init SQLs array for current extension
1534 function initExtensionSqls ($force = false) {
1535 // Auto-init the array or if forced
1536 if (($force === true) || (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()]))) {
1538 $GLOBALS['ext_sqls'][getCurrentExtensionName()] = array();
1540 // Initialize the generic array
1545 // Adds SQLs to the SQLs array but "assigns" it with current extension name
1546 function addExtensionSql ($sql) {
1547 // Is is the array there?
1548 if ((!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()])) || (!is_array($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()]))) {
1550 $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()] = array();
1554 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql);
1555 array_push($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()], $sql);
1558 // Getter for SQLs array for current extension
1559 function getExtensionSqls () {
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 $GLOBALS['ext_sqls'][getCurrentExtensionName()];
1572 // Count SQLs for current extension
1573 function countExtensionSqls () {
1574 // Output debug backtrace if not found (SHOULD NOT HAPPEN!)
1575 if (!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()])) {
1576 // Not found, should not happen
1577 reportBug(__FUNCTION__, __LINE__, sprintf("ext_sqls is empty, current extension: %s",
1578 getCurrentExtensionName()
1583 return count($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1586 // Removes SQLs for current extension
1587 function unsetExtensionSqls () {
1588 unset($GLOBALS['ext_sqls'][getCurrentExtensionName()]);
1591 // Auto-initializes the removal list
1592 function initExtensionRemovalList () {
1593 // Is the remove list there?
1594 if (!isset($GLOBALS['ext_update_remove'])) {
1596 $GLOBALS['ext_update_remove'] = array();
1600 // Checks whether the current extension is on the removal list
1601 function isExtensionOnRemovalList () {
1602 // Init removal list
1603 initExtensionRemovalList();
1606 return (in_array(getCurrentExtensionName(), $GLOBALS['ext_update_remove']));
1609 // Adds the current extension to the removal list
1610 function addCurrentExtensionToRemovalList () {
1612 array_push($GLOBALS['ext_update_remove'], getCurrentExtensionName());
1615 // Getter for removal list
1616 function getExtensionRemovalList () {
1617 // Return the removal list
1618 return $GLOBALS['ext_update_remove'];
1621 // Redirects if the provided extension is not installed
1622 function redirectOnUninstalledExtension ($ext_name) {
1623 // So is the extension there?
1624 if ((!isExtensionInstalled($ext_name)) || (!isExtensionActive($ext_name))) {
1625 // Redirect to index
1626 redirectToUrl('modules.php?module=index&code=' . getCode('EXTENSION_PROBLEM') . '&ext=' . $ext_name);
1630 // Filter for initialization of all extensions by loading them in 'init' mode
1631 function FILTER_INIT_EXTENSIONS () {
1632 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ENTERED!');
1633 // Init notification pool
1634 initIncludePool('notify');
1636 // Do we have some entries?
1637 if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
1638 // Load all found extensions if found
1639 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - START!');
1640 foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
1642 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - START');
1643 loadExtension($ext_name, 'init', getExtensionVersion($ext_name));
1644 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - END');
1646 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - END!');
1649 // Run any notifications
1650 runFilterChain('load_includes', 'notify');
1652 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'EXIT!');
1655 // Setter for extension mode
1656 function setExtensionMode ($ext_mode) {
1657 $GLOBALS['ext_mode'] = (string) $ext_mode;
1660 // Getter for extension mode
1661 function getExtensionMode () {
1662 return $GLOBALS['ext_mode'];
1665 // Setter for dry-run
1666 function enableExtensionDryRun ($dry_run = true) {
1667 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()='.getCurrentExtensionName().',dry_run='.intval($dry_run));
1668 $GLOBALS['ext_dry_run'] = (bool) $dry_run;
1671 // Getter for dry-run
1672 function isExtensionDryRun () {
1673 return $GLOBALS['ext_dry_run'];
1676 // Setter for current extension version
1677 function setCurrentExtensionVersion ($ext_ver) {
1678 // ext_ver should never be empty in other modes than 'test'
1679 if ((empty($ext_ver)) && (getExtensionMode() != 'test')) {
1680 // Please report all these messages
1681 reportBug(__FUNCTION__, __LINE__, 'ext_ver is empty. Current extension name: ' . getCurrentExtensionName() . ', mode=' . getExtensionMode());
1685 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver[' . gettype($ext_ver) . ']=' . $ext_ver);
1686 $GLOBALS['ext_current_version'][getCurrentExtensionName()] = (string) $ext_ver;
1689 // Getter for current extension version
1690 function getCurrentExtensionVersion () {
1691 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $GLOBALS['ext_current_version'][getCurrentExtensionName()]);
1692 return $GLOBALS['ext_current_version'][getCurrentExtensionName()];
1695 // Remove the extension from cache array
1696 function removeExtensionFromArray () {
1697 // "Cache" this name
1698 $ext_name = getCurrentExtensionName();
1700 // Now loop through the whole cache
1701 foreach ($GLOBALS['cache_array']['extension'] as $cacheName => $cacheArray) {
1702 // Is it an element?
1703 if (isset($cacheArray[$ext_name])) {
1705 unset($cacheArray[$ext_name]);
1706 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1709 $key = array_search($ext_name, $cacheArray);
1712 if ($key !== false) {
1713 // Found, so remove it
1714 unset($cacheArray[$key]);
1715 $GLOBALS['cache_array']['extension'][$cacheName] = $cacheArray;
1720 // Remove from other caches as well
1721 unset($GLOBALS['ext_is_installed'][$ext_name]);
1722 unset($GLOBALS['loaded_extension'][$ext_name]);
1725 // "Getter" for 'extension has a CSS file' (with same name, of course)
1726 function getExtensionHasCss () {
1727 // Do we have cache?
1728 if (!isset($GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()])) {
1729 // Construct FQFN for check
1730 $FQFN = sprintf("%stheme/%s/css/%s.css",
1733 getCurrentExtensionName()
1737 $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()] = convertBooleanToYesNo(isFileReadable($FQFN));
1741 return $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()];
1744 // Checks whether the given extension has a language file
1745 function ifExtensionHasLanguageFile ($ext_name) {
1746 // Do we have cache?
1747 if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
1749 incrementStatsEntry('cache_hits');
1751 // Determine it and put it in cache
1752 $GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] = convertBooleanToYesNo(isLanguageIncludeReadable($ext_name));
1756 return ($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name] == 'Y');
1759 // Load current extension's include file
1760 function loadCurrentExtensionInclude () {
1762 if (!isExtensionIncludeReadable()) {
1764 reportBug(__FUNCTION__, __LINE__, 'Extension ' . getCurrentExtensionName() . ' should be loaded, but is not readable.');
1767 // Generate INC name
1768 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1774 // Checks whether an extension is readable
1775 function isExtensionIncludeReadable ($ext_name = '') {
1776 // If empty, use current
1777 if (empty($ext_name)) {
1778 $ext_name = getCurrentExtensionName();
1782 if (!isset($GLOBALS['ext_inc_readable'][$ext_name])) {
1783 // Generate INC name
1784 $INC = sprintf("inc/extensions/ext-%s.php", getCurrentExtensionName());
1787 $GLOBALS['ext_inc_readable'][$ext_name] = isIncludeReadable($INC);
1791 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
1792 return $GLOBALS['ext_inc_readable'][$ext_name];
1795 // Checks if an extension's function file is readable
1796 function isExtensionFunctionFileReadable ($ext_name) {
1798 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name);
1799 if (isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name])) {
1800 // Just count cache hits
1801 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] .' - CACHE!');
1802 incrementStatsEntry('cache_hits');
1804 // Construct IFN for functions file
1805 $funcsInclude = sprintf("inc/libs/%s_functions.php", $ext_name);
1807 // Is this include there?
1808 $isIncludeFound = ((isFileReadable($funcsInclude)) && (!isExtensionLibraryLoaded($ext_name)) && (getExtensionMode() == 'test'));
1810 // And put in cache, converted
1811 $GLOBALS['cache_array']['extension']['ext_func'][$ext_name] = convertBooleanToYesNo($isIncludeFound);
1815 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_func=' . $GLOBALS['cache_array']['extension']['ext_func'][$ext_name]);
1816 return ($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y');
1819 // Adds a CREATE TABLE statement if the requested table is not there
1820 function addCreateTableSql ($tableName, $sql, $comment) {
1821 // Is the table not there?
1822 if (!isSqlTableCreated($tableName)) {
1823 // Is not found, so add it
1824 addExtensionSql('CREATE TABLE
1825 `{?_MYSQL_PREFIX?}_' . $tableName . '` (' . $sql . ')
1826 ENGINE = {?_TABLE_TYPE?}
1828 COLLATE utf8_general_ci
1829 COMMENT ' . chr(39) . $comment . chr(39));
1831 // Is already there, which should not happen
1832 reportBug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
1836 // Adds a DROP TABLE statement if the requested tabled is there
1837 function addDropTableSql ($tableName) {
1838 // Is the table there?
1839 if (isSqlTableCreated($tableName)) {
1840 // Then add it, non-existing tables can be ignored because it will
1841 // happen with every newly installed extension.
1842 addExtensionSql('DROP TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '`');
1845 $GLOBALS['isSqlTableCreated'][$tableName] = false;
1849 // Adds an admin menu to the SQL queue of the menu entry is not found
1850 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
1851 // Now check if this menu is there
1852 if (!isMenuActionValid('admin', $action, $what)) {
1854 if (is_null($what)) {
1856 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1864 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1873 // Add it to the queue
1874 addExtensionSql($sql);
1875 } elseif (isDebugModeEnabled()) {
1876 // Double menus should be located and fixed!
1877 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double admin menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1881 // Adds a guest menu to the SQL queue if the menu entry is not found
1882 function addGuestMenuSql ($action, $what, $title, $sort) {
1883 // Now check if this menu is there
1884 if (!isMenuActionValid('guest', $action, $what)) {
1886 if (is_null($what)) {
1888 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1895 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1903 // Add it to the queue
1904 addExtensionSql($sql);
1905 } elseif (isDebugModeEnabled()) {
1906 // Double menus should be located and fixed!
1907 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double guest menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1911 // Adds a member menu to the SQL queue if the menu entry is not found
1912 function addMemberMenuSql ($action, $what, $title, $sort) {
1913 // Now check if this menu is there
1914 if (!isMenuActionValid('member', $action, $what)) {
1916 if (is_null($what)) {
1918 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)",
1925 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)",
1933 // Add it to the queue
1934 addExtensionSql($sql);
1935 } elseif (isDebugModeEnabled()) {
1936 // Double menus should be located and fixed!
1937 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double member menu action=%s,what=%s,title=%s detected.", $action, $what, $title));
1941 // Adds a sponsor menu to the SQL queue if the menu entry is not found
1942 function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
1943 // Now check if this menu is there, if no ext-sponsor is installed all is not yet added
1944 if ((!isExtensionInstalled('sponsor')) || (!isMenuActionValid('sponsor', $action, $what))) {
1946 if (is_null($what)) {
1948 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)",
1956 $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s','%s','%s','%s',%s)",
1965 // Add it to the queue
1966 addExtensionSql($sql);
1967 } elseif (isDebugModeEnabled()) {
1968 // Double menus should be located and fixed!
1969 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Double sponsor menu action=%s,what=%s,title=%s,active=%s detected.", $action, $what, $title, $active));
1973 // Add configuration entry if not found for actual extension
1974 function addConfigAddSql ($columnName, $columnSql) {
1975 // Is the column there?
1976 if (!isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1977 // Not found, so add it
1978 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `' . $columnName . '` ' . $columnSql);
1979 } elseif (isDebugModeEnabled()) {
1981 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' already created. columnSql=' . $columnSql);
1985 // Drop configuration entry if found for actual extension
1986 function addConfigDropSql ($columnName) {
1987 // Is the column there?
1988 if (isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) {
1990 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` DROP `' . $columnName . '`');
1991 } elseif (isDebugModeEnabled()) {
1992 // Add debug line, reportBug() would cause some extenion updates fail
1993 logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' not found.');
1997 // Change configuration entry for actual extension
1998 function addConfigChangeSql ($oldColumnName, $newColumnName, $columnSql) {
1999 // Add the SQL statement
2000 addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` CHANGE `' . $oldColumnName . '` `' . $newColumnName . '` ' . $columnSql);
2003 // Enables/disables productive mode for current extension (used only while
2005 // @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable'
2006 function enableExtensionProductive ($isProductive = true) {
2007 // Log debug message
2008 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',isProductive=', intval($isProductive));
2011 $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
2014 // Checks whether the extension is in productive phase. If not set, development
2015 // phase (=false) is assumed.
2016 function isExtensionProductive ($ext_name = '') {
2017 // Is the extension name empty? Then use current
2018 if (empty($ext_name)) {
2019 // Get current extension name
2020 $ext_name = getCurrentExtensionName();
2022 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!');
2024 // Do we have cache?
2025 if (!isset($GLOBALS[__FUNCTION__][$ext_name])) {
2026 // Load extension only if not yet loaded
2027 if (!isset($GLOBALS['ext_productive'][$ext_name])) {
2028 // Load extension in test mode
2029 loadExtension($ext_name, 'test');
2033 $GLOBALS[__FUNCTION__][$ext_name] = ((isset($GLOBALS['ext_productive'][$ext_name])) && ($GLOBALS['ext_productive'][$ext_name] === true));
2037 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isProductive=', intval($GLOBALS[__FUNCTION__][$ext_name]) . ' - EXIT!');
2038 return $GLOBALS[__FUNCTION__][$ext_name];
2041 // Mark extension file as loaded
2042 function markExtensionAsLoaded ($ext_name) {
2043 // Is it already loaded?
2044 if (isExtensionLoaded($ext_name)) {
2046 reportBug(__FUNCTION__, __LINE__, 'Extension ' . $ext_name . ' is already marked as loaded!');
2050 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_loaded=true');
2051 $GLOBALS['ext_loaded']['ext_name'][$ext_name] = true;
2054 // Determine whether the given extension is already loaded
2055 function isExtensionLoaded ($ext_name) {
2057 return ((isset($GLOBALS['ext_loaded']['ext_name'][$ext_name])) && ($GLOBALS['ext_loaded']['ext_name'][$ext_name] === true));
2060 // Mark extension's library file as loaded
2061 function markExtensionLibraryAsLoaded ($ext_name) {
2062 // Is it already loaded?
2063 if (isExtensionLibraryLoaded($ext_name)) {
2065 reportBug(__FUNCTION__, __LINE__, 'Extension library ' . $ext_name . ' is already marked as loaded!');
2069 $GLOBALS['ext_loaded']['library'][$ext_name] = true;
2072 // Determine whether the given extension's library is already loaded
2073 function isExtensionLibraryLoaded ($ext_name) {
2075 return ((isset($GLOBALS['ext_loaded']['library'][$ext_name])) && ($GLOBALS['ext_loaded']['library'][$ext_name] === true));