Merge "Use HTML::hidden to create input fields"
[lhc/web/wiklou.git] / includes / installer / DatabaseUpdater.php
index f8ab1f2..8f5858b 100644 (file)
@@ -20,6 +20,8 @@
  * @file
  * @ingroup Deployment
  */
+use Wikimedia\Rdbms\Database;
+use Wikimedia\Rdbms\IDatabase;
 use MediaWiki\MediaWikiServices;
 
 require_once __DIR__ . '/../../maintenance/Maintenance.php';
@@ -81,6 +83,7 @@ abstract class DatabaseUpdater {
                FixDefaultJsonContentPages::class,
                CleanupEmptyCategories::class,
                AddRFCAndPMIDInterwiki::class,
+               PopulatePPSortKey::class
        ];
 
        /**
@@ -103,8 +106,6 @@ abstract class DatabaseUpdater {
        protected $holdContentHandlerUseDB = true;
 
        /**
-        * Constructor
-        *
         * @param Database $db To perform updates on
         * @param bool $shared Whether to perform updates on shared tables
         * @param Maintenance $maintenance Maintenance object which created us
@@ -392,7 +393,7 @@ abstract class DatabaseUpdater {
         * Writes the schema updates desired to a file for the DB Admin to run.
         * @param array $schemaUpdate
         */
-       private function writeSchemaUpdateFile( $schemaUpdate = [] ) {
+       private function writeSchemaUpdateFile( array $schemaUpdate = [] ) {
                $updates = $this->updatesSkipped;
                $this->updatesSkipped = [];
 
@@ -425,7 +426,7 @@ abstract class DatabaseUpdater {
         *
         * @param array $what What updates to perform
         */
-       public function doUpdates( $what = [ 'core', 'extensions', 'stats' ] ) {
+       public function doUpdates( array $what = [ 'core', 'extensions', 'stats' ] ) {
                $this->db->setSchemaVars( $this->getSchemaVars() );
 
                $what = array_flip( $what );
@@ -924,11 +925,41 @@ abstract class DatabaseUpdater {
                } elseif ( $this->updateRowExists( $updateKey ) ) {
                        $this->output( "...$field in table $table already modified by patch $patch.\n" );
                } else {
-                       $this->insertUpdateRow( $updateKey );
+                       $apply = $this->applyPatch( $patch, $fullpath, "Modifying $field field of table $table" );
+                       if ( $apply ) {
+                               $this->insertUpdateRow( $updateKey );
+                       }
+                       return $apply;
+               }
+               return true;
+       }
 
-                       return $this->applyPatch( $patch, $fullpath, "Modifying $field field of table $table" );
+       /**
+        * Modify an existing table, similar to modifyField. Intended for changes that
+        *  touch more than one column on a table.
+        *
+        * @param string $table Name of the table to modify
+        * @param string $patch Name of the patch file to apply
+        * @param string|bool $fullpath Whether to treat $patch path as relative or not, defaults to false
+        * @return bool False if this was skipped because of schema changes being skipped
+        */
+       public function modifyTable( $table, $patch, $fullpath = false ) {
+               if ( !$this->doTable( $table ) ) {
+                       return true;
                }
 
+               $updateKey = "$table-$patch";
+               if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
+                       $this->output( "...$table table does not exist, skipping modify table patch.\n" );
+               } elseif ( $this->updateRowExists( $updateKey ) ) {
+                       $this->output( "...table $table already modified by patch $patch.\n" );
+               } else {
+                       $apply = $this->applyPatch( $patch, $fullpath, "Modifying table $table" );
+                       if ( $apply ) {
+                               $this->insertUpdateRow( $updateKey );
+                       }
+                       return $apply;
+               }
                return true;
        }