'Article' => __DIR__ . '/includes/page/Article.php',
'AssembleUploadChunksJob' => __DIR__ . '/includes/jobqueue/jobs/AssembleUploadChunksJob.php',
'AtomFeed' => __DIR__ . '/includes/Feed.php',
+ 'AtomicSectionUpdate' => __DIR__ . '/includes/deferred/AtomicSectionUpdate.php',
'AttachLatest' => __DIR__ . '/maintenance/attachLatest.php',
'AuthPlugin' => __DIR__ . '/includes/AuthPlugin.php',
'AuthPluginUser' => __DIR__ . '/includes/AuthPlugin.php',
return;
}
- $method = __METHOD__;
- $dbw = wfGetDB( DB_MASTER );
- $dbw->onTransactionIdle( function () use ( $dbw, $method ) {
- $dbw->delete( 'ipblocks',
- array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), $method );
- } );
+ DeferredUpdates::addUpdate( new AtomicSectionUpdate(
+ wfGetDB( DB_MASTER ),
+ __METHOD__,
+ function ( IDatabase $dbw, $fname ) {
+ $dbw->delete(
+ 'ipblocks',
+ array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
+ $fname
+ );
+ }
+ ) );
}
/**
return;
}
- $method = __METHOD__;
- $dbw = wfGetDB( DB_MASTER );
- $dbw->onTransactionIdle( function () use ( $dbw, $method ) {
- $dbw->delete(
- 'page_restrictions',
- array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
- $method
- );
- $dbw->delete(
- 'protected_titles',
- array( 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
- $method
- );
- } );
+ DeferredUpdates::addUpdate( new AtomicSectionUpdate(
+ wfGetDB( DB_MASTER ),
+ __METHOD__,
+ function ( IDatabase $dbw, $fname ) {
+ $dbw->delete(
+ 'page_restrictions',
+ array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
+ $fname
+ );
+ $dbw->delete(
+ 'protected_titles',
+ array( 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
+ $fname
+ );
+ }
+ ) );
}
/**
--- /dev/null
+<?php
+
+/**
+ * Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
+ * @since 1.27
+ */
+class AtomicSectionUpdate implements DeferrableUpdate {
+ /** @var IDatabase */
+ private $dbw;
+ /** @var string */
+ private $fname;
+ /** @var Closure|callable */
+ private $callback;
+
+ /**
+ * @param IDatabase $dbw
+ * @param string $fname Caller name (usually __METHOD__)
+ * @param callable $callback
+ * @throws InvalidArgumentException
+ * @see IDatabase::doAtomicSection()
+ */
+ public function __construct( IDatabase $dbw, $fname, $callback ) {
+ $this->dbw = $dbw;
+ $this->fname = $fname;
+ if ( !is_callable( $callback ) ) {
+ throw new InvalidArgumentException( 'Not a valid callback/closure!' );
+ }
+ $this->callback = $callback;
+ }
+
+ public function doUpdate() {
+ $this->dbw->doAtomicSection( $this->fname, $this->callback );
+ }
+}