public function areAnySuppressed() {
$bit = $this->getSuppressBit();
- // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
- for ( $this->reset(); $this->current(); $this->next() ) {
- // @codingStandardsIgnoreEnd
- $item = $this->current();
+ /** @var $item RevDelItem */
+ foreach ( $this as $item ) {
if ( $item->getBits() & $bit ) {
return true;
}
}
+
return false;
}
* @since 1.23 Added 'perItemStatus' param
*/
public function setVisibility( array $params ) {
+ $status = Status::newGood();
+
$bitPars = $params['value'];
$comment = $params['comment'];
$perItemStatus = isset( $params['perItemStatus'] ) ? $params['perItemStatus'] : false;
$dbw = wfGetDB( DB_MASTER );
$this->res = $this->doQuery( $dbw );
+ $status->merge( $this->acquireItemLocks() );
+ if ( !$status->isGood() ) {
+ return $status;
+ }
+
$dbw->startAtomic( __METHOD__ );
+ $dbw->onTransactionResolution( function () {
+ // Release locks on commit or error
+ $this->releaseItemLocks();
+ } );
- $status = Status::newGood();
$missing = array_flip( $this->ids );
$this->clearFileOps();
$idsForLog = [];
$virtualNewBits = 0;
$logType = 'delete';
- // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
- for ( $this->reset(); $this->current(); $this->next() ) {
- // @codingStandardsIgnoreEnd
- /** @var $item RevDelItem */
- $item = $this->current();
+ // Will be filled with id => [old, new bits] information and
+ // passed to doPostCommitUpdates().
+ $visibilityChangeMap = [];
+
+ /** @var $item RevDelItem */
+ foreach ( $this as $item ) {
unset( $missing[$item->getId()] );
if ( $perItemStatus ) {
} elseif ( IP::isIPAddress( $item->getAuthorName() ) ) {
$authorIPs[] = $item->getAuthorName();
}
+
+ // Save the old and new bits in $visibilityChangeMap for
+ // later use.
+ $visibilityChangeMap[$item->getId()] = [
+ 'oldBits' => $oldBits,
+ 'newBits' => $newBits,
+ ];
} else {
$itemStatus->error(
'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
}
if ( $status->successCount == 0 ) {
- $dbw->rollback( __METHOD__ );
+ $dbw->endAtomic( __METHOD__ );
return $status;
}
// Move files, if there are any
$status->merge( $this->doPreCommitUpdates() );
if ( !$status->isOK() ) {
- // Fatal error, such as no configured archive directory
- $dbw->rollback( __METHOD__ );
+ // Fatal error, such as no configured archive directory or I/O failures
+ wfGetLBFactory()->rollbackMasterChanges( __METHOD__ );
return $status;
}
]
);
- // Clear caches
- $that = $this;
- $dbw->onTransactionIdle( function() use ( $that ) {
- $that->doPostCommitUpdates();
- } );
+ // Clear caches after commit
+ DeferredUpdates::addCallableUpdate(
+ function () use ( $visibilityChangeMap ) {
+ $this->doPostCommitUpdates( $visibilityChangeMap );
+ },
+ DeferredUpdates::PRESEND,
+ $dbw
+ );
$dbw->endAtomic( __METHOD__ );
return $status;
}
+ final protected function acquireItemLocks() {
+ $status = Status::newGood();
+ /** @var $item RevDelItem */
+ foreach ( $this as $item ) {
+ $status->merge( $item->lock() );
+ }
+
+ return $status;
+ }
+
+ final protected function releaseItemLocks() {
+ $status = Status::newGood();
+ /** @var $item RevDelItem */
+ foreach ( $this as $item ) {
+ $status->merge( $item->unlock() );
+ }
+
+ return $status;
+ }
+
/**
* Reload the list data from the master DB. This can be done after setVisibility()
* to allow $item->getHTML() to show the new data.
/**
* A hook for setVisibility(): do any necessary updates post-commit.
* STUB
+ * @param array [id => ['oldBits' => $oldBits, 'newBits' => $newBits], ... ]
* @return Status
*/
- public function doPostCommitUpdates() {
+ public function doPostCommitUpdates( array $visibilityChangeMap ) {
return Status::newGood();
}