From: Roland Häder Date: Tue, 27 Nov 2012 23:01:45 +0000 (+0000) Subject: Installation of extensions fixes X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1dfd89652afd8c4542e791a5d90315019365e962;p=mailer.git Installation of extensions fixes - Again some extensions has not been fully rewritten to newly introduced wrapper functions which caused them to not install - An extra back-tick (`) was found in column name :( - Added optional $forceFound variable which can be used to (if the table is missing) that the column/key is marked as "found" - Expanded debug messages with column/key name and $forceFound variable - TODOs.txt updated --- diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index 6c65c7f197..6488912587 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -45,14 +45,14 @@ ./inc/extensions/ext-nickname.php:52: // @TODO NOT NULL DEFAULT '' is bad practice, use NULL ./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:2172:// @TODO This should be rewrittten to allow, more development states, e.g. 'planing','alpha','beta','beta2','stable' +./inc/extensions-functions.php:2176:// @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/filters.php:1320: // @TODO No banner found, output some default banner +./inc/filters.php:1317: // @TODO No banner found, output some default banner ./inc/functions.php:1104: // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ? ./inc/functions.php:1190: // @TODO Are these convertions still required? ./inc/functions.php:1211:// @TODO Rewrite this function to use readFromFile() and writeToFile() diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 2457c6a474..e9ebc79cfc 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -668,7 +668,7 @@ function ifSqlTableExists ($tableName) { } // Is a table column there? -function ifSqlTableColumnExists ($tableName, $columnName) { +function ifSqlTableColumnExists ($tableName, $columnName, $forceFound = FALSE) { // Remove back-ticks $columnName = str_replace('`', '', $columnName); @@ -678,8 +678,8 @@ function ifSqlTableColumnExists ($tableName, $columnName) { // If the table is not there, it is okay if (!ifSqlTableExists($tableName)) { // Then abort here - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Table ' . $tableName . ' does not exist.'); - return FALSE; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Table ' . $tableName . ' does not exist, columnName=' . $columnName . ',forceFound=' . intval($forceFound)); + return (($forceFound === FALSE) && (isInstallationPhase())); } // END - if // Get column information @@ -695,7 +695,7 @@ function ifSqlTableColumnExists ($tableName, $columnName) { if (isInstallationPhase()) { // Then silently abort here //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'result[]=' . gettype($result) . ',isLinkUp=' . intval(SQL_IS_LINK_UP()) . ',tableName=' . $tableName . ',columnName=' . $columnName . ' - Returning FALSE ...'); - return FALSE; + return $forceFound; } else { // Please report this reportBug(__FUNCTION__, __LINE__, 'result[]=' . gettype($result) . ' is not a resource.'); @@ -714,7 +714,7 @@ function ifSqlTableColumnExists ($tableName, $columnName) { } // Checks depending on the mode if the index is there -function ifSqlTableIndexExist ($tableName, $keyName) { +function ifSqlTableIndexExist ($tableName, $keyName, $forceFound = FALSE) { // Remove back-ticks $keyName = str_replace('`', '', $keyName); @@ -724,8 +724,8 @@ function ifSqlTableIndexExist ($tableName, $keyName) { // If the table is not there, it is okay if (!ifSqlTableExists($tableName)) { // Then abort here - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Table ' . $tableName . ' does not exist.'); - return FALSE; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Table ' . $tableName . ' does not exist, keyName=' . $keyName . ',forceFound=' . intval($forceFound)); + return (($forceFound === FALSE) && (isInstallationPhase())); } // END - if // Show indexes @@ -737,14 +737,14 @@ function ifSqlTableIndexExist ($tableName, $keyName) { if (isInstallationPhase()) { // Then silently abort here //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'result[]=' . gettype($result) . ',isLinkUp=' . intval(SQL_IS_LINK_UP()) . ',tableName=' . $tableName . ',keyName=' . $keyName . ' - Returning FALSE ...'); - return FALSE; + return $forceFound; } else { // Please report this reportBug(__FUNCTION__, __LINE__, 'result[]=' . gettype($result) . ' is not a resource.'); } } // END - if - // The column is not found by default + // The key is not found by default $doesExist = FALSE; // Walk through all diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php index 435f7b92d3..e6fcb897ee 100644 --- a/inc/extensions-functions.php +++ b/inc/extensions-functions.php @@ -357,7 +357,7 @@ function registerExtension ($ext_name, $taskId, $isDryRun = FALSE, $ignoreUpdate setSqlsArray(getExtensionSqls()); // Run installation pre-installation filters - runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun(), 'enable_codes' => FALSE)); + runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun(), 'ext_installing' => TRUE, 'enable_codes' => FALSE)); // Register extension //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'insert=' . getCurrentExtensionName() . '/' . getCurrentExtensionVersion() . ' - INSERT!'); @@ -771,7 +771,7 @@ function updateExtension ($ext_name, $ext_ver, $isDryRun = FALSE, $ignoreDepende setSqlsArray(getExtensionSqls()); // Run SQLs - runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun(), 'enable_codes' => FALSE)); + runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun(), 'ext_installing' => TRUE, 'enable_codes' => FALSE)); if (isExtensionDryRun() === FALSE) { // Run filters on success extension update @@ -1543,10 +1543,14 @@ function initExtensionSqls ($force = FALSE) { // Adds SQLs to the SQLs array but "assigns" it with current extension name function addExtensionSql ($sql) { + // Copy current name/version to local variable + $currentName = getCurrentExtensionName(); + $currentVersion = getCurrentExtensionVersion(); + // Is is the array there? - if ((!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()])) || (!is_array($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()]))) { + if ((!isset($GLOBALS['ext_sqls'][$currentName][$currentVersion])) || (!is_array($GLOBALS['ext_sqls'][$currentName][$currentVersion]))) { // Init array - $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()] = array(); + $GLOBALS['ext_sqls'][$currentName][$currentVersion] = array(); } // END - if // Is the SQL statement empty? @@ -1560,8 +1564,8 @@ function addExtensionSql ($sql) { } // END - if // Add it - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql); - array_push($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()], $sql); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $currentName . ',ext_version=' . $currentVersion . ',sql=' . $sql); + array_push($GLOBALS['ext_sqls'][$currentName][$currentVersion], $sql); } // Getter for SQLs array for current extension @@ -2000,7 +2004,7 @@ function addSponsorMenuSql ($action, $what, $title, $active, $sort) { // Add ALTER TABLE `foo` ADD sql if not found function addExtensionAddTableColumnSql ($tableName, $columnName, $columnSql) { // Is the column there? - if (!ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName)) { + if (!ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName, isInstallationPhase())) { // Then add it addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD `' . $columnName . '` ' . $columnSql); } elseif (isDebugModeEnabled()) { @@ -2012,7 +2016,7 @@ function addExtensionAddTableColumnSql ($tableName, $columnName, $columnSql) { // Add ALTER TABLE `foo` ADD INDEX sql if not found function addExtensionAddTableIndexSql ($tableName, $indexName, $columnSql) { // Is the column there? - if (!ifSqlTableIndexExist('{?_MYSQL_PREFIX?}_' . $tableName, $indexName)) { + if (!ifSqlTableIndexExist('{?_MYSQL_PREFIX?}_' . $tableName, $indexName, isInstallationPhase())) { // Then add it addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD INDEX `' . $indexName . '` ' . $columnSql); } elseif (isDebugModeEnabled()) { @@ -2024,7 +2028,7 @@ function addExtensionAddTableIndexSql ($tableName, $indexName, $columnSql) { // Add ALTER TABLE `foo` ADD UNIQUE INDEX sql if not found function addExtensionAddTableUniqueSql ($tableName, $indexName, $columnSql) { // Is the column there? - if (!ifSqlTableIndexExist('{?_MYSQL_PREFIX?}_' . $tableName, $indexName)) { + if (!ifSqlTableIndexExist('{?_MYSQL_PREFIX?}_' . $tableName, $indexName, isInstallationPhase())) { // Then add it addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD UNIQUE INDEX `' . $indexName . '` ' . $columnSql); } elseif (isDebugModeEnabled()) { @@ -2035,8 +2039,8 @@ function addExtensionAddTableUniqueSql ($tableName, $indexName, $columnSql) { // Add ALTER TABLE `foo` ADD FULLTEXT sql if not found function addExtensionAddTableFulltextSql ($tableName, $indexName, $columnSql) { - // Is the column there? - if (!ifSqlTableIndexExist('{?_MYSQL_PREFIX?}_' . $tableName, $indexName)) { + // Is the column there and MyISAM engine? (InnoDB doesn't support FULLTEXT) + if ((getTableType() == 'MyISAM') && (!ifSqlTableIndexExist('{?_MYSQL_PREFIX?}_' . $tableName, $indexName, isInstallationPhase()))) { // Then add it addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD FULLTEXT `' . $indexName . '` ' . $columnSql); } elseif (isDebugModeEnabled()) { @@ -2048,7 +2052,7 @@ function addExtensionAddTableFulltextSql ($tableName, $indexName, $columnSql) { // Add ALTER TABLE `foo` CHANGE sql if not found function addExtensionChangeTableColumnSql ($tableName, $fromColumnName, $toColumnName, $columnSql) { // Is the column there? - if ((ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $fromColumnName)) && (($fromColumnName == $toColumnName) || (!ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $toColumnName)))) { + if ((ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $fromColumnName)) && (($fromColumnName == $toColumnName) || (!ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $toColumnName, isInstallationPhase())))) { // Then add it addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` CHANGE `' . $fromColumnName . '` `' . $toColumnName . '` ' . $columnSql); } elseif (isDebugModeEnabled()) { @@ -2060,7 +2064,7 @@ function addExtensionChangeTableColumnSql ($tableName, $fromColumnName, $toColum // Add ALTER TABLE `foo` DROP sql if not found function addExtensionDropTableColumnSql ($tableName, $columnName) { // Is the column there? - if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName)) { + if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName, isInstallationPhase())) { // Then add it addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` DROP `' . $columnName . '`'); } elseif (isDebugModeEnabled()) { @@ -2072,7 +2076,7 @@ function addExtensionDropTableColumnSql ($tableName, $columnName) { // Add ALTER TABLE `foo` DROP INDEX sql if not found function addExtensionDropTableIndexSql ($tableName, $indexName) { // Is the column there? - if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $indexName)) { + if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $indexName, isInstallationPhase())) { // Then add it addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` DROP INDEX `' . $indexName . '`'); } elseif (isDebugModeEnabled()) { diff --git a/inc/extensions/ext-refback.php b/inc/extensions/ext-refback.php index 192176096e..b6252421ea 100644 --- a/inc/extensions/ext-refback.php +++ b/inc/extensions/ext-refback.php @@ -108,8 +108,8 @@ switch (getExtensionMode()) { addExtensionDependency('user'); // SQL commands to run - drop old first, add new next - addExtensionDropTableColumnSql('user_refs', 'refback`'); - addExtensionDropTableColumnSql('user_refs', 'points`'); + addExtensionDropTableColumnSql('user_refs', 'refback'); + addExtensionDropTableColumnSql('user_refs', 'points'); addExtensionAddTableColumnSql('user_refs', 'refback_percents', 'FLOAT(4,1) NOT NULL DEFAULT 0.0'); addExtensionAddTableColumnSql('user_refs', 'refback_points', 'FLOAT(20,5) NOT NULL DEFAULT 0.00000'); diff --git a/inc/extensions/ext-sql_patches.php b/inc/extensions/ext-sql_patches.php index 40a8e3a95d..a4cb1d7e67 100644 --- a/inc/extensions/ext-sql_patches.php +++ b/inc/extensions/ext-sql_patches.php @@ -355,11 +355,6 @@ IN ( addExtensionAddTableUniqueSql('mod_reg', 'module', '(`module`)'); addExtensionAddTableIndexSql('admin_menu', 'action', '(`action`)'); addExtensionAddTableIndexSql('admin_menu', 'what', '(`what`)'); - addExtensionAddTableIndexSql('task_system', 'task_type', '(`task_type`)'); - addExtensionAddTableIndexSql('task_system', 'status', '(`status`)'); - addExtensionAddTableIndexSql('task_system', 'task_created', '(`task_created`)'); - addExtensionAddTableFulltextSql('task_system', 'subject', '(`subject`)'); - addExtensionAddTableIndexSql('task_system', 'subject', '(`subject`)'); addExtensionAddTableIndexSql('extensions', 'ext_active', '(`ext_active`)'); addExtensionAddTableIndexSql('guest_menu', 'action', '(`action`)'); addExtensionAddTableIndexSql('guest_menu', 'what', '(`what`)'); @@ -549,10 +544,8 @@ INDEX (`admin_id`)", break; case '0.4.8': // SQL queries for v0.4.8 - addExtensionAddTableIndexSql('task_system', 'subject', '(`subject`)'); - // Update notes (these will be set as task text!) - setExtensionUpdateNotes("Index für Betreff eingefügt."); + setExtensionUpdateNotes("Update nach ext-task verschoben."); break; case '0.4.9': // SQL queries for v0.4.9 @@ -561,8 +554,8 @@ INDEX (`admin_id`)", break; case '0.5.0': // SQL queries for v0.5.0 - addExtensionDropTableIndexSql('refsystem', 'level`'); - addExtensionDropTableIndexSql('refsystem', 'userid`'); + addExtensionDropTableIndexSql('refsystem', 'level'); + addExtensionDropTableIndexSql('refsystem', 'userid'); addExtensionAddTableIndexSql('refsystem', 'userid_level', '(`userid`, `level`)'); // Update notes (these will be set as task text!) @@ -618,7 +611,7 @@ INDEX (`admin_id`)", break; case '0.5.8': // SQL queries for v0.5.8 - addExtensionDropTableColumnSql('extensions` DROP `ext_lang_file`'); + addExtensionDropTableColumnSql('extensions', 'ext_lang_file'); // Update notes (these will be set as task text!) setExtensionUpdateNotes("Sprachdateinamen werden nicht mehr in der Datenbank behalten."); diff --git a/inc/extensions/ext-task.php b/inc/extensions/ext-task.php index 41d0eb429a..29945d6c92 100644 --- a/inc/extensions/ext-task.php +++ b/inc/extensions/ext-task.php @@ -55,6 +55,13 @@ switch (getExtensionMode()) { addAdminMenuSql('task', NULL, 'Aufgaben-Management','Erweitertes Aufgaben-Management zur leichten verwaltung der vom System erzeugten Aufgaben.',1); addAdminMenuSql('task','list_task','Aufgaben auflisten','Alle Ihnen zugewiesenen Aufgaben auflisten (keine Updates).',1); addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `status`='SOLVED' WHERE `status`='CLOSED'"); + // These SQL updates has been moved from ext-sql_patches to here + addExtensionAddTableIndexSql('task_system', 'task_type', '(`task_type`)'); + addExtensionAddTableIndexSql('task_system', 'status', '(`status`)'); + addExtensionAddTableIndexSql('task_system', 'task_created', '(`task_created`)'); + addExtensionAddTableFulltextSql('task_system', 'subject', '(`subject`)'); + addExtensionAddTableIndexSql('task_system', 'subject', '(`subject`)'); + addExtensionAddTableIndexSql('task_system', 'subject', '(`subject`)'); break; case 'remove': // Do stuff when removing extension diff --git a/inc/extensions/ext-user.php b/inc/extensions/ext-user.php index 4396672e91..de7aab71a4 100644 --- a/inc/extensions/ext-user.php +++ b/inc/extensions/ext-user.php @@ -386,7 +386,7 @@ INDEX (`userid`)", break; case '0.3.6': // SQL queries for v0.3.6 - addExtensionDropTableIndexSql('user_cats', 'userid`'); + addExtensionDropTableIndexSql('user_cats', 'userid'); addExtensionAddTableUniqueSql('user_cats', 'userid_catid', '(`userid`, `cat_id`)'); // Update notes (these will be set as task text!) @@ -396,7 +396,6 @@ INDEX (`userid`)", case '0.3.7': // SQL queries for v0.3.7 addExtensionChangeTableColumnSql('user_points', 'id', 'id', 'BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT'); addExtensionChangeTableColumnSql('user_points', 'userid', 'userid', 'BIGINT(20) UNSIGNED NULL DEFAULT NULL'); - addExtensionChangeTableColumnSql('user_points', 'cat_id', 'cat_id', 'TINYINT(3) UNSIGNED NULL DEFAULT NULL'); addExtensionChangeTableColumnSql('user_data', 'userid', 'userid', 'BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT'); addExtensionChangeTableColumnSql('user_del', 'userid', 'userid', 'BIGINT(20) UNSIGNED NULL DEFAULT NULL'); addExtensionChangeTableColumnSql('user_links', 'stats_id', 'stats_id', 'BIGINT(20) UNSIGNED NULL DEFAULT NULL'); diff --git a/inc/filters.php b/inc/filters.php index 98cf7eb463..0c6b498021 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -277,8 +277,8 @@ function FILTER_RUN_SQLS ($filterData) { // Is there still a query left? if (!empty($sql)) { - // Is there an "ALTER TABLE" command? - if (substr(strtolower($sql), 0, 11) == 'alter table') { + // Is there an "ALTER TABLE" command? Exclude installation phase here as it would cause this query to fail + if ((substr(strtolower($sql), 0, 11) == 'alter table') && (!isset($filterData['ext_installing']))) { // Analyse the alteration command //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Alterting table: ' . $sql . ',enable_codes=' . intval($filterData['enable_codes'])); SQL_ALTER_TABLE($sql, __FUNCTION__, __LINE__, $filterData['enable_codes']); @@ -301,9 +301,6 @@ function FILTER_RUN_SQLS ($filterData) { // Debug message //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '- Left!'); - // Clear any SQL queries - //initSqls(); - // Return counter return $count; } diff --git a/inc/fix_menu.php b/inc/fix_menu.php index 5fbfcab34d..62515a9601 100644 --- a/inc/fix_menu.php +++ b/inc/fix_menu.php @@ -98,11 +98,11 @@ foreach (array('guest','member','admin') as $menu) { initSqls(); // Now insert our unqiue key for action-what combination - addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP KEY `action_what`", $menu)); + addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP INDEX `action_what`", $menu)); addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE INDEX `action_what` (`action`, `what`)", $menu)); // Now insert our unqiue key for what - addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP KEY `what`", $menu)); + addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` DROP INDEX `what`", $menu)); addSql(sprintf("ALTER TABLE `{?_MYSQL_PREFIX?}_%s_menu` ADD UNIQUE INDEX `what` (`what`)", $menu)); // And run all