X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fextensions-functions.php;h=ca7717c09105e0c5cf1fdd59bc823fff5a352e07;hb=c15eee48f9da1469cf3cdca3a48ba2d3c382a7c9;hp=714483dac359db6fb19c53ca17a067dd807d5c48;hpb=b622c2d9285f044f49328cbd98efbf2f1a24aa8e;p=mailer.git diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php index 714483dac3..ca7717c091 100644 --- a/inc/extensions-functions.php +++ b/inc/extensions-functions.php @@ -41,8 +41,8 @@ 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', $dry_run = false) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_mode=' . $ext_mode . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ' - ENTERED!'); +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? if ((isset($GLOBALS['loaded_extension'][$ext_name][$ext_mode])) && (!in_array($ext_mode, array('update', 'test')))) { @@ -53,6 +53,9 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = fal // 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); @@ -78,12 +81,12 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = fal // In all but test-mode we need these messages to debug! Please report all (together, e.g.) if (($ext_mode != 'test') && (getCurrentExtensionVersion() == '0.0.0')) { // Abort here, this must now always be set! - reportBug(__FUNCTION__, __LINE__, 'Extension version is empty, setting to 0.0. ext_name=' . $ext_name . ', ext_mode=' . $ext_mode . ', dry_run=' . intval($dry_run)); + reportBug(__FUNCTION__, __LINE__, 'Extension version is empty, setting to 0.0.0 ext_name=' . $ext_name . ', ext_mode=' . $ext_mode . ', isDryRun=' . intval($isDryRun)); } // END - if } // Set dry-run - enableExtensionDryRun($dry_run); + enableExtensionDryRun($isDryRun); // Init array initIncludePool('extension'); @@ -122,7 +125,7 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = fal loadLanguageFile($ext_name); } // END - if - // Do we have cache? + // Is there cache? if (isExtensionFunctionFileReadable($ext_name)) { // Not yet loaded? if ((($GLOBALS['cache_array']['extension']['ext_func'][$ext_name] == 'Y') || (!isset($GLOBALS['cache_array']['extension']['ext_func'][$ext_name]))) && (!isExtensionLibraryLoaded($ext_name))) { @@ -177,13 +180,13 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = fal } // Registers an extension and possible update dependencies -function registerExtension ($ext_name, $taskId, $dry_run = 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 . ',task_id=' . intval($taskId) . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - ENTERED!'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . intval($taskId) . ',isDryRun=' . intval($isDryRun) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - ENTERED!'); setCurrentExtensionName($ext_name); // Enable dry-run - enableExtensionDryRun($dry_run); + enableExtensionDryRun($isDryRun); // By default all extensions are in productive phase enableExtensionProductive(); @@ -198,8 +201,8 @@ function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates // When this extension is already in registration/update phase, all is fine if ((isExtensionRegistrationRunning($ext_name)) || ((isExtensionUpdateRunning($ext_name)) && ($ignoreUpdates === false))) { // Then abort here with 'true' becaus it is fine - //* 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)); - //* BUG: */ reportBug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . $taskId . ',dry_run=' . intval($dry_run) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - Please investigate!'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in registration/update phase, all fine,taskId=' . $taskId . ',isDryRun=' . intval($isDryRun) . ',ignoreUpdates=' . intval($ignoreUpdates)); + //* BUG: */ reportBug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . $taskId . ',isDryRun=' . intval($isDryRun) . ',ignoreUpdates=' . intval($ignoreUpdates) . ' - Please investigate!'); return true; } // END - if @@ -213,19 +216,19 @@ function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates } // END - if // Is the task id zero? Then we need to auto-fix it here - if (($taskId == '0') && (!isInstallationPhase())) { + if (((is_null($taskId)) || ($taskId == '0')) && (!isInstallationPhase())) { // Try to find the task $taskId = determineExtensionTaskId(getCurrentExtensionName()); // Still zero and not in dry-run? - if (($taskId == '0') && (!isExtensionDryRun())) { + if (((is_null($taskId)) || ($taskId == '0')) && (!isExtensionDryRun())) { // Now try to create a new task $taskId = createNewExtensionTask(getCurrentExtensionName()); // Is it still zero? - if ($taskId == '0') { + 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, $dry_run = false, $ignoreUpdates // 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, $dry_run = false, $ignoreUpdates 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, $dry_run = false, $ignoreUpdates // 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); @@ -288,14 +291,14 @@ function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_ver[' . gettype($ext_ver) . ']=' . $ext_ver . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ',currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ' - EMPTY?'); if (empty($ext_ver)) { // Extension not registered so far so first load task's id... - $taskId = determineExtensionTaskId($ext_update); + $updateTaskId = determineExtensionTaskId($ext_update); // Entry found? - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'taskId=' . $taskId . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ',currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ' - CHECKING!'); - if (($taskId > 0) || (isInstallationPhase())) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'updateTaskId=' . $updateTaskId . ',isInstallationPhase()=' . intval(isInstallationPhase()) . ',currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ' - CHECKING!'); + if (($updateTaskId > 0) || (isInstallationPhase())) { // Try to register the extension - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',taskId=' . $taskId . ',isExtensionDryRun()=' . isExtensionDryRun()); - $processResult = registerExtension($ext_update, $taskId, isExtensionDryRun(), true); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',updateTaskId=' . $updateTaskId . ',isExtensionDryRun()=' . intval(isExtensionDryRun())); + $processResult = registerExtension($ext_update, $updateTaskId, isExtensionDryRun(), true, $ext_name); // Reset extension name setCurrentExtensionName($ext_name); @@ -332,6 +335,7 @@ function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates // Is there no update? if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) { // Then test is passed! + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=true,countExtensionUpdateDependencies()=0 - Test passed!'); $processResult = true; } // END - if @@ -360,7 +364,7 @@ function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) { // New way, with CSS //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion() . 'ext_css=' . getExtensionHasCss()); - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`,`ext_has_css`) VALUES ('%s','%s','%s','%s')", + SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`, `ext_has_css`) VALUES ('%s','%s','%s','%s')", array( getCurrentExtensionName(), getThisExtensionAlwaysActive(), @@ -370,7 +374,7 @@ function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates } else { // Old way, no CSS //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion()); - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`,`ext_active`,`ext_version`) VALUES ('%s','%s','%s')", + SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`) VALUES ('%s','%s','%s')", array( getCurrentExtensionName(), getThisExtensionAlwaysActive(), @@ -418,7 +422,7 @@ function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates } // @TODO This redirect is still needed to register sql_patches! Please try to avoid it - if (($ret === true) && ($dry_run === false) && ($ext_name == 'sql_patches') && (!isInstallationPhase())) { + if (($ret === true) && ($isDryRun === false) && ($ext_name == 'sql_patches') && (!isInstallationPhase())) { /* * This is a really dirty hack to prevent an error about a missing * configuration entry which should be there after registration of @@ -428,7 +432,7 @@ function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates } // END - if // Return status code - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',currName=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',processResult=' . intval($processResult) . ',ret=' . intval($ret) . ' - EXIT!'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult) . ',ret=' . intval($ret) . ' - EXIT!'); return $ret; } @@ -470,7 +474,7 @@ function doExtensionSqls ($ext_id, $load_mode) { // Debug message //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SQLs::count=' . countSqls()); - // Do we have entries? + // Are there entries? if (isSqlsValid()) { // Run SQL commands... runFilterChain('run_sqls'); @@ -525,7 +529,7 @@ function isExtensionInstalled ($ext_name) { // Look in database $ext_id = getExtensionId($ext_name); - // Do we have a record? + // Is there a record? $isInstalled = ($ext_id > 0); // Log debug message @@ -667,9 +671,9 @@ function getExtensionVersion ($ext_name, $force = false) { } // Updates a given extension with current extension version to latest version -function updateExtension ($ext_name, $ext_ver, $dry_run = false, $ignoreDependencies = false) { +function updateExtension ($ext_name, $ext_ver, $isDryRun = false, $ignoreDependencies = false) { // Only admins are allowed to update extensions - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',isDryRun=' . intval($isDryRun) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - ENTERED!'); if ((!isAdmin()) || (empty($ext_name))) { // Called as non-admin or empty extension reportBug(__FUNCTION__, __LINE__, 'Called as non-admin (isAdmin()=' . intval(isAdmin()) . '), or empty extension name. ext_name=' . $ext_name); @@ -679,7 +683,7 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false, $ignoreDependen setCurrentExtensionName($ext_name); // Is this extension update already running? - if ((isExtensionUpdateRunning($ext_name, $ignoreDependencies)) && ($dry_run === false)) { + if ((isExtensionUpdateRunning($ext_name, $ignoreDependencies)) && ($isDryRun === false)) { // This is fine but needs logging ATM //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, all fine.'); //* BUG: */ reportBug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, please investigate!'); @@ -738,7 +742,7 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false, $ignoreDependen $processResult = updateExtension($ext_depend, getExtensionVersion($ext_depend), isExtensionDryRun(), true); } else { // Register new extension - $processResult = registerExtension($ext_depend, 0, isExtensionDryRun()); + $processResult = registerExtension($ext_depend, NULL, isExtensionDryRun()); } } // END - if } // END - foreach @@ -775,7 +779,7 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false, $ignoreDependen } // END - if } // END - if - //* DEBUG: */logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',dry_run=' . intval($dry_run) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - EXIT!'); + //* DEBUG: */logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',ext_ver=' . $ext_ver . ',isDryRun=' . intval($isDryRun) . ',ignoreDependencies=' . intval($ignoreDependencies) . ' - EXIT!'); } // Output verbose SQL table for extension @@ -789,9 +793,9 @@ function addExtensionVerboseSqlTable ($title = '{--ADMIN_SQLS_EXECUTED_ON_REMOVA // Init variables $OUT = ''; - // Do we have queries? + // Is there queries? if (isVerboseSqlEnabled()) { - // Do we have entries? + // Are there entries? if (countExtensionSqls() > 0) { // Init counter $idx = 0; @@ -879,7 +883,7 @@ function getExtensionId ($ext_name) { // Init id number $data['ext_id'] = '0'; - // Do we have cache? + // Is there cache? if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) { // Load from cache $data['ext_id'] = $GLOBALS['cache_array']['extension']['ext_id'][$ext_name]; @@ -910,7 +914,7 @@ function getExtensionId ($ext_name) { // Determines whether the given extension name is valid function isExtensionNameValid ($ext_name) { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS['ext_name_valid'][$ext_name])) { // Generate include file name $INC = sprintf("inc/extensions/ext-%s.php", $ext_name); @@ -1038,7 +1042,8 @@ function createNewExtensionTask ($ext_name) { $taskId = determineTaskIdBySubject($subject); // Not installed and do we have created a task for the admin? - if (($taskId == '0') && (!isExtensionInstalled($ext_name))) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId[' . gettype($taskId) . ']=' . $taskId); + if (((is_null($taskId)) || ($taskId == '0')) && (!isExtensionInstalled($ext_name))) { // Set default message if ext-foo is missing $message = '{%message,ADMIN_EXTENSION_TEXT_FILE_MISSING=' . $ext_name . '%}'; @@ -1075,7 +1080,8 @@ function createExtensionDeactivationTask ($ext_name) { $taskId = determineTaskIdBySubject($subject); // Not installed and do we have created a task for the admin? - if (($taskId == '0') && (isExtensionInstalled($ext_name))) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId[' . gettype($taskId) . ']=' . $taskId); + if (((is_null($taskId)) || ($taskId == '0')) && (isExtensionInstalled($ext_name))) { // Task not created so add it $taskId = createNewTask($subject, SQL_ESCAPE(loadTemplate('task_EXTENSION_deactivated', true, $ext_name)), 'EXTENSION_DEACTIVATION'); } // END - if @@ -1086,8 +1092,14 @@ function createExtensionDeactivationTask ($ext_name) { // Determines the task id for given extension function determineExtensionTaskId ($ext_name) { + // Is it installation phase and table task_system is not found? + if ((isInstallationPhase()) && (!ifSqlTableExists('task_system'))) { + // Then return NULL (not found) + return NULL; + } // END - if + // Default is not found - $data['task_id'] = '0'; + $data['task_id'] = NULL; // Search for extension task's id $result = SQL_QUERY_ESC("SELECT `id` AS task_id FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `task_type`='EXTENSION' AND `subject`='[%s:]' LIMIT 1", @@ -1270,7 +1282,7 @@ function addExtensionDependency ($updateDepends) { * Double-adding happens when the extension and an update of the same * extension requires the same other extension again. */ - logDebugMessage(__FUNCTION__, __LINE__, 'updateDepends=' . $updateDepends . ',extensionMode=' . getExtensionMode() . ',currentExtension=' . getCurrentExtensionName() . ' - called twice.'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'updateDepends=' . $updateDepends . ',extensionMode=' . getExtensionMode() . ',currentExtension=' . getCurrentExtensionName() . ' - called twice.'); return; } // END - if @@ -1550,6 +1562,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); @@ -1633,15 +1655,15 @@ function FILTER_INIT_EXTENSIONS () { // Init notification pool initIncludePool('notify'); - // Do we have some entries? + // Are there some entries? if (isset($GLOBALS['cache_array']['extension']['ext_name'])) { // Load all found extensions if found //* 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 @@ -1663,14 +1685,14 @@ function getExtensionMode () { } // Setter for dry-run -function enableExtensionDryRun ($dry_run = true) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()='.getCurrentExtensionName().',dry_run='.intval($dry_run)); - $GLOBALS['ext_dry_run'] = (bool) $dry_run; +function enableExtensionDryRun ($isDryRun = true) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getCurrentExtensionName()='.getCurrentExtensionName().',isDryRun='.intval($isDryRun)); + $GLOBALS['ext_isDryRun'] = (bool) $isDryRun; } // Getter for dry-run function isExtensionDryRun () { - return $GLOBALS['ext_dry_run']; + return $GLOBALS['ext_isDryRun']; } // Setter for current extension version @@ -1724,7 +1746,7 @@ function removeExtensionFromArray () { // "Getter" for 'extension has a CSS file' (with same name, of course) function getExtensionHasCss () { - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()])) { // Construct FQFN for check $FQFN = sprintf("%stheme/%s/css/%s.css", @@ -1743,7 +1765,7 @@ function getExtensionHasCss () { // Checks whether the given extension has a language file function ifExtensionHasLanguageFile ($ext_name) { - // Do we have cache? + // Is there cache? if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) { // Count cache hits incrementStatsEntry('cache_hits'); @@ -1846,6 +1868,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 @@ -1853,7 +1888,7 @@ function addAdminMenuSql ($action, $what, $title, $descr, $sort) { // Is what null? if (is_null($what)) { // Add main menu - $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)", + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`, `what`, `title`, `descr`, `sort`) VALUES ('%s',NULL,'%s','%s',%s)", $action, $title, $descr, @@ -1861,7 +1896,7 @@ function addAdminMenuSql ($action, $what, $title, $descr, $sort) { ); } else { // Add sub menu - $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s',%s)", + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu` (`action`, `what`, `title`, `descr`, `sort`) VALUES ('%s','%s','%s','%s',%s)", $action, $what, $title, @@ -1885,14 +1920,14 @@ function addGuestMenuSql ($action, $what, $title, $sort) { // Is what null? if (is_null($what)) { // Add main menu - $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)", + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`, `what`, `title`, `visible`, `locked`, `sort`) VALUES ('%s',NULL,'%s','N','Y',%s)", $action, $title, bigintval($sort) ); } else { // Add sub menu - $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)", + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`, `what`, `title`, `visible`, `locked`, `sort`) VALUES ('%s','%s','%s','N','Y',%s)", $action, $what, $title, @@ -1915,14 +1950,14 @@ function addMemberMenuSql ($action, $what, $title, $sort) { // Is what null? if (is_null($what)) { // Add main menu - $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s',NULL,'%s','N','Y',%s)", + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`, `what`, `title`, `visible`, `locked`, `sort`) VALUES ('%s',NULL,'%s','N','Y',%s)", $action, $title, bigintval($sort) ); } else { // Add sub menu - $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES ('%s','%s','%s','N','Y',%s)", + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`, `what`, `title`, `visible`, `locked`, `sort`) VALUES ('%s','%s','%s','N','Y',%s)", $action, $what, $title, @@ -1945,7 +1980,7 @@ function addSponsorMenuSql ($action, $what, $title, $active, $sort) { // Is what null? if (is_null($what)) { // Add main menu - $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s',NULL,'%s','%s',%s)", + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`, `what`, `title`, `active`, `sort`) VALUES ('%s',NULL,'%s','%s',%s)", $action, $title, $active, @@ -1953,7 +1988,7 @@ function addSponsorMenuSql ($action, $what, $title, $active, $sort) { ); } else { // Add sub menu - $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`,`what`,`title`,`active`,`sort`) VALUES ('%s','%s','%s','%s',%s)", + $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_sponsor_menu` (`action`, `what`, `title`, `active`, `sort`) VALUES ('%s','%s','%s','%s',%s)", $action, $what, $title, @@ -1973,7 +2008,7 @@ function addSponsorMenuSql ($action, $what, $title, $active, $sort) { // Add configuration entry if not found for actual extension function addConfigAddSql ($columnName, $columnSql) { // Is the column there? - if (!isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) { + if (!ifSqlColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) { // Not found, so add it addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `' . $columnName . '` ' . $columnSql); } elseif (isDebugModeEnabled()) { @@ -1985,7 +2020,7 @@ function addConfigAddSql ($columnName, $columnSql) { // Drop configuration entry if found for actual extension function addConfigDropSql ($columnName) { // Is the column there? - if (isSqlTableColumnFound('{?_MYSQL_PREFIX?}_config', $columnName)) { + if (ifSqlColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) { // Found, so add it addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` DROP `' . $columnName . '`'); } elseif (isDebugModeEnabled()) { @@ -2000,6 +2035,62 @@ function addConfigChangeSql ($oldColumnName, $newColumnName, $columnSql) { addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` CHANGE `' . $oldColumnName . '` `' . $newColumnName . '` ' . $columnSql); } +/** + * Checks if given subject is found and if not, adds an SQL query to the + * extension registration queue. + */ +function registerExtensionPointsData ($subject, $columnName, $lockedMode, $paymentMethod) { + // Default is old extension version + $add = ''; + + // Is the extension equal or newer 0.8.9? + if (((isInstallationPhase()) && ((getExtensionMode() == 'register') || (getExtensionMode() == 'update'))) || (isExtensionInstalledAndNewer('sql_patches', '0.8.9'))) { + // Then add provider + $add = " AND `account_provider`='EXTENSION'"; + } // END - if + + // Is the 'subject' there? + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ifSqlTableExists(points_data)=' . ifSqlTableExists('points_data') . ',getExtensionMode()=' . getExtensionMode() . ',add=' . $add); + if (((!ifSqlTableExists('points_data')) && ((getExtensionMode() == 'register') || (getExtensionMode() == 'update'))) || (countSumTotalData($subject, 'points_data', 'id', 'subject', true, $add) == 0)) { + // Not found so: + if ((isset($GLOBALS['previous_extension'][getCurrentExtensionName()])) && (!ifSqlTableExists('points_data'))) { + $dummy = $GLOBALS['previous_extension'][getCurrentExtensionName()]; + reportBug(__FUNCTION__, __LINE__, 'previous_extension[' . gettype($dummy) . ']=' . $dummy . ',getCurrentExtensionName()=' . getCurrentExtensionName() . ' - Under development, please report this!'); + } // END - if + + // ... add an SQL query + addExtensionSql(sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_points_data` (`subject`, `column_name`, `locked_mode`, `payment_method`) VALUES ('%s','%s','%s','%s')", + $subject, + $columnName, + $lockedMode, + $paymentMethod + )); + } // END - if +} + +/** + * Checks if given subject is found and if so, adds an SQL query to the + * extension unregistration queue. + */ +function unregisterExtensionPointsData ($subject) { + // Default is old extension version + $add = ''; + + // Is the extension equal or newer 0.8.9? + if (isExtensionInstalledAndNewer('sql_patches', '0.8.9')) { + // Then add provider + $add = " AND `account_provider`='EXTENSION'"; + } // END - if + + // Is the 'subject' there? + if (countSumTotalData($subject, 'points_data', 'id', 'subject', true, $add) == 1) { + // Found one or more, so add an SQL query + addExtensionSql(sprintf("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_points_data` WHERE `subject`='%s'" . $add . " LIMIT 1", + $subject + )); + } // END - if +} + // Enables/disables productive mode for current extension (used only while // registration). // @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable' @@ -2021,7 +2112,7 @@ function isExtensionProductive ($ext_name = '') { } // END - if //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - ENTERED!'); - // Do we have cache? + // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$ext_name])) { // Load extension only if not yet loaded if (!isset($GLOBALS['ext_productive'][$ext_name])) {