From: Bartosz DziewoƄski Date: Wed, 30 Nov 2016 19:49:31 +0000 (+0100) Subject: DatabaseUpdater: Stop inserting junk into 'updatelog' every time the updater runs X-Git-Tag: 1.31.0-rc.0~4714^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;ds=sidebyside;h=b225a84ff95badf1e407c3952e1e0c540507a8e8;p=lhc%2Fweb%2Fwiklou.git DatabaseUpdater: Stop inserting junk into 'updatelog' every time the updater runs Nothing ever looks at these rows, and if you have update.php in a Cron job or a Git hook or something, they can accumulate in huge numbers. Also remove a test which verified that the rows get inserted. If you reached this place while trying to find out what the weird "updatelist-1.28.0-14628929450" rows in your database are, rest assured they are useless. If they're causing disk space problems, you can delete them: DELETE FROM updatelog WHERE ul_key LIKE 'updatelist-%'; Change-Id: If94f243810e82ea3724cbd47b301bb96ba9a49d9 --- diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index 6a702e9fbb..6a8a99ff09 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -32,8 +32,6 @@ require_once __DIR__ . '/../../maintenance/Maintenance.php'; * @since 1.17 */ abstract class DatabaseUpdater { - protected static $updateCounter = 0; - /** * Array of updates to perform on the database * @@ -423,8 +421,6 @@ abstract class DatabaseUpdater { * @param array $what What updates to perform */ public function doUpdates( $what = [ 'core', 'extensions', 'stats' ] ) { - global $wgVersion; - $this->db->setSchemaVars( $this->getSchemaVars() ); $what = array_flip( $what ); @@ -441,12 +437,9 @@ abstract class DatabaseUpdater { $this->checkStats(); } - $this->setAppliedUpdates( $wgVersion, $this->updates ); - if ( $this->fileHandle ) { $this->skipSchema = false; $this->writeSchemaUpdateFile(); - $this->setAppliedUpdates( "$wgVersion-schema", $this->updatesSkipped ); } } @@ -482,23 +475,6 @@ abstract class DatabaseUpdater { $this->updates = array_merge( $this->updates, $updatesDone ); } - /** - * @param string $version - * @param array $updates - */ - 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', - [ 'ul_key' => $key, 'ul_value' => serialize( $updates ) ], - __METHOD__ ); - $this->db->setFlag( DBO_DDLMODE ); - } - /** * Helper function: check if the given key is present in the updatelog table. * Obviously, only use this for updates that occur after the updatelog table was diff --git a/tests/phpunit/includes/installer/DatabaseUpdaterTest.php b/tests/phpunit/includes/installer/DatabaseUpdaterTest.php deleted file mode 100644 index 2a75cf4020..0000000000 --- a/tests/phpunit/includes/installer/DatabaseUpdaterTest.php +++ /dev/null @@ -1,286 +0,0 @@ -setAppliedUpdates( "test", [] ); - $expected = "updatelist-test-" . time() . "0"; - $actual = $db->lastInsertData['ul_key']; - $this->assertEquals( $expected, $actual, var_export( $db->lastInsertData, true ) ); - $dbu->setAppliedUpdates( "test", [] ); - $expected = "updatelist-test-" . time() . "1"; - $actual = $db->lastInsertData['ul_key']; - $this->assertEquals( $expected, $actual, var_export( $db->lastInsertData, true ) ); - } -} - -class FakeDatabase extends Database { - public $lastInsertTable; - public $lastInsertData; - - function __construct() { - $this->cliMode = true; - $this->connLogger = new \Psr\Log\NullLogger(); - $this->queryLogger = new \Psr\Log\NullLogger(); - $this->errorLogger = function ( Exception $e ) { - wfWarn( get_class( $e ) . ": {$e->getMessage()}" ); - }; - $this->currentDomain = DatabaseDomain::newUnspecified(); - } - - function clearFlag( $arg, $remember = self::REMEMBER_NOTHING ) { - } - - function setFlag( $arg, $remember = self::REMEMBER_NOTHING ) { - } - - public function insert( $table, $a, $fname = __METHOD__, $options = [] ) { - $this->lastInsertTable = $table; - $this->lastInsertData = $a; - } - - /** - * Get the type of the DBMS, as it appears in $wgDBtype. - * - * @return string - */ - function getType() { - // TODO: Implement getType() method. - } - - /** - * Open a connection to the database. Usually aborts on failure - * - * @param string $server Database server host - * @param string $user Database user name - * @param string $password Database user password - * @param string $dbName Database name - * @return bool - * @throws DBConnectionError - */ - function open( $server, $user, $password, $dbName ) { - // TODO: Implement open() method. - } - - /** - * Fetch the next row from the given result object, in object form. - * Fields can be retrieved with $row->fieldname, with fields acting like - * member variables. - * If no more rows are available, false is returned. - * - * @param ResultWrapper|stdClass $res Object as returned from Database::query(), etc. - * @return stdClass|bool - * @throws DBUnexpectedError Thrown if the database returns an error - */ - function fetchObject( $res ) { - // TODO: Implement fetchObject() method. - } - - /** - * Fetch the next row from the given result object, in associative array - * form. Fields are retrieved with $row['fieldname']. - * If no more rows are available, false is returned. - * - * @param ResultWrapper $res Result object as returned from Database::query(), etc. - * @return array|bool - * @throws DBUnexpectedError Thrown if the database returns an error - */ - function fetchRow( $res ) { - // TODO: Implement fetchRow() method. - } - - /** - * Get the number of rows in a result object - * - * @param mixed $res A SQL result - * @return int - */ - function numRows( $res ) { - // TODO: Implement numRows() method. - } - - /** - * Get the number of fields in a result object - * @see https://secure.php.net/mysql_num_fields - * - * @param mixed $res A SQL result - * @return int - */ - function numFields( $res ) { - // TODO: Implement numFields() method. - } - - /** - * Get a field name in a result object - * @see https://secure.php.net/mysql_field_name - * - * @param mixed $res A SQL result - * @param int $n - * @return string - */ - function fieldName( $res, $n ) { - // TODO: Implement fieldName() method. - } - - /** - * Get the inserted value of an auto-increment row - * - * The value inserted should be fetched from nextSequenceValue() - * - * Example: - * $id = $dbw->nextSequenceValue( 'page_page_id_seq' ); - * $dbw->insert( 'page', [ 'page_id' => $id ] ); - * $id = $dbw->insertId(); - * - * @return int - */ - function insertId() { - // TODO: Implement insertId() method. - } - - /** - * Change the position of the cursor in a result object - * @see https://secure.php.net/mysql_data_seek - * - * @param mixed $res A SQL result - * @param int $row - */ - function dataSeek( $res, $row ) { - // TODO: Implement dataSeek() method. - } - - /** - * Get the last error number - * @see https://secure.php.net/mysql_errno - * - * @return int - */ - function lastErrno() { - // TODO: Implement lastErrno() method. - } - - /** - * Get a description of the last error - * @see https://secure.php.net/mysql_error - * - * @return string - */ - function lastError() { - // TODO: Implement lastError() method. - } - - /** - * mysql_fetch_field() wrapper - * Returns false if the field doesn't exist - * - * @param string $table Table name - * @param string $field Field name - * - * @return Field - */ - function fieldInfo( $table, $field ) { - // TODO: Implement fieldInfo() method. - } - - /** - * Get information about an index into an object - * @param string $table Table name - * @param string $index Index name - * @param string $fname Calling function name - * @return mixed Database-specific index description class or false if the index does not exist - */ - function indexInfo( $table, $index, $fname = __METHOD__ ) { - // TODO: Implement indexInfo() method. - } - - /** - * Get the number of rows affected by the last write query - * @see https://secure.php.net/mysql_affected_rows - * - * @return int - */ - function affectedRows() { - // TODO: Implement affectedRows() method. - } - - /** - * Wrapper for addslashes() - * - * @param string $s String to be slashed. - * @return string Slashed string. - */ - function strencode( $s ) { - // TODO: Implement strencode() method. - } - - /** - * Returns a wikitext link to the DB's website, e.g., - * return "[https://www.mysql.com/ MySQL]"; - * Should at least contain plain text, if for some reason - * your database has no website. - * - * @return string Wikitext of a link to the server software's web site - */ - function getSoftwareLink() { - // TODO: Implement getSoftwareLink() method. - } - - /** - * A string describing the current software version, like from - * mysql_get_server_info(). - * - * @return string Version information from the database server. - */ - function getServerVersion() { - // TODO: Implement getServerVersion() method. - } - - /** - * Closes underlying database connection - * @since 1.20 - * @return bool Whether connection was closed successfully - */ - protected function closeConnection() { - // TODO: Implement closeConnection() method. - } - - /** - * The DBMS-dependent part of query() - * - * @param string $sql SQL query. - * @return ResultWrapper|bool Result object to feed to fetchObject, - * fetchRow, ...; or false on failure - */ - protected function doQuery( $sql ) { - // TODO: Implement doQuery() method. - } -} - -class FakeDatabaseUpdater extends DatabaseUpdater { - function __construct( $db ) { - $this->db = $db; - self::$updateCounter = 0; - } - - /** - * Get an array of updates to perform on the database. Should return a - * multi-dimensional array. The main key is the MediaWiki version (1.12, - * 1.13...) with the values being arrays of updates, identical to how - * updaters.inc did it (for now) - * - * @return array - */ - protected function getCoreUpdateList() { - return []; - } - - public function canUseNewUpdatelog() { - return true; - } - - public function setAppliedUpdates( $version, $updates = [] ) { - parent::setAppliedUpdates( $version, $updates ); - } -}