return $status;
}
+ /**
+ * Create the tables for each extension the user enabled
+ * @return Status
+ */
+ public function createExtensionTables() {
+ $status = $this->getConnection();
+ if ( !$status->isOK() ) {
+ return $status;
+ }
+ $this->db;
+ $updater = DatabaseUpdater::newForDB( $this->db );
+ $extensionUpdates = $updater->getNewExtensions();
+
+ // No extensions need tables (or haven't updated to new installer support)
+ if( !count( $extensionUpdates ) ) {
+ return $status;
+ }
+
+ $ourExtensions = array_map( 'strtolower', $this->getVar( '_Extensions' ) );
+
+ foreach( $ourExtensions as $ext ) {
+ if( isset( $extensionUpdates[$ext] ) ) {
+ $this->db->begin( __METHOD__ );
+ $error = $this->db->sourceFile( $extensionUpdates[$ext] );
+ if( $error !== true ) {
+ $this->db->rollback( __METHOD__ );
+ $status->warning( 'config-install-tables-failed', $error );
+ } else {
+ $this->db->commit( __METHOD__ );
+ }
+ }
+ }
+ return $status;
+ }
+
+ /**
+ * Create the tables for each extension the user enabled
+ * @return Status
+ */
+ public function createExtensionTables() {
+ $status = $this->getConnection();
+ if ( !$status->isOK() ) {
+ return $status;
+ }
+ $this->db;
+ $updater = DatabaseUpdater::newForDB( $this->db );
+ $extensionUpdates = $updater->getNewExtensions();
+
+ // No extensions need tables (or haven't updated to new installer support)
+ if( !count( $extensionUpdates ) ) {
+ return $status;
+ }
+
+ $ourExtensions = array_map( 'strtolower', $this->getVar( '_Extensions' ) );
+
+ foreach( $ourExtensions as $ext ) {
+ if( isset( $extensionUpdates[$ext] ) ) {
+ $this->db->begin( __METHOD__ );
+ $error = $this->db->sourceFile( $extensionUpdates[$ext] );
+ if( $error !== true ) {
+ $this->db->rollback( __METHOD__ );
+ $status->warning( 'config-install-tables-failed', $error );
+ } else {
+ $this->db->commit( __METHOD__ );
+ }
+ }
+ }
+ return $status;
+ }
+
+ /**
+ * Create the tables for each extension the user enabled
+ * @return Status
+ */
+ public function createExtensionTables() {
+ $status = $this->getConnection();
+ if ( !$status->isOK() ) {
+ return $status;
+ }
+ $this->db;
+ $updater = DatabaseUpdater::newForDB( $this->db );
+ $extensionUpdates = $updater->getNewExtensions();
+
+ // No extensions need tables (or haven't updated to new installer support)
+ if( !count( $extensionUpdates ) ) {
+ return $status;
+ }
+
+ $ourExtensions = array_map( 'strtolower', $this->getVar( '_Extensions' ) );
+
+ foreach( $ourExtensions as $ext ) {
+ if( isset( $extensionUpdates[$ext] ) ) {
+ $this->db->begin( __METHOD__ );
+ $error = $this->db->sourceFile( $extensionUpdates[$ext] );
+ if( $error !== true ) {
+ $this->db->rollback( __METHOD__ );
+ $status->warning( 'config-install-tables-failed', $error );
+ } else {
+ $this->db->commit( __METHOD__ );
+ }
+ }
+ }
+ return $status;
+ }
+
/**
* Get the DBMS-specific options for LocalSettings.php generation.
*
*/
protected $updates = array();
+ /**
+ * List of extension-provided database updates
+ * @var array
+ */
protected $extensionUpdates = array();
+ /**
+ * Used to hold schema files during installation process
+ * @var array
+ */
+ protected $newExtensions = array();
+
/**
* Handle to the database subclass
*
* @param DatabaseBase $db
* @param bool $shared
* @param null $maintenance
- * @return
+ * @return DatabaseUpdater
*/
public static function newForDB( &$db, $shared = false, $maintenance = null ) {
$type = $db->getType();
$this->extensionUpdates[] = array( 'addTable', $tableName, $sqlPath, true );
}
+ /**
+ * Add a brand new extension to MediaWiki. Used during the initial install
+ * @param $ext String Name of extension
+ * @param $sqlPath String Full path to the schema file
+ */
+ public function addNewExtension( $ext, $sqlPath ) {
+ $this->newExtensions[ strtolower( $ext ) ] = $sqlPath;
+ }
+
+ /**
+ * Get the list of extensions that registered a schema with our DB type
+ * @return array
+ */
+ public function getNewExtensions() {
+ return $this->newExtensions;
+ }
+
/**
* Get the list of extension-defined updates
*
* @return Status
*/
protected function includeExtensions() {
+ global $IP;
$exts = $this->getVar( '_Extensions' );
- $path = $this->getVar( 'IP' ) . '/extensions';
+ $IP = $this->getVar( 'IP' );
+ $path = $IP . '/extensions';
+
+ /**
+ * We need to include DefaultSettings before including extensions to avoid
+ * warnings about unset variables. However, the only thing we really
+ * want here is $wgHooks['LoadExtensionSchemaUpdates']. This won't work
+ * if the extension has hidden hook registration in $wgExtensionFunctions,
+ * but we're not opening that can of worms
+ * @see https://bugzilla.wikimedia.org/show_bug.cgi?id=26857
+ */
+ global $wgHooks, $IP;
+ require( "$IP/includes/DefaultSettings.php" );
foreach( $exts as $e ) {
require( "$path/$e/$e.php" );
array_unshift( $this->installSteps,
array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) )
);
+ $this->installSteps[] = array(
+ 'name' => 'extension-tables',
+ 'callback' => array( $installer, 'createExtensionTables' )
+ );
}
return $this->installSteps;
}