9 * Version of FileJournal that logs to a DB table
12 class DBFileJournal
extends FileJournal
{
13 protected $wiki = false; // string; wiki DB name
16 * Construct a new instance from configuration.
18 * 'wiki' : wiki name to use for LoadBalancer
20 * @param $config Array
22 protected function __construct( array $config ) {
23 parent
::__construct( $config );
25 $this->wiki
= $config['wiki'];
29 * @see FileJournal::logChangeBatch()
32 protected function doLogChangeBatch( array $entries, $batchId ) {
33 $status = Status
::newGood();
35 $dbw = $this->getMasterDB();
37 $status->fatal( 'filejournal-fail-dbconnect', $this->backend
);
40 $now = wfTimestamp( TS_UNIX
);
43 foreach ( $entries as $entry ) {
45 'fj_batch_uuid' => $batchId,
46 'fj_backend' => $this->backend
,
47 'fj_op' => $entry['op'],
48 'fj_path' => $entry['path'],
49 'fj_path_sha1' => wfBaseConvert( sha1( $entry['path'] ), 16, 36, 31 ),
50 'fj_new_sha1' => $entry['newSha1'],
51 'fj_timestamp' => $dbw->timestamp( $now )
57 $dbw->insert( 'filejournal', $data, __METHOD__
);
59 } catch ( DBError
$e ) {
60 $status->fatal( 'filejournal-fail-dbquery', $this->backend
);
68 * @see FileJournal::purgeOldLogs()
71 protected function doPurgeOldLogs() {
72 $status = Status
::newGood();
73 if ( $this->ttlDays
<= 0 ) {
74 return $status; // nothing to do
77 $dbw = $this->getMasterDB();
79 $status->fatal( 'filejournal-fail-dbconnect', $this->backend
);
82 $dbCutoff = $dbw->timestamp( time() - 86400 * $this->ttlDays
);
86 $dbw->delete( 'filejournal',
87 array( 'fj_timestamp < ' . $dbw->addQuotes( $dbCutoff ) ),
91 } catch ( DBError
$e ) {
92 $status->fatal( 'filejournal-fail-dbquery', $this->backend
);
100 * Get a master connection to the logging DB
102 * @return DatabaseBase|null
104 protected function getMasterDB() {
106 $lb = wfGetLBFactory()->newMainLB();
107 return $lb->getConnection( DB_MASTER
, array(), $this->wiki
);
108 } catch ( DBConnectionError
$e ) {