X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fdb%2FIDatabase.php;h=c024632edfbc7b4066b37f87926b41525f277d49;hb=144245268ddce82b3734281fd1a3fbc09793209e;hp=710efb2ca60b96dd66b0036b816cbf06ff8ceb0a;hpb=eb7c38328bbf76a3317323c03b97b2ab2f047801;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/IDatabase.php b/includes/db/IDatabase.php index 710efb2ca6..c024632edf 100644 --- a/includes/db/IDatabase.php +++ b/includes/db/IDatabase.php @@ -33,6 +33,11 @@ * @ingroup Database */ interface IDatabase { + /* Constants to onTransactionResolution() callbacks */ + const TRIGGER_IDLE = 1; + const TRIGGER_COMMIT = 2; + const TRIGGER_ROLLBACK = 3; + /** * A string describing the current software version, and possibly * other details in a user-friendly way. Will be listed on Special:Version, etc. @@ -1215,6 +1220,23 @@ interface IDatabase { */ public function getMasterPos(); + /** + * Run an anonymous function as soon as the current transaction commits or rolls back. + * An error is thrown if no transaction is pending. Queries in the function will run in + * AUTO-COMMIT mode unless there are begin() calls. Callbacks must commit any transactions + * that they begin. + * + * This is useful for combining cooperative locks and DB transactions. + * + * The callback takes one argument: + * How the transaction ended (IDatabase::TRIGGER_COMMIT or IDatabase::TRIGGER_ROLLBACK) + * + * @param callable $callback + * @return mixed + * @since 1.28 + */ + public function onTransactionResolution( callable $callback ); + /** * Run an anonymous function as soon as there is no transaction pending. * If there is a transaction and it is rolled back, then the callback is cancelled. @@ -1228,10 +1250,13 @@ interface IDatabase { * * Updates will execute in the order they were enqueued. * + * The callback takes one argument: + * How the transaction ended (IDatabase::TRIGGER_COMMIT or IDatabase::TRIGGER_IDLE) + * * @param callable $callback * @since 1.20 */ - public function onTransactionIdle( $callback ); + public function onTransactionIdle( callable $callback ); /** * Run an anonymous function before the current transaction commits or now if there is none. @@ -1246,7 +1271,7 @@ interface IDatabase { * @param callable $callback * @since 1.22 */ - public function onTransactionPreCommitOrIdle( $callback ); + public function onTransactionPreCommitOrIdle( callable $callback ); /** * Begin an atomic section of statements @@ -1313,7 +1338,7 @@ interface IDatabase { * @throws UnexpectedValueException * @since 1.27 */ - public function doAtomicSection( $fname, $callback ); + public function doAtomicSection( $fname, callable $callback ); /** * Begin a transaction. If a transaction is already in progress,