*
* @var array
*/
- protected $updates = array();
+ protected $updates = [];
/**
* Array of updates that were skipped
*
* @var array
*/
- protected $updatesSkipped = array();
+ protected $updatesSkipped = [];
/**
* List of extension-provided database updates
* @var array
*/
- protected $extensionUpdates = array();
+ protected $extensionUpdates = [];
/**
* Handle to the database subclass
protected $shared = false;
/**
- * Scripts to run after database update
+ * @var string[] Scripts to run after database update
* Should be a subclass of LoggedUpdateMaintenance
*/
- protected $postDatabaseUpdateMaintenance = array(
- 'DeleteDefaultMessages',
- 'PopulateRevisionLength',
- 'PopulateRevisionSha1',
- 'PopulateImageSha1',
- 'FixExtLinksProtocolRelative',
- 'PopulateFilearchiveSha1',
- 'PopulateBacklinkNamespace',
- 'FixDefaultJsonContentPages'
- );
+ protected $postDatabaseUpdateMaintenance = [
+ DeleteDefaultMessages::class,
+ PopulateRevisionLength::class,
+ PopulateRevisionSha1::class,
+ PopulateImageSha1::class,
+ FixExtLinksProtocolRelative::class,
+ PopulateFilearchiveSha1::class,
+ PopulateBacklinkNamespace::class,
+ FixDefaultJsonContentPages::class,
+ CleanupEmptyCategories::class,
+ ];
/**
* File handle for SQL output.
$this->maintenance->setDB( $db );
$this->initOldGlobals();
$this->loadExtensions();
- Hooks::run( 'LoadExtensionSchemaUpdates', array( $this ) );
+ Hooks::run( 'LoadExtensionSchemaUpdates', [ $this ] );
}
/**
# For extensions only, should be populated via hooks
# $wgDBtype should be checked to specifiy the proper file
- $wgExtNewTables = array(); // table, dir
- $wgExtNewFields = array(); // table, column, dir
- $wgExtPGNewFields = array(); // table, column, column attributes; for PostgreSQL
- $wgExtPGAlteredFields = array(); // table, column, new type, conversion method; for PostgreSQL
- $wgExtNewIndexes = array(); // table, index, dir
- $wgExtModifiedFields = array(); // table, index, dir
+ $wgExtNewTables = []; // table, dir
+ $wgExtNewFields = []; // table, column, dir
+ $wgExtPGNewFields = []; // table, column, column attributes; for PostgreSQL
+ $wgExtPGAlteredFields = []; // table, column, new type, conversion method; for PostgreSQL
+ $wgExtNewIndexes = []; // table, index, dir
+ $wgExtModifiedFields = []; // table, index, dir
}
/**
// This will automatically add "AutoloadClasses" to $wgAutoloadClasses
$data = $registry->readFromQueue( $queue );
- $hooks = array( 'wgHooks' => array( 'LoadExtensionSchemaUpdates' => array() ) );
+ $hooks = [ 'wgHooks' => [ 'LoadExtensionSchemaUpdates' => [] ] ];
if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
$hooks = $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'];
}
* @param string $sqlPath Full path to the schema file
*/
public function addExtensionTable( $tableName, $sqlPath ) {
- $this->extensionUpdates[] = array( 'addTable', $tableName, $sqlPath, true );
+ $this->extensionUpdates[] = [ 'addTable', $tableName, $sqlPath, true ];
}
/**
* @param string $sqlPath
*/
public function addExtensionIndex( $tableName, $indexName, $sqlPath ) {
- $this->extensionUpdates[] = array( 'addIndex', $tableName, $indexName, $sqlPath, true );
+ $this->extensionUpdates[] = [ 'addIndex', $tableName, $indexName, $sqlPath, true ];
}
/**
* @param string $sqlPath
*/
public function addExtensionField( $tableName, $columnName, $sqlPath ) {
- $this->extensionUpdates[] = array( 'addField', $tableName, $columnName, $sqlPath, true );
+ $this->extensionUpdates[] = [ 'addField', $tableName, $columnName, $sqlPath, true ];
}
/**
* @param string $sqlPath
*/
public function dropExtensionField( $tableName, $columnName, $sqlPath ) {
- $this->extensionUpdates[] = array( 'dropField', $tableName, $columnName, $sqlPath, true );
+ $this->extensionUpdates[] = [ 'dropField', $tableName, $columnName, $sqlPath, true ];
}
/**
* @param string $sqlPath The path to the SQL change path
*/
public function dropExtensionIndex( $tableName, $indexName, $sqlPath ) {
- $this->extensionUpdates[] = array( 'dropIndex', $tableName, $indexName, $sqlPath, true );
+ $this->extensionUpdates[] = [ 'dropIndex', $tableName, $indexName, $sqlPath, true ];
}
/**
* @param string $sqlPath
*/
public function dropExtensionTable( $tableName, $sqlPath ) {
- $this->extensionUpdates[] = array( 'dropTable', $tableName, $sqlPath, true );
+ $this->extensionUpdates[] = [ 'dropTable', $tableName, $sqlPath, true ];
}
/**
public function renameExtensionIndex( $tableName, $oldIndexName, $newIndexName,
$sqlPath, $skipBothIndexExistWarning = false
) {
- $this->extensionUpdates[] = array(
+ $this->extensionUpdates[] = [
'renameIndex',
$tableName,
$oldIndexName,
$skipBothIndexExistWarning,
$sqlPath,
true
- );
+ ];
}
/**
* @param string $sqlPath The path to the SQL change path
*/
public function modifyExtensionField( $tableName, $fieldName, $sqlPath ) {
- $this->extensionUpdates[] = array( 'modifyField', $tableName, $fieldName, $sqlPath, true );
+ $this->extensionUpdates[] = [ 'modifyField', $tableName, $fieldName, $sqlPath, true ];
}
/**
/**
* @since 1.17
*
- * @return array
+ * @return string[]
*/
public function getPostDatabaseUpdateMaintenance() {
return $this->postDatabaseUpdateMaintenance;
* Writes the schema updates desired to a file for the DB Admin to run.
* @param array $schemaUpdate
*/
- private function writeSchemaUpdateFile( $schemaUpdate = array() ) {
+ private function writeSchemaUpdateFile( $schemaUpdate = [] ) {
$updates = $this->updatesSkipped;
- $this->updatesSkipped = array();
+ $this->updatesSkipped = [];
foreach ( $updates as $funcList ) {
$func = $funcList[0];
*
* @param array $what What updates to perform
*/
- public function doUpdates( $what = array( 'core', 'extensions', 'stats' ) ) {
+ public function doUpdates( $what = [ 'core', 'extensions', 'stats' ] ) {
global $wgVersion;
- $this->db->begin( __METHOD__ );
$what = array_flip( $what );
$this->skipSchema = isset( $what['noschema'] ) || $this->fileHandle !== null;
if ( isset( $what['core'] ) ) {
$this->writeSchemaUpdateFile();
$this->setAppliedUpdates( "$wgVersion-schema", $this->updatesSkipped );
}
-
- $this->db->commit( __METHOD__ );
}
/**
* @param bool $passSelf Whether to pass this object we calling external functions
*/
private function runUpdates( array $updates, $passSelf ) {
- $updatesDone = array();
- $updatesSkipped = array();
+ $updatesDone = [];
+ $updatesSkipped = [];
foreach ( $updates as $params ) {
$origParams = $params;
$func = array_shift( $params );
if ( !is_array( $func ) && method_exists( $this, $func ) ) {
- $func = array( $this, $func );
+ $func = [ $this, $func ];
} elseif ( $passSelf ) {
array_unshift( $params, $this );
}
$updatesDone[] = $origParams;
wfGetLBFactory()->waitForReplication();
} else {
- $updatesSkipped[] = array( $func, $params, $origParams );
+ $updatesSkipped[] = [ $func, $params, $origParams ];
}
}
$this->updatesSkipped = array_merge( $this->updatesSkipped, $updatesSkipped );
* @param string $version
* @param array $updates
*/
- protected function setAppliedUpdates( $version, $updates = array() ) {
+ protected function setAppliedUpdates( $version, $updates = [] ) {
$this->db->clearFlag( DBO_DDLMODE );
if ( !$this->canUseNewUpdatelog() ) {
return;
$key = "updatelist-$version-" . time() . self::$updateCounter;
self::$updateCounter++;
$this->db->insert( 'updatelog',
- array( 'ul_key' => $key, 'ul_value' => serialize( $updates ) ),
+ [ 'ul_key' => $key, 'ul_value' => serialize( $updates ) ],
__METHOD__ );
$this->db->setFlag( DBO_DDLMODE );
}
'updatelog',
# Bug 65813
'1 AS X',
- array( 'ul_key' => $key ),
+ [ 'ul_key' => $key ],
__METHOD__
);
*/
public function insertUpdateRow( $key, $val = null ) {
$this->db->clearFlag( DBO_DDLMODE );
- $values = array( 'ul_key' => $key );
+ $values = [ 'ul_key' => $key ];
if ( $val && $this->canUseNewUpdatelog() ) {
$values['ul_value'] = $val;
}
global $wgExtNewFields, $wgExtNewTables, $wgExtModifiedFields,
$wgExtNewIndexes;
- $updates = array();
+ $updates = [];
foreach ( $wgExtNewTables as $tableRecord ) {
- $updates[] = array(
+ $updates[] = [
'addTable', $tableRecord[0], $tableRecord[1], true
- );
+ ];
}
foreach ( $wgExtNewFields as $fieldRecord ) {
- $updates[] = array(
+ $updates[] = [
'addField', $fieldRecord[0], $fieldRecord[1],
$fieldRecord[2], true
- );
+ ];
}
foreach ( $wgExtNewIndexes as $fieldRecord ) {
- $updates[] = array(
+ $updates[] = [
'addIndex', $fieldRecord[0], $fieldRecord[1],
$fieldRecord[2], true
- );
+ ];
}
foreach ( $wgExtModifiedFields as $fieldRecord ) {
- $updates[] = array(
+ $updates[] = [
'modifyField', $fieldRecord[0], $fieldRecord[1],
$fieldRecord[2], true
- );
+ ];
}
return $updates;
*/
public function copyFile( $filename ) {
$this->db->sourceFile( $filename, false, false, false,
- array( $this, 'appendLine' )
+ [ $this, 'appendLine' ]
);
}
public function setFileAccess() {
$repo = RepoGroup::singleton()->getLocalRepo();
$zonePath = $repo->getZonePath( 'temp' );
- if ( $repo->getBackend()->directoryExists( array( 'dir' => $zonePath ) ) ) {
+ if ( $repo->getBackend()->directoryExists( [ 'dir' => $zonePath ] ) ) {
// If the directory was never made, then it will have the right ACLs when it is made
- $status = $repo->getBackend()->secure( array(
+ $status = $repo->getBackend()->secure( [
'dir' => $zonePath,
'noAccess' => true,
'noListing' => true
- ) );
+ ] );
if ( $status->isOK() ) {
$this->output( "Set the local repo temp zone container to be private.\n" );
} else {
*/
protected function checkStats() {
$this->output( "...site_stats is populated..." );
- $row = $this->db->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
+ $row = $this->db->selectRow( 'site_stats', '*', [ 'ss_row_id' => 1 ], __METHOD__ );
if ( $row === false ) {
$this->output( "data is missing! rebuilding...\n" );
} elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
if ( $activeUsers == -1 ) {
$activeUsers = $this->db->selectField( 'recentchanges',
'COUNT( DISTINCT rc_user_text )',
- array( 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ), __METHOD__
+ [ 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ], __METHOD__
);
$this->db->update( 'site_stats',
- array( 'ss_active_users' => intval( $activeUsers ) ),
- array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 )
+ [ 'ss_active_users' => intval( $activeUsers ) ],
+ [ 'ss_row_id' => 1 ], __METHOD__, [ 'LIMIT' => 1 ]
);
}
$this->output( "...ss_active_users user count set...\n" );