27use Wikimedia\Timestamp\ConvertibleTimestamp;
44 parent::__construct( $config );
46 $this->domain = $config[
'domain'] ?? $config[
'wiki'];
56 $status = StatusValue::newGood();
61 return $status->fatal(
'filejournal-fail-dbconnect', $this->backend );
64 $now = ConvertibleTimestamp::time();
67 foreach ( $entries as $entry ) {
69 'fj_batch_uuid' => $batchId,
71 'fj_op' => $entry[
'op'],
72 'fj_path' => $entry[
'path'],
73 'fj_new_sha1' => $entry[
'newSha1'],
74 'fj_timestamp' => $dbw->timestamp( $now )
79 $dbw->insert(
'filejournal', $data, __METHOD__ );
82 if ( mt_rand( 0, 99 ) == 0 ) {
87 return $status->fatal(
'filejournal-fail-dbquery', $this->backend );
100 return $dbw->selectField(
'filejournal',
'MAX(fj_id)',
101 [
'fj_backend' => $this->backend ],
114 $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $time ) );
116 return $dbw->selectField(
'filejournal',
'fj_id',
117 [
'fj_backend' => $this->backend,
"fj_timestamp <= $encTimestamp" ],
119 [
'ORDER BY' =>
'fj_timestamp DESC' ]
132 $res = $dbw->select(
'filejournal',
'*',
134 'fj_backend' => $this->backend,
135 'fj_id >= ' . $dbw->addQuotes( (
int)$start ) ],
137 array_merge( [
'ORDER BY' =>
'fj_id ASC' ],
138 $limit ? [
'LIMIT' => $limit ] : [] )
142 foreach (
$res as $row ) {
144 foreach ( (array)$row as $key => $value ) {
145 $item[substr( $key, 3 )] = $value;
159 $status = StatusValue::newGood();
160 if ( $this->ttlDays <= 0 ) {
165 $dbCutoff = $dbw->timestamp( ConvertibleTimestamp::time() - 86400 * $this->ttlDays );
167 $dbw->delete(
'filejournal',
168 [
'fj_timestamp < ' . $dbw->addQuotes( $dbCutoff ) ],
183 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
185 return $lb->getConnectionRef(
DB_PRIMARY, [], $this->domain, $lb::CONN_TRX_AUTOCOMMIT );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Version of FileJournal that logs to a DB table.
doGetChangeEntries( $start, $limit)
getMasterDB()
Get a primary connection to the logging DB.
doLogChangeBatch(array $entries, $batchId)
doGetPositionAtTime( $time)
getPrimaryDB()
Get a primary connection to the logging DB.
__construct(array $config)
Construct a new instance from configuration.
Class for handling file operation journaling.
purgeOldLogs()
Purge any old log entries.