More rewrites/fixes:
authorRoland Häder <roland@mxchange.org>
Mon, 1 Oct 2012 21:54:05 +0000 (21:54 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 1 Oct 2012 21:54:05 +0000 (21:54 +0000)
- 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
inc/extensions-functions.php
inc/extensions/ext-user.php
inc/mysql-manager.php
inc/wrapper-functions.php

index 0a40a813fc98c5354bbddf80a8981fdaa34d7f6b..423b8bc3dc0d6dff593ce91c747d4e12848b5386 100644 (file)
 ./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);
 ./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
 ./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
index a2222b2655eea62fe5bb863fe9fc9f19575f66d8..184df7cd0241086ba31ec8380413012b2a4f8f61 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,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);
 }
 
index b71278088a1dd45a360bc0d1e54829ad9244fc8b..9d8e7163ab8e7adbd43f5571d0e6f85bc4218132 100644 (file)
@@ -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&uuml;gen von SQL-Spalten f&uuml;r die Mitgliederanmeldung hinzugef&uuml;gt.");
                                break;
index a890c6e36118e498c6518b6da1c356f913c311c7..426c64b646e4252454618802c5181804948b5464 100644 (file)
@@ -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,
index 2adbd0968ceb67d5f4016c5990ae4be3649ffef5..354fe7cbe4743335007219fd6788d750b23f2518 100644 (file)
@@ -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     sunelbe<at>gmail<dot>com
+ * @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