/** * Migrates user options from the user table blob to user_properties */ protected function doMigrateUserOptions() { if ( $this->db->tableExists( 'user_properties' ) ) { $cl = $this->maintenance->runChild( 'ConvertUserOptions', 'convertUserOptions.php' ); $cl->execute(); $this->output( "done.\n" ); } }
/** * Determine whether an existing installation of MediaWiki is present in * the configured administrative connection. Returns true if there is * such a wiki, false if the database doesn't exist. * * Traditionally, this is done by testing for the existence of either * the revision table or the cur table. * * @return Boolean */ public function needsUpgrade() { $status = $this->getConnection(); if (!$status->isOK()) { return false; } if (!$this->db->selectDB($this->getVar('wgDBname'))) { return false; } return $this->db->tableExists('cur', __METHOD__) || $this->db->tableExists('revision', __METHOD__); }
/** * Modify an existing field * * @param $table String: name of the table to which the field belongs * @param $field String: name of the field to modify * @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)) { $this->output("...{$table} table does not exist, skipping modify field patch\n"); } elseif (!$this->db->fieldExists($table, $field)) { $this->output("...{$field} field does not exist in {$table} table, skipping modify field patch\n"); } else { $this->output("Modifying {$field} field of table {$table}..."); $this->applyPatch($patch, $fullpath); $this->output("ok\n"); } }
/** * Modify an existing field * * @param $table String: name of the table to which the field belongs * @param $field String: name of the field to modify * @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) { $updateKey = "{$table}-{$field}-{$patch}"; if (!$this->db->tableExists($table, __METHOD__)) { $this->output("...{$table} table does not exist, skipping modify field patch.\n"); } elseif (!$this->db->fieldExists($table, $field, __METHOD__)) { $this->output("...{$field} field does not exist in {$table} table, skipping modify field patch.\n"); } elseif ($this->updateRowExists($updateKey)) { $this->output("...{$field} in table {$table} already modified by patch {$patch}.\n"); } else { $this->applyPatch($patch, $fullpath, "Modifying {$field} field of table {$table}"); $this->insertUpdateRow($updateKey); } }
/** * @param DatabaseBase $dbw * @param string $table * @param string $column * @param string $wiki */ function doDeletes($dbw, $table, $column, $wiki) { if (!$dbw->tableExists($table)) { $this->error("Maintenance script cannot be run on this wiki as there is no {$table} table", 1); } $this->output("{$table}:\n"); $count = 0; do { $wikiQuoted = $dbw->addQuotes($wiki); $dbw->query("DELETE FROM {$table} WHERE {$column}={$wikiQuoted} LIMIT 500", __METHOD__); $affected = $dbw->affectedRows(); $count += $affected; $this->output("{$count}\n"); wfWaitForSlaves(); } while ($affected === 500); $this->output("{$count} {$table} rows deleted\n"); }
/** * Enable profiling table when it's turned on */ protected function doEnableProfiling() { global $wgProfiler; if (!$this->doTable('profiling')) { return true; } $profileToDb = false; if (isset($wgProfiler['output'])) { $out = $wgProfiler['output']; if ($out === 'db') { $profileToDb = true; } elseif (is_array($out) && in_array('db', $out)) { $profileToDb = true; } } if ($profileToDb && !$this->db->tableExists('profiling', __METHOD__)) { $this->applyPatch('patch-profiling.sql', false, 'Add profiling table'); } }
/** * @param DatabaseBase $dbw * @param string $table * @param string $column * @param string $wiki */ function doDeletes($dbw, $table, $column, $wiki) { if (!$dbw->tableExists($table)) { $this->error("Maintenance script cannot be run on this wiki as there is no {$table} table", 1); } $this->output("{$table}:\n"); $count = 0; do { // https://bugzilla.wikimedia.org/show_bug.cgi?id=52868 //$dbw->delete( // $table, // array( $column => $wiki ), // __METHOD__, // array( 'LIMIT' => 500 ), //); $wikiQuoted = $dbw->addQuotes($wiki); $dbw->query("DELETE FROM {$table} WHERE {$column}={$wikiQuoted} LIMIT 500", __METHOD__); $affected = $dbw->affectedRows(); $count += $affected; $this->output("{$count}\n"); wfWaitForSlaves(); } while ($affected === 500); $this->output("{$count} {$table} rows deleted\n"); }
function execute() { $this->dbw = wfGetDB(DB_MASTER); $logging = $this->dbw->tableName('logging'); $logging_1_10 = $this->dbw->tableName('logging_1_10'); $logging_pre_1_10 = $this->dbw->tableName('logging_pre_1_10'); if ($this->dbw->tableExists('logging_pre_1_10') && !$this->dbw->tableExists('logging')) { # Fix previous aborted run echo "Cleaning up from previous aborted run\n"; $this->dbw->query("RENAME TABLE {$logging_pre_1_10} TO {$logging}", __METHOD__); } if ($this->dbw->tableExists('logging_pre_1_10')) { echo "This script has already been run to completion\n"; return; } # Create the target table if (!$this->dbw->tableExists('logging_1_10')) { global $wgDBTableOptions; $sql = <<<EOT CREATE TABLE {$logging_1_10} ( -- Log ID, for referring to this specific log entry, probably for deletion and such. log_id int unsigned NOT NULL auto_increment, -- Symbolic keys for the general log type and the action type -- within the log. The output format will be controlled by the -- action field, but only the type controls categorization. log_type varbinary(10) NOT NULL default '', log_action varbinary(10) NOT NULL default '', -- Timestamp. Duh. log_timestamp binary(14) NOT NULL default '19700101000000', -- The user who performed this action; key to user_id log_user int unsigned NOT NULL default 0, -- Key to the page affected. Where a user is the target, -- this will point to the user page. log_namespace int NOT NULL default 0, log_title varchar(255) binary NOT NULL default '', -- Freeform text. Interpreted as edit history comments. log_comment varchar(255) NOT NULL default '', -- LF separated list of miscellaneous parameters log_params blob NOT NULL, -- rev_deleted for logs log_deleted tinyint unsigned NOT NULL default '0', PRIMARY KEY log_id (log_id), KEY type_time (log_type, log_timestamp), KEY user_time (log_user, log_timestamp), KEY page_time (log_namespace, log_title, log_timestamp), KEY times (log_timestamp) ) {$wgDBTableOptions} EOT; echo "Creating table logging_1_10\n"; $this->dbw->query($sql, __METHOD__); } # Synchronise the tables echo "Doing initial sync...\n"; $this->sync('logging', 'logging_1_10'); echo "Sync done\n\n"; # Rename the old table away echo "Renaming the old table to {$logging_pre_1_10}\n"; $this->dbw->query("RENAME TABLE {$logging} TO {$logging_pre_1_10}", __METHOD__); # Copy remaining old rows # Done before the new table is active so that $copyPos is accurate echo "Doing final sync...\n"; $this->sync('logging_pre_1_10', 'logging_1_10'); # Move the new table in echo "Moving the new table in...\n"; $this->dbw->query("RENAME TABLE {$logging_1_10} TO {$logging}", __METHOD__); echo "Finished.\n"; }
public function testUnknownTableCorruptsResults() { $res = $this->db->select('page', '*', array('page_id' => 1)); $this->assertFalse($this->db->tableExists('foobarbaz')); $this->assertInternalType('int', $res->numRows()); }