]> 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 c5f03b20974538a99d5a601c028bbcbf7ebc0d53..435f7b92d3d9fa44f3bf49b8825227924890d450 100644 (file)
@@ -1837,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.');
        }
 }
 
@@ -1846,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
@@ -1857,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
@@ -1995,7 +2000,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 (!ifSqlColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName)) {
+       if (!ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName)) {
                // Then add it
                addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD `' . $columnName . '` ' . $columnSql);
        } elseif (isDebugModeEnabled()) {
@@ -2004,10 +2009,46 @@ 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)) {
+               // 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 ((ifSqlColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $fromColumnName)) && (($fromColumnName == $toColumnName) || (!ifSqlColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $toColumnName)))) {
+       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()) {
@@ -2019,7 +2060,7 @@ function addExtensionChangeTableColumnSql ($tableName, $fromColumnName, $toColum
 // Add ALTER TABLE `foo` DROP sql if not found
 function addExtensionDropTableColumnSql ($tableName, $columnName) {
        // Is the column there?
-       if (ifSqlColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName)) {
+       if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName)) {
                // Then add it
                addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` DROP `' . $columnName . '`');
        } elseif (isDebugModeEnabled()) {
@@ -2028,10 +2069,22 @@ 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)) {
+               // 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
                addExtensionAddTableColumnSql('config', $columnName, $columnSql);
        } elseif (isDebugModeEnabled()) {
@@ -2043,7 +2096,7 @@ 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
                addExtensionDropTableColumnSql('config', $columnName);
        } elseif (isDebugModeEnabled()) {