ce820ff18b952282905ae66b0f891eebe5b9f620
3 * Class for handling database updates. Roughly based off of updaters.inc, with
4 * a few improvements :)
9 // Array of updates to perform on the database
10 protected $updates = array();
13 protected $db, $updater;
15 public function __construct( $db ) {
17 switch( $this->db
->getType() ) {
19 $this->updater
= new MysqlUpdaters();
22 $this->updater
= new SqliteUpdaters();
25 throw new MWException( __METHOD__
. ' called for unsupported $wgDBtype' );
29 public function doUpdates() {
31 require_once( "$IP/maintenance/updaters.inc" );
33 foreach ( $this->updates
as $version => $updates ) {
34 foreach( $updates as $params ) {
35 $func = array_shift( $params );
36 call_user_func_array( $func, $params );
39 $this->setAppliedUpdates( $version, $updates );
43 protected function loadUpdates() {
44 foreach( $this->updater
->getUpdates() as $version => $updates ) {
45 $appliedUpdates = $this->getAppliedUpdates( $version );
46 if( !$appliedUpdates ||
count( $appliedUpdates ) != count( $updates ) ) {
47 $this->updates
[ $version ] = $updates;
52 private function getAppliedUpdates( $version ) {
53 $key = "updatelist-$version";
54 $val = $this->db
->selectField( 'updatelog', 'ul_value',
55 array( 'ul_key' => $key ), __METHOD__
);
59 return unserialize( $val );
63 private function setAppliedUpdates( $version, $updates = array() ) {
64 $key = "updatelist-$version";
65 $this->db
->delete( 'updatelog', array( 'ul_key' => $key ), __METHOD__
);
66 $this->db
->insert( 'updatelog',
67 array( 'ul_key' => $key, 'ul_value' => serialize( $updates ) ),