Merge "(bug 44141) Vector: Phase out one-pixel images."
[lhc/web/wiklou.git] / includes / installer / DatabaseUpdater.php
index 2fe9676..746cd12 100644 (file)
@@ -256,6 +256,19 @@ abstract class DatabaseUpdater {
                $this->extensionUpdates[] = array( 'dropField', $tableName, $columnName, $sqlPath, true );
        }
 
+       /**
+        * Drop an index from an extension table
+        *
+        * @since 1.21
+        *
+        * @param $tableName string The table name
+        * @param $indexName string The index name
+        * @param $sqlPath string The path to the SQL change path
+        */
+       public function dropExtensionIndex( $tableName, $indexName, $sqlPath ) {
+               $this->extensionUpdates[] = array( 'dropIndex', $tableName, $indexName, $sqlPath, true );
+       }
+
        /**
         *
         * @since 1.20
@@ -267,6 +280,32 @@ abstract class DatabaseUpdater {
                $this->extensionUpdates[] = array( 'dropTable', $tableName, $sqlPath, true );
        }
 
+       /**
+        * Rename an index on an extension table
+        *
+        * @since 1.21
+        *
+        * @param $tableName string The table name
+        * @param $oldIndexName string The old index name
+        * @param $newIndexName string The new index name
+        * @param $skipBothIndexExistWarning Boolean: Whether to warn if both the old and the new indexes exist. [facultative; by default, false]
+        * @param $sqlPath string The path to the SQL change path
+        */
+       public function renameExtensionIndex( $tableName, $oldIndexName, $newIndexName, $sqlPath, $skipBothIndexExistWarning = false ) {
+               $this->extensionUpdates[] = array( 'renameIndex', $tableName, $oldIndexName, $newIndexName, $skipBothIndexExistWarning, $sqlPath, true );
+       }
+
+       /**
+        * @since 1.21
+        *
+        * @param $tableName string The table name
+        * @param $fieldName string The field to be modified
+        * @param $sqlPath string The path to the SQL change path
+        */
+       public function modifyExtensionField( $tableName, $fieldName, $sqlPath) {
+               $this->extensionUpdates[] = array( 'modifyField', $tableName, $fieldName, $sqlPath, true );
+       }
+
        /**
         *
         * @since 1.20
@@ -412,7 +451,7 @@ abstract class DatabaseUpdater {
                $key = "updatelist-$version-" . time();
                $this->db->insert( 'updatelog',
                        array( 'ul_key' => $key, 'ul_value' => serialize( $updates ) ),
-                        __METHOD__ );
+                       __METHOD__ );
                $this->db->setFlag( DBO_DDLMODE );
        }
 
@@ -536,7 +575,7 @@ abstract class DatabaseUpdater {
         *
         * @return Array
         */
-       protected abstract function getCoreUpdateList();
+       abstract protected function getCoreUpdateList();
 
        /**
         * Append an SQL fragment to the open file handle.
@@ -569,6 +608,7 @@ abstract class DatabaseUpdater {
 
        /**
         * Applies a SQL patch
+        *
         * @param $path String Path to the patch file
         * @param $isFullPath Boolean Whether to treat $path as a relative or not
         * @param $msg String Description of the patch
@@ -593,12 +633,13 @@ abstract class DatabaseUpdater {
                } else {
                        $this->db->sourceFile( $path );
                }
-               $this->output( "done.\n" );
+               $this->output( "done.\n" );
                return true;
        }
 
        /**
         * Add a new table to the database
+        *
         * @param $name String Name of the new table
         * @param $patch String Path to the patch file
         * @param $fullpath Boolean Whether to treat $patch path as a relative or not
@@ -619,6 +660,7 @@ abstract class DatabaseUpdater {
 
        /**
         * Add a new field to an existing table
+        *
         * @param $table String Name of the table to modify
         * @param $field String Name of the new field
         * @param $patch String Path to the patch file
@@ -642,6 +684,7 @@ abstract class DatabaseUpdater {
 
        /**
         * Add a new index to an existing table
+        *
         * @param $table String Name of the table to modify
         * @param $index String Name of the new index
         * @param $patch String Path to the patch file
@@ -655,7 +698,6 @@ abstract class DatabaseUpdater {
 
                if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
                        $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
-                       return false;
                } else if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
                        $this->output( "...index $index already set on $table table.\n" );
                } else {
@@ -690,7 +732,7 @@ abstract class DatabaseUpdater {
         * Drop an index from an existing table
         *
         * @param $table String: Name of the table to modify
-        * @param $index String: Name of the old index
+        * @param $index String: Name of the index
         * @param $patch String: Path to the patch file
         * @param $fullpath Boolean: Whether to treat $patch path as a relative or not
         * @return Boolean false if this was skipped because schema changes are skipped
@@ -708,6 +750,48 @@ abstract class DatabaseUpdater {
                return true;
        }
 
+       /**
+        * Rename an index from an existing table
+        *
+        * @param $table String: Name of the table to modify
+        * @param $oldIndex String: Old name of the index
+        * @param $newIndex String: New name of the index
+        * @param $skipBothIndexExistWarning Boolean: Whether to warn if both the old and the new indexes exist.
+        * @param $patch String: Path to the patch file
+        * @param $fullpath Boolean: Whether to treat $patch path as a relative or not
+        * @return Boolean false if this was skipped because schema changes are skipped
+        */
+       protected function renameIndex( $table, $oldIndex, $newIndex, $skipBothIndexExistWarning, $patch, $fullpath = false ) {
+               if ( !$this->doTable( $table ) ) {
+                       return true;
+               }
+
+               // First requirement: the table must exist
+               if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
+                       $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
+                       return true;
+               }
+
+               // Second requirement: the new index must be missing
+               if ( $this->db->indexExists( $table, $newIndex, __METHOD__ ) ) {
+                       $this->output( "...index $newIndex already set on $table table.\n" );
+                       if ( !$skipBothIndexExistWarning && $this->db->indexExists( $table, $oldIndex, __METHOD__ ) ) {
+                               $this->output( "...WARNING: $oldIndex still exists, despite it has been renamed into $newIndex (which also exists).\n" .
+                                       "            $oldIndex should be manually removed if not needed anymore.\n" );
+                       }
+                       return true;
+               }
+
+               // Third requirement: the old index must exist
+               if ( !$this->db->indexExists( $table, $oldIndex, __METHOD__ ) ) {
+                       $this->output( "...skipping: index $oldIndex doesn't exist.\n" );
+                       return true;
+               }
+
+               // Requirements have been satisfied, patch can be applied
+               return $this->applyPatch( $patch, $fullpath, "Renaming index $oldIndex into $newIndex to table $table" );
+       }
+
        /**
         * If the specified table exists, drop it, or execute the
         * patch if one is provided.