| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Maintenance; |
| 4 |
|
| 5 |
use Wikimedia\Rdbms\IDatabase; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class UndoLog { |
| 12 |
|
| 13 |
private $file; |
| 14 |
|
| 15 |
private $dbw; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function __construct( $fileName, IDatabase $dbw ) { |
| 22 |
if ( $fileName !== null ) { |
| 23 |
$this->file = fopen( $fileName, 'a' ); |
| 24 |
if ( !$this->file ) { |
| 25 |
throw new \RuntimeException( 'Unable to open undo log' ); |
| 26 |
} |
| 27 |
} |
| 28 |
$this->dbw = $dbw; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function update( $table, array $newValues, array $oldValues, $fname ) { |
| 39 |
$this->dbw->newUpdateQueryBuilder() |
| 40 |
->update( $table ) |
| 41 |
->set( $newValues ) |
| 42 |
->where( $oldValues ) |
| 43 |
->caller( $fname )->execute(); |
| 44 |
|
| 45 |
$updated = (bool)$this->dbw->affectedRows(); |
| 46 |
if ( $this->file && $updated ) { |
| 47 |
$table = $this->dbw->tableName( $table ); |
| 48 |
fwrite( |
| 49 |
$this->file, |
| 50 |
"UPDATE $table" . |
| 51 |
' SET ' . $this->dbw->makeList( $oldValues, IDatabase::LIST_SET ) . |
| 52 |
' WHERE ' . $this->dbw->makeList( $newValues, IDatabase::LIST_AND ) . ";\n" |
| 53 |
); |
| 54 |
} |
| 55 |
return $updated; |
| 56 |
} |
| 57 |
} |