]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions-functions.php
Do not add columns to CREATE statements if you already add them with ALTER TABLE
[mailer.git] / inc / extensions-functions.php
index ae3cf47a9024a98f6d44e797a8d610b543ab14f5..435f7b92d3d9fa44f3bf49b8825227924890d450 100644 (file)
@@ -996,19 +996,6 @@ function doDeactivateExtension ($ext_name, $inRebuild = FALSE) {
        );
 }
 
-// Checks whether the extension is older than given
-function isExtensionOlder ($ext_name, $ext_ver) {
-       // Get current extension version
-       $currVersion = getExtensionVersion($ext_name);
-
-       // Remove all dots from both versions
-       $currVersion = str_replace('.', '', $currVersion);
-       $ext_ver = str_replace('.', '', $ext_ver);
-
-       // Now compare both and return the result
-       return ($currVersion < $ext_ver);
-}
-
 // Creates a new task for updated extension
 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
        // Create subject line
@@ -1164,20 +1151,20 @@ function addExtensionNotes ($ext_ver) {
                                // Initial release
                                $content = array(
                                        'ver'   => $ext_ver,
-                                       'notes' => '{--INITIAL_RELEASE--}'
+                                       'notes' => '{--ADMIN_EXTENSION_INITIAL_RELEASE--}'
                                );
                        } else {
                                // Not productive
                                $content = array(
                                        'ver'   => $ext_ver,
-                                       'notes' => '{--DEVELOPER_RELEASE--}'
+                                       'notes' => '{--ADMIN_EXTENSION_DEVELOPER_RELEASE--}'
                                );
                        }
                } else {
                        // No update notes found
                        $content = array(
                                'ver'   => $ext_ver,
-                               'notes' => '{--NO_UPDATE_NOTICES--}'
+                               'notes' => '{--ADMIN_EXTENSION_UPDATE_NOTICES_404--}'
                        );
                }
 
@@ -1850,8 +1837,8 @@ CHARACTER SET utf8
 COLLATE utf8_general_ci
 COMMENT ' . chr(39) . $comment . chr(39));
        } else {
-               // Is already there, which should not happen
-               reportBug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
+               // Is already there
+               logDebugMessage(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created.');
        }
 }
 
@@ -1859,8 +1846,10 @@ COMMENT ' . chr(39) . $comment . chr(39));
 function addDropTableSql ($tableName) {
        // Is the table there?
        if (ifSqlTableExists($tableName)) {
-               // Then add it, non-existing tables can be ignored because it will
-               // happen with every newly installed extension.
+               /*
+                * Then add it, non-existing tables can be ignored because it will
+                * happen with every newly installed extension.
+                */
                addExtensionSql('DROP TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '`');
 
                // Mark it as gone
@@ -1870,6 +1859,9 @@ function addDropTableSql ($tableName) {
 
 // Adds a RENAME TABLE stament if 'from' table exist and 'to' table not
 function addRenameTableSql ($fromTable, $toTable) {
+       // Make sure both are not the same
+       assert($fromTable != $toTable);
+
        // Is renaming required?
        if ((ifSqlTableExists($fromTable)) && (!ifSqlTableExists($toTable))) {
                // Add it
@@ -2005,12 +1997,96 @@ 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)) {
+               // Then add it
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD `' . $columnName . '` ' . $columnSql);
+       } elseif (isDebugModeEnabled()) {
+               // Add debug line
+               logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $columnName . ',columnSql=' . $columnSql . ': does already exist.');
+       }
+}
+
+// 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)) {
+               // Then add it
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD INDEX `' . $indexName . '` ' . $columnSql);
+       } elseif (isDebugModeEnabled()) {
+               // Add debug line
+               logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',indexName=' . $indexName . ',columnSql=' . $columnSql . ': does already exist.');
+       }
+}
+
+// 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)) {
+               // Then add it
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD UNIQUE INDEX `' . $indexName . '` ' . $columnSql);
+       } elseif (isDebugModeEnabled()) {
+               // Add debug line
+               logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',indexName=' . $indexName . ',columnSql=' . $columnSql . ': does already exist.');
+       }
+}
+
+// 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)) {
+               // Then add it
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD FULLTEXT `' . $indexName . '` ' . $columnSql);
+       } elseif (isDebugModeEnabled()) {
+               // Add debug line
+               logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',indexName=' . $indexName . ',columnSql=' . $columnSql . ': does already exist.');
+       }
+}
+
+// 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)))) {
+               // Then add it
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` CHANGE `' . $fromColumnName . '` `' . $toColumnName . '` ' . $columnSql);
+       } elseif (isDebugModeEnabled()) {
+               // Add debug line
+               logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',fromColumnName=' . $fromColumnName . ',toColumnName=' . $toColumnName . ',columnSql=' . $columnSql . ': Cannot be changed.');
+       }
+}
+
+// Add ALTER TABLE `foo` DROP sql if not found
+function addExtensionDropTableColumnSql ($tableName, $columnName) {
+       // Is the column there?
+       if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName)) {
+               // Then add it
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` DROP `' . $columnName . '`');
+       } elseif (isDebugModeEnabled()) {
+               // Add debug line
+               logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $columnName . ': does not exist.');
+       }
+}
+
+// Add ALTER TABLE `foo` DROP INDEX sql if not found
+function addExtensionDropTableIndexSql ($tableName, $indexName) {
+       // Is the column there?
+       if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $indexName)) {
+               // Then add it
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` DROP INDEX `' . $indexName . '`');
+       } elseif (isDebugModeEnabled()) {
+               // Add debug line
+               logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',indexName=' . $indexName . ': does not exist.');
+       }
+}
+
 // Add configuration entry if not found for actual extension
 function addConfigAddSql ($columnName, $columnSql) {
        // Is the column there?
-       if (!ifSqlColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) {
+       if (!ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) {
                // Not found, so add it
-               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `' . $columnName . '` ' . $columnSql);
+               addExtensionAddTableColumnSql('config', $columnName, $columnSql);
        } elseif (isDebugModeEnabled()) {
                // Add debug line
                logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' already created. columnSql=' . $columnSql);
@@ -2020,9 +2096,9 @@ function addConfigAddSql ($columnName, $columnSql) {
 // Drop configuration entry if found for actual extension
 function addConfigDropSql ($columnName) {
        // Is the column there?
-       if (ifSqlColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) {
+       if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) {
                // Found, so add it
-               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_config` DROP `' . $columnName . '`');
+               addExtensionDropTableColumnSql('config', $columnName);
        } elseif (isDebugModeEnabled()) {
                // Add debug line, reportBug() would cause some extenion updates fail
                logDebugMessage(__FUNCTION__, __LINE__, 'Configuration entry ' . $columnName . ' not found.');