]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions-functions.php
Reverted of changes in 1704, see ticket #160
[mailer.git] / inc / extensions-functions.php
index e26f462871cd34ea878f7241832808b70cd0635c..a33aabce0f13c33ae093a8315cf57f4f0c3310e7 100644 (file)
@@ -18,6 +18,7 @@
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -226,7 +227,7 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
                        incrementExtensionUpdateIterator();
 
                        // Check for required file
-                       if (loadExtension($ext_update, 'register', '', getExtensionDryRun())) {
+                       if ((!isExtensionInstalled($ext_update)) && (loadExtension($ext_update, 'register', '', getExtensionDryRun()))) {
                                // Set current extension name again
                                setCurrentExtensionName($ext_name);
 
@@ -254,12 +255,15 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
                                        } // END - if
                                } elseif ($ext_ver != getCurrentExtensionVersion()) {
                                        // Ok, update this extension now
-                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().",ext_update=".$ext_update.",ext_ver=".$ext_ver."/".getCurrentExtensionVersion()."");
-                                       $GLOBALS['ext_backup'][$ext_update][$ext_ver] = getCurrentExtensionName();
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName='.getCurrentExtensionName().',currVer='.getCurrentExtensionVersion().'');
+                                       $GLOBALS['ext_backup_name'][$ext_update][$ext_ver] = getCurrentExtensionName();
+                                       $GLOBALS['ext_backup_ver'][$ext_update][$ext_ver] = getCurrentExtensionVersion();
                                        updateExtension($ext_update, $ext_ver, getExtensionDryRun());
-                                       setCurrentExtensionName($GLOBALS['ext_backup'][$ext_update][$ext_ver]);
-                                       unset($GLOBALS['ext_backup'][$ext_update][$ext_ver]);
-                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()."");
+                                       setCurrentExtensionName($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
+                                       setCurrentExtensionVersion($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
+                                       unset($GLOBALS['ext_backup_name'][$ext_update][$ext_ver]);
+                                       unset($GLOBALS['ext_backup_ver'][$ext_update][$ext_ver]);
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName='.getCurrentExtensionName().',currVer='.getCurrentExtensionVersion().'');
 
                                        // All okay!
                                        $test = true;
@@ -537,7 +541,7 @@ function getExtensionVersion ($ext_name, $force = false) {
        // Is the cache written?
        if (isset($GLOBALS['cache_array']['extension']['ext_version'][$ext_name])) {
                // Load data from cache
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": CACHE!");
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $ext_name . ': CACHE!');
                $data['ext_version'] = $GLOBALS['cache_array']['extension']['ext_version'][$ext_name];
 
                // Count cache hits
@@ -546,15 +550,15 @@ function getExtensionVersion ($ext_name, $force = false) {
                // Load from database
                $result = SQL_QUERY_ESC("SELECT `ext_version` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
                        array($ext_name), __FUNCTION__, __LINE__);
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, ": DB - ".SQL_NUMROWS($result)."");
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $ext_name . ': DB - '.SQL_NUMROWS($result).'');
 
                // Is the extension there?
                if (SQL_NUMROWS($result) == 1) {
                        // Load entry
                        $data = SQL_FETCHARRAY($result);
                } elseif (isDebugModeEnabled()) {
-                       // Not found!
-                       logDebugMessage(__FUNCTION__, __LINE__, sprintf(": Cannot find extension %s in database!", $ext_name));
+                       // Not found, please report all
+                       debug_report_bug(sprintf(": Cannot find extension %s in database!", $ext_name));
                }
 
                // Free result
@@ -679,7 +683,7 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false
        $OUT = '';
 
        // Do we have queries?
-       if ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) {
+       if ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')) {
                // Init switch color
                $SW = 2;
 
@@ -718,7 +722,7 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false
 
                // Load main template
                $OUT = loadTemplate('admin_ext_sql_table', true, $content);
-       } elseif ((getExtensionVersion('sql_patches') >= '0.0.7') && (getConfig('verbose_sql') == 'Y')) {
+       } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')) {
                // No addional SQL commands to run
                $OUT = loadTemplate('admin_settings_saved', true, getMessage('ADMIN_NO_ADDITIONAL_SQLS'));
        } // END - if
@@ -863,7 +867,7 @@ function doDeactivateExtension($ext_name) {
 
                // Notify the admin
                sendAdminNotification(
-               getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
+                       getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
                        'admin_ext_deactivated',
                        array('ext_name' => $ext_name)
                );
@@ -946,7 +950,7 @@ function ifModuleHasMenu ($mod, $forceDb = false) {
        // All is false by default
        $ret = false;
 
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "mod={$mod},cache=".getExtensionVersion('cache'));
+       // Extension installed and newer than or has version 0.1.2?
        if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
                // Cache version is okay, so let's check the cache!
                if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) {
@@ -957,9 +961,9 @@ function ifModuleHasMenu ($mod, $forceDb = false) {
                        // Check cache and count hit
                        $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y');
                        incrementStatsEntry('cache_hits');
-               } elseif ($mod == 'admin') {
-                       // Admin module has always a menu!
-                       $ret = true;
+               } else {
+                       // Admin/guest/member/sponsor modules have always a menu!
+                       $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor'));
                }
        } elseif ((isExtensionInstalled('sql_patches')) && (getExtensionVersion('sql_patches') >= '0.3.6') && ((!isExtensionActive('cache')) || ($forceDb === true))) {
                // Check database for entry
@@ -981,12 +985,14 @@ function ifModuleHasMenu ($mod, $forceDb = false) {
                // Free memory
                SQL_FREERESULT($result);
        } elseif (!isExtensionInstalled('sql_patches')) {
-               // No sql_patches installed, so maybe in admin area or no admin registered?
-               $ret = (((isAdmin()) || (!isAdminRegistered())) && ($mod == 'admin')); // Then there is a menu!
+               // No sql_patches installed, so maybe in admin/guest/member/sponsor area or no admin registered?
+               $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); // Then there is a menu!
+       } else {
+               // Unsupported state!
+               logDebugMessage(__FUNCTION__, __LINE__, 'This should never be reached.');
        }
 
        // Return status
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().intval($ret));
        return $ret;
 }
 
@@ -1445,7 +1451,7 @@ function getCurrentExtensionVersion () {
        return $GLOBALS['ext_current_version'];
 }
 
-// Remove the extension from global cache array
+// Remove the extension from cache array
 function removeExtensionFromArray () {
        // "Cache" this name
        $ext_name = getCurrentExtensionName();
@@ -1553,7 +1559,7 @@ function isExtensionIncludeReadable ($ext_name = '') {
        } // END - if
 
        // Return result
-       //* DEBUG: */ print __FUNCTION__.': '.$ext_name.'='.intval($GLOBALS['ext_inc_readable'][$ext_name]).'<br />';
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',realable='.intval($GLOBALS['ext_inc_readable'][$ext_name]));
        return $GLOBALS['ext_inc_readable'][$ext_name];
 }