* @since 1.20
*/
class DBFileJournal extends FileJournal {
- /** @var DatabaseBase */
+ /** @var IDatabase */
protected $dbw;
protected $wiki = false; // string; wiki DB name
/**
* Construct a new instance from configuration.
- * $config includes:
- * 'wiki' : wiki name to use for LoadBalancer
*
- * @param $config Array
+ * @param array $config Includes:
+ * 'wiki' : wiki name to use for LoadBalancer
*/
protected function __construct( array $config ) {
parent::__construct( $config );
/**
* @see FileJournal::logChangeBatch()
+ * @param array $entries
+ * @param string $batchId
* @return Status
*/
protected function doLogChangeBatch( array $entries, $batchId ) {
$dbw = $this->getMasterDB();
} catch ( DBError $e ) {
$status->fatal( 'filejournal-fail-dbconnect', $this->backend );
+
return $status;
}
$now = wfTimestamp( TS_UNIX );
- $data = array();
+ $data = [];
foreach ( $entries as $entry ) {
- $data[] = array(
+ $data[] = [
'fj_batch_uuid' => $batchId,
'fj_backend' => $this->backend,
'fj_op' => $entry['op'],
'fj_path' => $entry['path'],
'fj_new_sha1' => $entry['newSha1'],
'fj_timestamp' => $dbw->timestamp( $now )
- );
+ ];
}
try {
}
} catch ( DBError $e ) {
$status->fatal( 'filejournal-fail-dbquery', $this->backend );
+
return $status;
}
/**
* @see FileJournal::doGetCurrentPosition()
- * @return integer|false
+ * @return bool|mixed The value from the field, or false on failure.
*/
protected function doGetCurrentPosition() {
$dbw = $this->getMasterDB();
return $dbw->selectField( 'filejournal', 'MAX(fj_id)',
- array( 'fj_backend' => $this->backend ),
+ [ 'fj_backend' => $this->backend ],
__METHOD__
);
}
/**
* @see FileJournal::doGetPositionAtTime()
- * @param $time integer|string timestamp
- * @return integer|false
+ * @param int|string $time Timestamp
+ * @return bool|mixed The value from the field, or false on failure.
*/
protected function doGetPositionAtTime( $time ) {
$dbw = $this->getMasterDB();
$encTimestamp = $dbw->addQuotes( $dbw->timestamp( $time ) );
+
return $dbw->selectField( 'filejournal', 'fj_id',
- array( 'fj_backend' => $this->backend, "fj_timestamp <= $encTimestamp" ),
+ [ 'fj_backend' => $this->backend, "fj_timestamp <= $encTimestamp" ],
__METHOD__,
- array( 'ORDER BY' => 'fj_timestamp DESC' )
+ [ 'ORDER BY' => 'fj_timestamp DESC' ]
);
}
/**
* @see FileJournal::doGetChangeEntries()
- * @return Array
- * @throws DBError
+ * @param int $start
+ * @param int $limit
+ * @return array
*/
protected function doGetChangeEntries( $start, $limit ) {
$dbw = $this->getMasterDB();
$res = $dbw->select( 'filejournal', '*',
- array(
+ [
'fj_backend' => $this->backend,
- 'fj_id >= ' . $dbw->addQuotes( (int)$start ) ), // $start may be 0
+ 'fj_id >= ' . $dbw->addQuotes( (int)$start ) ], // $start may be 0
__METHOD__,
- array_merge( array( 'ORDER BY' => 'fj_id ASC' ),
- $limit ? array( 'LIMIT' => $limit ) : array() )
+ array_merge( [ 'ORDER BY' => 'fj_id ASC' ],
+ $limit ? [ 'LIMIT' => $limit ] : [] )
);
- $entries = array();
+ $entries = [];
foreach ( $res as $row ) {
- $item = array();
+ $item = [];
foreach ( (array)$row as $key => $value ) {
$item[substr( $key, 3 )] = $value; // "fj_op" => "op"
}
$dbCutoff = $dbw->timestamp( time() - 86400 * $this->ttlDays );
$dbw->delete( 'filejournal',
- array( 'fj_timestamp < ' . $dbw->addQuotes( $dbCutoff ) ),
+ [ 'fj_timestamp < ' . $dbw->addQuotes( $dbCutoff ) ],
__METHOD__
);
/**
* Get a master connection to the logging DB
*
- * @return DatabaseBase
+ * @return IDatabase
* @throws DBError
*/
protected function getMasterDB() {
if ( !$this->dbw ) {
// Get a separate connection in autocommit mode
$lb = wfGetLBFactory()->newMainLB();
- $this->dbw = $lb->getConnection( DB_MASTER, array(), $this->wiki );
+ $this->dbw = $lb->getConnection( DB_MASTER, [], $this->wiki );
$this->dbw->clearFlag( DBO_TRX );
}
+
return $this->dbw;
}
}