MediaWiki master
UndoLog.php
Go to the documentation of this file.
1<?php
2
4
6
11class UndoLog {
12 private $file;
13 private $dbw;
14
19 public function __construct( $fileName, IDatabase $dbw ) {
20 if ( $fileName !== null ) {
21 $this->file = fopen( $fileName, 'a' );
22 if ( !$this->file ) {
23 throw new \RuntimeException( 'Unable to open undo log' );
24 }
25 }
26 $this->dbw = $dbw;
27 }
28
36 public function update( $table, array $newValues, array $oldValues, $fname ) {
37 $this->dbw->newUpdateQueryBuilder()
38 ->update( $table )
39 ->set( $newValues )
40 ->where( $oldValues )
41 ->caller( $fname )->execute();
42
43 $updated = (bool)$this->dbw->affectedRows();
44 if ( $this->file && $updated ) {
45 $table = $this->dbw->tableName( $table );
46 fwrite(
47 $this->file,
48 "UPDATE $table" .
49 ' SET ' . $this->dbw->makeList( $oldValues, IDatabase::LIST_SET ) .
50 ' WHERE ' . $this->dbw->makeList( $newValues, IDatabase::LIST_AND ) . ";\n"
51 );
52 }
53 return $updated;
54 }
55}
Update a database while optionally writing SQL that reverses the update to a file.
Definition UndoLog.php:11
__construct( $fileName, IDatabase $dbw)
Definition UndoLog.php:19
update( $table, array $newValues, array $oldValues, $fname)
Definition UndoLog.php:36
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:36