X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fextensions-functions.php;h=af6f615564a4c64766b55fc337f9023e12d8386b;hb=9bc2a494fae1a98f0873a6f3bd8c878b09124b9f;hp=4bc33da72f09b7a5f1f0310880290accba053f4f;hpb=fc162164725588cf75969f707faead9c9cd8e68b;p=mailer.git diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php index 4bc33da72f..af6f615564 100644 --- a/inc/extensions-functions.php +++ b/inc/extensions-functions.php @@ -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,7 +382,7 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru // In normal mode return a true on success $ret = true; - } elseif (getExtensionDryRun() === true) { + } elseif (isExtensionDryRun() === true) { // In "dry-run" mode do always return a true $ret = true; @@ -391,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 @@ -638,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(); @@ -648,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); @@ -658,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(); @@ -678,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 @@ -698,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()]); @@ -710,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 @@ -732,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 @@ -746,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 @@ -910,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) ); @@ -938,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 %s 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, '{--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 @@ -1550,7 +1570,7 @@ function enableExtensionDryRun ($dry_run = true) { } // Getter for dry-run -function getExtensionDryRun () { +function isExtensionDryRun () { return $GLOBALS['ext_dry_run']; }