X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fdb%2FIDatabase.php;h=41b131f40ba166c1fbf2ee008f63fbc5c74a5fee;hp=0a71df2312e5e4a931de4aa85d6281104af68310;hb=708c02281e6e8880ae2cebbda7f353ce97841f94;hpb=55e23b7c48a1b8bb7423c899208239d5ae9a5a75 diff --git a/includes/db/IDatabase.php b/includes/db/IDatabase.php index 0a71df2312..41b131f40b 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. @@ -1216,7 +1221,30 @@ interface IDatabase { public function getMasterPos(); /** - * Run an anonymous function as soon as there is no transaction pending. + * @return bool Whether the DB is marked as read-only server-side + * @since 1.28 + */ + public function serverIsReadOnly(); + + /** + * Run a callback 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 a callback as soon as there is no transaction pending. * If there is a transaction and it is rolled back, then the callback is cancelled. * Queries in the function will run in AUTO-COMMIT mode unless there are begin() calls. * Callbacks must commit any transactions that they begin. @@ -1228,15 +1256,19 @@ 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. + * Run a callback before the current transaction commits or now if there is none. * If there is a transaction and it is rolled back, then the callback is cancelled. - * Callbacks must not start nor commit any transactions. + * Callbacks must not start nor commit any transactions. If no transaction is active, + * then a transaction will wrap the callback. * * This is useful for updates that easily cause deadlocks if locks are held too long * but where atomicity is strongly desired for these updates and some related updates. @@ -1246,7 +1278,7 @@ interface IDatabase { * @param callable $callback * @since 1.22 */ - public function onTransactionPreCommitOrIdle( $callback ); + public function onTransactionPreCommitOrIdle( callable $callback ); /** * Begin an atomic section of statements