]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions-functions.php
Rewrites/fixes for surfbar
[mailer.git] / inc / extensions-functions.php
index a05bb7b4e183df819de0ec99728d57f49553992a..af6f615564a4c64766b55fc337f9023e12d8386b 100644 (file)
@@ -166,9 +166,9 @@ function loadExtension ($ext_name, $ext_mode = 'init', $ext_ver = '', $dry_run =
 }
 
 // Registeres an extension and possible update depencies
-function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = true) {
+function registerExtension ($ext_name, $taskId, $dry_run = false, $logout = true) {
        // Set current extension name
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . $task_id . ',dry_run=' . intval($dry_run) . ',logout=' . intval($logout) . ' - ENTERED!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . $taskId . ',dry_run=' . intval($dry_run) . ',logout=' . intval($logout) . ' - ENTERED!');
        setCurrentExtensionName($ext_name);
 
        // Enable dry-run
@@ -200,17 +200,23 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
        } // END - if
 
        // Is the task id zero? Then we need to auto-fix it here
-       if ($task_id == '0') {
+       if ($taskId == '0') {
                // Try to find the task
-               $task_id = determineExtensionTaskId(getCurrentExtensionName());
+               $taskId = determineExtensionTaskId(getCurrentExtensionName());
 
                // Still zero and not in dry-run?
-               if (($task_id == '0') && (!getExtensionDryRun())) {
-                       // Then request a bug report
-                       debug_report_bug(__FUNCTION__, __LINE__, sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
-                               __FUNCTION__,
-                               getCurrentExtensionName()
-                       ));
+               if (($taskId == '0') && (!isExtensionDryRun())) {
+                       // Now try to create a new task
+                       $taskId = createNewExtensionTask(getCurrentExtensionName());
+
+                       // Is it still zero?
+                       if ($taskId == '0') {
+                               // Then request a bug report
+                               debug_report_bug(__FUNCTION__, __LINE__, sprintf("%s: task_id is still zero after determineExtensionTaskId(%s)",
+                                       __FUNCTION__,
+                                       getCurrentExtensionName()
+                               ));
+                       } // END - if
                } // END - if
        } // END - if
 
@@ -228,7 +234,7 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
 
        // Does this extension exists?
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
-       if (loadExtension(getCurrentExtensionName(), 'register', '', getExtensionDryRun())) {
+       if (loadExtension(getCurrentExtensionName(), 'register', '', isExtensionDryRun())) {
                // Set current extension name again
                setCurrentExtensionName($ext_name);
 
@@ -238,7 +244,7 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
                foreach ($history as $ver) {
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ', ext_ver=' . $ver);
                        // Load extension in update mode
-                       loadExtension(getCurrentExtensionName(), 'update', $ver, getExtensionDryRun());
+                       loadExtension(getCurrentExtensionName(), 'update', $ver, isExtensionDryRun());
 
                        // Add update notes to our output
                        addExtensionNotes($ver);
@@ -254,7 +260,7 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
 
                        // 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', '', getExtensionDryRun()))) {
+                       if ((!isExtensionInstalled($ext_update)) && (!isExtensionRegistrationRunning($ext_update)) && (loadExtension($ext_update, 'test', '', isExtensionDryRun()))) {
                                // Set current extension name again
                                setCurrentExtensionName($ext_name);
 
@@ -274,7 +280,7 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
                                        if ($task > 0) {
                                                // Try to register the extension
                                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ':ext_update=' . $ext_update . ',taskId=' . $task);
-                                               $test = registerExtension($ext_update, $task, getExtensionDryRun(), false);
+                                               $test = registerExtension($ext_update, $task, isExtensionDryRun(), false);
 
                                                // Reset extension name
                                                setCurrentExtensionName($ext_name);
@@ -286,7 +292,7 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
                                        //* 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());
+                                       updateExtension($ext_update, $ext_ver, isExtensionDryRun());
                                        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]);
@@ -328,14 +334,14 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
                // Does everthing before wents ok?
                if ($test === true) {
                        // "Dry-run-mode" activated?
-                       if ((getExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
+                       if ((isExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName());
                                // Init SQLs and transfer ext->generic
                                initSqls();
                                setSqlsArray(getExtensionSqls());
 
                                // Run installation pre-installation filters
-                               runFilterChain('pre_extension_installed', array('dry_run' => getExtensionDryRun()));
+                               runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun()));
 
                                // Register extension
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'insert=' . getCurrentExtensionName() . '/' . getCurrentExtensionVersion() . ' - INSERT!');
@@ -364,7 +370,7 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
                                runFilterChain('post_extension_installed', array(
                                        'pool'     => 'extension',
                                        'ext_name' => getCurrentExtensionName(),
-                                       'task_id'  => $task_id
+                                       'task_id'  => $taskId
                                ));
 
                                // Re-init queries and notes
@@ -376,12 +382,11 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
 
                                // In normal mode return a true on success
                                $ret = true;
-                       } elseif (getExtensionDryRun() === true) {
-                               // In  "dry-run" mode return array with all SQL commands
-                               $ret = getExtensionSqls();
+                       } elseif (isExtensionDryRun() === true) {
+                               // In  "dry-run" mode do always return a true
+                               $ret = true;
 
                                // Re-init queries and notes
-                               initExtensionSqls(true);
                                initExtensionNotes();
                        } else {
                                // Extension has been removed for updates, so all is fine!
@@ -392,16 +397,16 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName());
                        $ret = false;
                }
-       } elseif (($task_id > 0) && (getCurrentExtensionName() != '')) {
+       } elseif (($taskId > 0) && (getCurrentExtensionName() != '')) {
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
                // Remove task from system when id and extension's name is valid
                SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
-                       array(bigintval($task_id)), __FUNCTION__, __LINE__);
+                       array(bigintval($taskId)), __FUNCTION__, __LINE__);
        }
 
        // Is this the sql_patches?
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . '/' . getExtensionMode());
-       if ((getCurrentExtensionName() == 'sql_patches') && ((getExtensionMode() == 'register') || (getExtensionMode() == 'remove')) && (!getExtensionDryRun()) && ($test)) {
+       if ((getCurrentExtensionName() == 'sql_patches') && ((getExtensionMode() == 'register') || (getExtensionMode() == 'remove')) && (!isExtensionDryRun()) && ($test)) {
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ': LOAD!');
                if ($logout === true) {
                        // Then redirect to logout
@@ -639,7 +644,7 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
        initIncludePool('extension');
 
        // Load extension in test mode
-       loadExtension($ext_name, 'test', $ext_ver, getExtensionDryRun());
+       loadExtension($ext_name, 'test', $ext_ver, isExtensionDryRun());
 
        // Save version history
        $history = getExtensionVersionHistory();
@@ -649,7 +654,7 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
 
        // Check if version is updated
        //* DEBUG: */ debugOutput(getCurrentExtensionName().'/'.$ext_name.':'.getThisExtensionVersion().'/'.$ext_ver.'/'.intval(is_array($history)));
-       if (((getThisExtensionVersion() != $ext_ver) || (getExtensionDryRun())) && (is_array($history))) {
+       if (((getThisExtensionVersion() != $ext_ver) || (isExtensionDryRun())) && (is_array($history))) {
                // Search for starting point
                $start = array_search($ext_ver, $history);
 
@@ -659,7 +664,7 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
                        $GLOBALS['update_ver'][getCurrentExtensionName()] = $history[$idx];
 
                        // Load again...
-                       loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], getExtensionDryRun());
+                       loadExtension(getCurrentExtensionName(), 'update', $GLOBALS['update_ver'][getCurrentExtensionName()], isExtensionDryRun());
 
                        // Get all depencies
                        $depencies = getExtensionUpdateDependencies();
@@ -679,10 +684,10 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
                                                // Is the extension there?
                                                if (isExtensionInstalled($ext_depend)) {
                                                        // Update another extension first!
-                                                       $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), getExtensionDryRun());
+                                                       $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), isExtensionDryRun());
                                                } else {
                                                        // Register new extension
-                                                       $test = registerExtension($ext_depend, 0, getExtensionDryRun(), false);
+                                                       $test = registerExtension($ext_depend, 0, isExtensionDryRun(), false);
                                                }
                                        } // END - if
                                } // END - foreach
@@ -699,7 +704,7 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
                } // END - for
 
                // In real-mode execute any existing includes
-               if (getExtensionDryRun() === false) {
+               if (isExtensionDryRun() === false) {
                        $GLOBALS['ext_inc_pool'][getCurrentExtensionName()] = getIncludePool('extension');
                        runFilterChain('load_includes', 'extension');
                        setIncludePool('extension', $GLOBALS['ext_inc_pool'][getCurrentExtensionName()]);
@@ -711,9 +716,9 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
                setSqlsArray(getExtensionSqls());
 
                // Run SQLs
-               runFilterChain('run_sqls', array('dry_run' => getExtensionDryRun()));
+               runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun()));
 
-               if (getExtensionDryRun() === false) {
+               if (isExtensionDryRun() === false) {
                        // Run filters on success extension update
                        runFilterChain('extension_update', getCurrentExtensionName());
                } // END - if
@@ -725,7 +730,7 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false
        // Empty title?
        if (empty($title)) {
                // Then fix it to default
-               $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REMOVAL');
+               $title = '{--ADMIN_SQLS_EXECUTED_ON_REMOVAL--}';
        } // END - if
 
        // Init variables
@@ -733,9 +738,6 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false
 
        // Do we have queries?
        if ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y')) {
-               // Init switch color
-               $SW = 2;
-
                // Get all SQLs
                foreach (getExtensionSqls() as $sqls) {
                        // New array format is recursive
@@ -747,16 +749,12 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false
                                if (!empty($sql)) {
                                        // Prepare output for template
                                        $content = array(
-                                               'sw'  => $SW,
                                                'i'   => ($idx+1),
                                                'sql' => $sql
                                        );
 
                                        // Load row template
                                        $OUT .= loadTemplate('admin_ext_sql_row', true, $content);
-
-                                       // Switch color
-                                       $SW = 3 - $SW;
                                } // END - if
                        } // END - foreach
                } // END - foreach
@@ -773,7 +771,7 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false
                $OUT = loadTemplate('admin_ext_sql_table', true, $content);
        } 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'));
+               $OUT = loadTemplate('admin_settings_saved', true, '{--ADMIN_NO_ADDITIONAL_SQLS--}');
        } // END - if
 
        // Return output
@@ -911,12 +909,12 @@ function doDeactivateExtension($ext_name) {
                // Then run all queries
                doExtensionSqls(getExtensionId($ext_name), 'deactivate');
 
-               // Create new task
+               // Create new task (we ignore the task id here)
                createExtensionDeactivationTask($ext_name);
 
                // Notify the admin
                sendAdminNotification(
-                       getMessage('ADMIN_SUBJECT_EXTENSION_DEACTIVATED'),
+                       '{--ADMIN_EXTENSION_DEACTIVATED_SUBJECT--}',
                        'admin_ext_deactivated',
                        array('ext_name' => $ext_name)
                );
@@ -939,59 +937,80 @@ function isExtensionOlder ($ext_name, $ext_ver) {
 // Creates a new task for updated extension
 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
        // Create subject line
-       $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXTENSION_SUBJ--}';
+       $subject = '[UPDATE-' . $ext_name . '-' . $ext_ver . ':] {--ADMIN_UPDATE_EXTENSION_SUBJECT--}';
+
+       // Get task id
+       $taskId = determineTaskIdBySubject($subject);
 
        // Is the extension there?
        if (isExtensionInstalled($ext_name)) {
                // Check if task is not there
-               if (determineTaskIdBySubject($subject) == '0') {
+               if ($taskId == '0') {
                        // Create extension update-task
-                       createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
+                       $taskId = createNewTask($subject, $notes, 'EXTENSION_UPDATE', 0, $adminId);
                } // END - if
        } else {
                // Extension not there! :-(
                debug_report_bug(__FUNCTION__, __LINE__, sprintf("Extension <span class=\"data\">%s</span> not found but should be updated?", $ext_name));
        }
+
+       // Return task id
+       return $taskId;
 }
 
 // Creates a new task for newly installed extension
-function createNewExtensionTask ($adminId, $subject, $ext) {
+function createNewExtensionTask ($ext_name) {
+       // Generate subject line
+       $subject = sprintf("[%s:]", $ext_name);
+
+       // Get task id
+       $taskId = determineTaskIdBySubject($subject);
+
        // Not installed and do we have created a task for the admin?
-       if ((determineTaskIdBySubject($subject) == '0') && (!isExtensionInstalled($ext))) {
+       if (($taskId == '0') && (!isExtensionInstalled($ext_name))) {
                // Set default message if ext-foo is missing
-               $message = getMaskedMessage('ADMIN_EXTENSION_TEXT_FILE_MISSING', $ext);
+               $message = getMaskedMessage('ADMIN_EXTENSION_TEXT_FILE_MISSING', $ext_name);
 
                // Template file
                $tpl = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
                        getConfig('PATH'),
                        getLanguage(),
-                       $ext
+                       $ext_name
                );
 
                // Load text for task if found
                if (isFileReadable($tpl)) {
                        // Load extension's own text template (HTML!)
-                       $message = loadTemplate('ext_' . $ext, true);
+                       $message = loadTemplate('ext_' . $ext_name, true);
                } else {
                        // Write this in debug.log as well
                        logDebugMessage(__FUNCTION__, __LINE__, $message);
                }
 
                // Task not created so it's a brand-new extension which we need to register and create a task for!
-               createNewTask($subject, $message, 'EXTENSION', 0, $adminId, false);
+               $taskId = createNewTask($subject, $message, 'EXTENSION', 0, getCurrentAdminId(), false);
        } // END - if
+
+       // Return task id
+       return $taskId;
 }
 
 // Creates a task for automatically deactivated (deprecated) extension
-function createExtensionDeactivationTask ($ext) {
+function createExtensionDeactivationTask ($ext_name) {
        // Create subject line
-       $subject = sprintf("[%s:] %s", $ext, getMessage('TASK_SUBJ_EXTENSION_DEACTIVATED'));
+       $subject = sprintf("[%s:] %s", $ext_name, '{--ADMIN_TASK_EXTENSION_DEACTIVATED_SUBJECT--}');
+
+       // Get task id
+       $taskId = determineTaskIdBySubject($subject);
 
        // Not installed and do we have created a task for the admin?
-       if ((determineTaskIdBySubject($subject) == '0') && (isExtensionInstalled($ext))) {
+       if (($taskId == '0') && (isExtensionInstalled($ext_name))) {
                // Task not created so add it
-               createNewTask($subject, SQL_ESCAPE(loadTemplate('task_EXTENSION_deactivated', true, $ext)), 'EXTENSION_DEACTIVATION');
+               $taskId = createNewTask($subject, SQL_ESCAPE(loadTemplate('task_EXTENSION_deactivated', true, $ext_name)), 'EXTENSION_DEACTIVATION');
        } // END - if
+
+       // Return task id
+       return $taskId;
 }
 
 // Checks if the module has a menu
@@ -1110,13 +1129,13 @@ function addExtensionNotes ($ver) {
                        // Initial release
                        $content = array(
                                'ver'   => $ver,
-                               'notes' => getMessage('INITIAL_RELEASE')
+                               'notes' => '{--INITIAL_RELEASE--}'
                        );
                } else {
                        // No update notes found!
                        $content = array(
                                'ver'   => $ver,
-                               'notes' => getMessage('NO_UPDATE_NOTES')
+                               'notes' => '{--NO_UPDATE_NOTES--}'
                        );
                }
 
@@ -1551,7 +1570,7 @@ function enableExtensionDryRun ($dry_run = true) {
 }
 
 // Getter for dry-run
-function getExtensionDryRun () {
+function isExtensionDryRun () {
        return $GLOBALS['ext_dry_run'];
 }