From 771a678b35cf29540fccf550adc5d3b63feefc7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 1 Oct 2012 21:54:05 +0000 Subject: [PATCH] More rewrites/fixes: - Added check in addExtensionSql() if $sql is empty and if so, return without adding empty entries - Added saving of 'previous_extension' which is the "source extension" of the dependency request ('previous_extension' requires other one) - Added check for entry in 'previous_extension' and abort (under development) - Added search_array() from PHP user comments (thank you for sharing this code) - Other minor fixes/improvements - TODOs.txt updated --- DOCS/TODOs.txt | 22 +++++++++++----------- inc/extensions-functions.php | 29 +++++++++++++++++++++-------- inc/extensions/ext-user.php | 3 --- inc/mysql-manager.php | 10 ++++++++-- inc/wrapper-functions.php | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 24 deletions(-) diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index 0a40a813fc..423b8bc3dc 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -43,19 +43,19 @@ ./inc/extensions/ext-rallye.php:94: // @TODO Fix config_rallye_prices to list_rallye_prices ./inc/extensions/ext-yoomedia.php:121: // @TODO Can this be moved into a database table? ./inc/extensions/ext-yoomedia.php:54:// @TODO Only deprecated when 'ext-network' is ready! setExtensionDeprecated('Y'); -./inc/extensions-functions.php:2012:// @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable' -./inc/extensions-functions.php:421: // @TODO This redirect is still needed to register sql_patches! Please try to avoid it -./inc/extensions-functions.php:437:// @TODO Change from ext_id to ext_name (not just even the variable! ;-) ) -./inc/extensions-functions.php:577: // @TODO Extension is loaded, what next? +./inc/extensions-functions.php:2038:// @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable' +./inc/extensions-functions.php:424: // @TODO This redirect is still needed to register sql_patches! Please try to avoid it +./inc/extensions-functions.php:440:// @TODO Change from ext_id to ext_name (not just even the variable! ;-) ) +./inc/extensions-functions.php:580: // @TODO Extension is loaded, what next? ./inc/filter/bonus_filter.php:56: // @TODO This query isn't right, it will only update if the user was for a longer time away! ./inc/filter/cache_filter.php:94: // @TODO This should be rewritten not to load the cache file for just checking if it is there for save removal. ./inc/filter/forced_filter.php:73: // @TODO This part is unfinished ./inc/functions.php:1082: // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ? ./inc/functions.php:1168: // @TODO Are these convertions still required? ./inc/functions.php:1189:// @TODO Rewrite this function to use readFromFile() and writeToFile() -./inc/functions.php:1810: // @TODO Find a way to cache this -./inc/functions.php:1915: // @TODO This is still very static, rewrite it somehow -./inc/functions.php:2119: // @TODO Rename column data_type to e.g. mail_status +./inc/functions.php:1712: // @TODO Find a way to cache this +./inc/functions.php:1817: // @TODO This is still very static, rewrite it somehow +./inc/functions.php:2021: // @TODO Rename column data_type to e.g. mail_status ./inc/gen_sql_patches.php:95:// @TODO Rewrite this to a filter ./inc/header.php:66:// @TODO Find a way to not use direct module comparison ./inc/install-functions.php:91: // @TODO DEACTIVATED: changeDataInLocalConfigurationFile('OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestElement('omode'), 0); @@ -168,9 +168,9 @@ ./inc/modules/member/what-unconfirmed.php:169: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() ./inc/modules/member/what-unconfirmed.php:234: // @TODO This 'userid' cannot be saved because of encapsulated EL code ./inc/modules/order.php:78: // @TODO Unused: 2,4 -./inc/mysql-manager.php:1424: // @TODO Rewrite these lines to a filter -./inc/mysql-manager.php:1448: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1704: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:1421: // @TODO Rewrite these lines to a filter +./inc/mysql-manager.php:1445: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:1701: // @TODO Rewrite this to a filter ./inc/mysql-manager.php:390: // @TODO Try to rewrite this to one or more functions ./inc/mysql-manager.php:44:// @TODO Can we cache this? ./inc/purge/purge-inact.php:55: // @TODO Rewrite these if() blocks to a filter @@ -185,7 +185,7 @@ ./inc/template-functions.php:285: // @TODO Remove these sanity checks if all is fine ./inc/template-functions.php:598:// @TODO $simple/$constants are deprecated ./inc/template-functions.php:696: // @TODO $userid is deprecated and should be removed from loadEmailTemplate() and replaced with $content[userid] in all templates -./inc/wrapper-functions.php:2916: // @TODO Find a way to not use direct module comparison +./inc/wrapper-functions.php:2956: // @TODO Find a way to not use direct module comparison ./inc/wrapper-functions.php:494:// @TODO Do some more sanity check here ./inc/xml-functions.php:208: // @TODO Handle characters ./mailid.php:102: // @TODO Rewrite this to a filter diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php index a2222b2655..184df7cd02 100644 --- a/inc/extensions-functions.php +++ b/inc/extensions-functions.php @@ -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,8 +1560,18 @@ 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); + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql); array_push($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()], $sql); } diff --git a/inc/extensions/ext-user.php b/inc/extensions/ext-user.php index b71278088a..9d8e7163ab 100644 --- a/inc/extensions/ext-user.php +++ b/inc/extensions/ext-user.php @@ -559,9 +559,6 @@ INDEX (`refid`)", // Register a filter registerFilter(__FILE__, __LINE__, 'pre_user_registration', 'TESTER_USER_REGISTRATION_ADD_SQL_COLUMNS', false, true, isExtensionDryRun()); - // This depends on ext-register - addExtensionDependency('register'); - // Update notes (these will be set as task text!) setExtensionUpdateNotes("Filter zum Hinzufügen von SQL-Spalten für die Mitgliederanmeldung hinzugefügt."); break; diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index a890c6e361..426c64b646 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -1791,14 +1791,20 @@ function registerExtensionPointsData ($subject, $columnName, $lockedMode, $payme $add = ''; // Is the extension equal or newer 0.8.9? - if ((getExtensionMode() == 'register') || (getExtensionMode() == 'update') || (isExtensionInstalledAndNewer('sql_patches', '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? if (((!ifSqlTableExists('points_data')) && ((getExtensionMode() == 'register') || (getExtensionMode() == 'update'))) || (countSumTotalData($subject, 'points_data', 'id', 'subject', true, $add) == 0)) { - // Not found so add an SQL query + // Not found so: + if (isset($GLOBALS['previous_extension'][getCurrentExtensionName()])) { + $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, diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 2adbd0968c..354fe7cbe4 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -2802,6 +2802,40 @@ function parseFloat ($floatString){ return floatval($floatString); } +/** + * Searches a multi-dimensional array (as used in many places) for given + * key/value pair as taken from user comments from PHP documentation website. + * + * @param $array An array with one or more dimensions + * @param $key Key to look for + * @param $valur Value to look for + * @return $results Resulted array or empty array if $array is no array + * @author sunelbegmailcom + * @link http://de.php.net/manual/en/function.array-search.php#110120 + */ +function search_array ($array, $key, $value) { + // Init array result + $results = array(); + + // Is $array really an array? + if (is_array($array)) { + // Does key and value match? + if (isset($array[$key]) && $array[$key] == $value) { + // Then add it as result + $results[] = $array; + } // END - if + + // Search for whole array + foreach ($array as $subArray) { + // Search recursive and merge again + $results = merge_array($results, search_array($subArray, $key, $value)); + } // END - foreach + } // END - if + + // Return resulting array + return $results; +} + // Generates a YES/NO option list from given default function generateYesNoOptions ($defaultValue = '') { // Generate it -- 2.39.2