]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions-functions.php
Debug lines removed
[mailer.git] / inc / extensions-functions.php
index b3e95cdcfaa43337297cb8cd09c9be58978f0cec..022440a79d11d45a60b5bffcea6e415d7c733759 100644 (file)
@@ -41,7 +41,7 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Load the extension and maybe found language and function files.
-function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $isDryRun = false) {
+function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $isDryRun = false, $previousExtension = NULL) {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_mode=' . $ext_mode . ',ext_ver=' . $ext_ver . ',isDryRun=' . intval($isDryRun) . ' - ENTERED!');
        // Loading an extension in same mode, but not test/update, twice is not
        // good, so is the extension $ext_name already loaded in mode $ext_mode?
@@ -53,6 +53,9 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $isDryRun = fa
        // Make sure this situation can only happen once
        $GLOBALS['loaded_extension'][$ext_name][$ext_mode] = true;
 
+       // Remember previous extension here
+       $GLOBALS['previous_extension'][$ext_name] = $previousExtension;
+
        // Set extension mode
        setExtensionMode($ext_mode);
 
@@ -177,7 +180,7 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $isDryRun = fa
 }
 
 // Registers an extension and possible update dependencies
-function registerExtension ($ext_name, $taskId, $isDryRun = false, $ignoreUpdates = false) {
+function registerExtension ($ext_name, $taskId, $isDryRun = false, $ignoreUpdates = false, $previousExtension = NULL) {
        // Set current extension name
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . intval($taskId) . ',isDryRun=' . intval($isDryRun) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - ENTERED!');
        setCurrentExtensionName($ext_name);
@@ -225,7 +228,7 @@ function registerExtension ($ext_name, $taskId, $isDryRun = false, $ignoreUpdate
                        // Is it still zero?
                        if ((is_null($taskId)) || ($taskId == '0')) {
                                // Then request a bug report
-                               reportBug(__FUNCTION__, __LINE__, sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
+                               reportBug(__FUNCTION__, __LINE__, sprintf("%s: task_id is still zero after determineExtensionTaskId/createNewExtensionTask(%s)",
                                        __FUNCTION__,
                                        getCurrentExtensionName()
                                ));
@@ -247,7 +250,7 @@ function registerExtension ($ext_name, $taskId, $isDryRun = false, $ignoreUpdate
 
        // Does this extension exists?
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ' - CALLING loadExtension() ...');
-       if (loadExtension(getCurrentExtensionName(), 'register', '0.0.0', isExtensionDryRun())) {
+       if (loadExtension(getCurrentExtensionName(), 'register', '0.0.0', isExtensionDryRun(), $previousExtension)) {
                // Set current extension name again
                setCurrentExtensionName($ext_name);
 
@@ -257,7 +260,7 @@ function registerExtension ($ext_name, $taskId, $isDryRun = false, $ignoreUpdate
                foreach ($history as $ext_ver) {
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $ext_ver);
                        // Load extension in update mode
-                       loadExtension(getCurrentExtensionName(), 'update', $ext_ver, isExtensionDryRun());
+                       loadExtension(getCurrentExtensionName(), 'update', $ext_ver, isExtensionDryRun(), $previousExtension);
 
                        // Add update notes to our output
                        addExtensionNotes($ext_ver);
@@ -273,7 +276,7 @@ function registerExtension ($ext_name, $taskId, $isDryRun = false, $ignoreUpdate
 
                        // Check if extension is not installed and not already in registration procedure and if loading it wents finally fine...
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',isExtensionRegistrationRunning(' . $ext_update . ')=' . intval(isExtensionRegistrationRunning($ext_update)));
-                       if ((!isExtensionInstalled($ext_update)) && (!isExtensionRegistrationRunning($ext_update)) && (loadExtension($ext_update, 'test', '', isExtensionDryRun()))) {
+                       if ((!isExtensionInstalled($ext_update)) && (!isExtensionRegistrationRunning($ext_update)) && (loadExtension($ext_update, 'test', '', isExtensionDryRun(), $previousExtension))) {
                                // Set current extension name again
                                setCurrentExtensionName($ext_name);
 
@@ -295,7 +298,7 @@ function registerExtension ($ext_name, $taskId, $isDryRun = false, $ignoreUpdate
                                        if (($updateTaskId > 0) || (isInstallationPhase())) {
                                                // Try to register the extension
                                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',updateTaskId=' . $updateTaskId . ',isExtensionDryRun()=' . intval(isExtensionDryRun()));
-                                               $processResult = registerExtension($ext_update, $updateTaskId, isExtensionDryRun(), true);
+                                               $processResult = registerExtension($ext_update, $updateTaskId, isExtensionDryRun(), true, $ext_name);
 
                                                // Reset extension name
                                                setCurrentExtensionName($ext_name);
@@ -1557,6 +1560,16 @@ function addExtensionSql ($sql) {
                $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()] = array();
        } // END - if
 
+       // Is the SQL statement empty?
+       if (empty($sql)) {
+               /*
+                * Abort here as this may happen if getExtensionMode() is 'activate' or
+                * 'deactivate'. This means that for 'mode' are no SQL statements
+                * specified.
+                */
+               return;
+       } // END - if
+
        // Add it
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql);
        array_push($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()], $sql);
@@ -1646,9 +1659,9 @@ function FILTER_INIT_EXTENSIONS () {
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - START!');
                foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
                        // Load it
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - START');
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - START');
                        loadExtension($ext_name, 'init', getExtensionVersion($ext_name));
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name='.$ext_name.' - END');
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - END');
                } // END - foreach
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHE - END!');
        } // END - if
@@ -1853,6 +1866,19 @@ function addDropTableSql ($tableName) {
        } // END - if
 }
 
+// Adds a RENAME TABLE stament if 'from' table exist and 'to' table not
+function addRenameTableSql ($fromTable, $toTable) {
+       // Is renaming required?
+       if ((ifSqlTableExists($fromTable)) && (!ifSqlTableExists($toTable))) {
+               // Add it
+               addExtensionSql('RENAME TABLE `{?_MYSQL_PREFIX?}_' . $fromTable . '` TO `{?_MYSQL_PREFIX?}_' . $toTable . '`');
+
+               // Mark both tables
+               $GLOBALS['ifSqlTableExists'][$fromTable] = false;
+               $GLOBALS['ifSqlTableExists'][$toTable]   = true;
+       } // END - if
+}
+
 // Adds an admin menu to the SQL queue of the menu entry is not found
 function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
        // Now check if this menu is there