Moved modify_field() from updaters.inc to DatabaseUpdater.php so that it can be used...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 11 Sep 2010 08:35:39 +0000 (08:35 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 11 Sep 2010 08:35:39 +0000 (08:35 +0000)
includes/installer/DatabaseUpdater.php
maintenance/updaters.inc

index 33b5cb6..bb240d1 100644 (file)
@@ -227,7 +227,7 @@ abstract class DatabaseUpdater {
 
                foreach ( $wgExtModifiedFields as $fieldRecord ) {
                        $updates[] = array(
-                               'modify_field', $fieldRecord[0], $fieldRecord[1],
+                               'modifyField', $fieldRecord[0], $fieldRecord[1],
                                        $fieldRecord[2], true
                        );
                }
@@ -328,6 +328,26 @@ abstract class DatabaseUpdater {
                }
        }
 
+       /**
+        * Modify an existing field
+        *
+        * @param $table String: name of the table to modify
+        * @param $field String: name of the old field
+        * @param $patch String: path to the patch file
+        * @param $fullpath Boolean: whether to treat $patch path as a relative or not
+        */
+       public function modifyField( $table, $field, $patch, $fullpath = false ) {
+               if ( !$this->db->tableExists( $table ) ) {
+                       wfOut( "...$table table does not exist, skipping modify field patch\n" );
+               } elseif ( !$this->db->fieldExists( $table, $field ) ) {
+                       wfOut( "...$field field does not exist in $table table, skipping modify field patch\n" );
+               } else {
+                       wfOut( "Modifying $field field of table $table..." );
+                       $this->applyPatch( $patch, $fullpath );
+                       wfOut( "ok\n" );
+               }
+       }
+
        /**
         * Purge the objectcache table
         */
index b657b6d..def3530 100644 (file)
@@ -9,23 +9,6 @@ if ( !defined( 'MEDIAWIKI' ) ) {
        exit( 1 );
 }
 
-function modify_field( $table, $field, $patch, $fullpath = false ) {
-       $dbw = wfGetDB( DB_MASTER );
-       if ( !$dbw->tableExists( $table ) ) {
-               wfOut( "...$table table does not exist, skipping modify field patch\n" );
-       } elseif ( !$dbw->fieldExists( $table, $field ) ) {
-               wfOut( "...$field field does not exist in $table table, skipping modify field patch\n" );
-       } else {
-               wfOut( "Modifying $field field of table $table..." );
-               if ( $fullpath ) {
-                       $dbw->sourceFile( $patch );
-               } else {
-                       $dbw->sourceFile( archive( $patch ) );
-               }
-               wfOut( "ok\n" );
-       }
-}
-
 function drop_index_if_exists( $table, $index, $patch, $fullpath = false ) {
        $dbw = wfGetDB( DB_MASTER );
        if ( $dbw->indexExists( $table, $index ) ) {