From 3ee7eee36015ce6b47c6695e66eaa54a9dcfd29a Mon Sep 17 00:00:00 2001 From: stibba Date: Mon, 29 Oct 2018 22:18:29 +0100 Subject: [PATCH] Use new ScopedCallback::newScopedIgnoreUserAbort helper function Introduced in Ib6e307d76f93. This patch updates FileBackend, LoadBalancer and LBFactory to use a public function newScopedIgnoreUserAbort in ScopedCallback instead of all using the exact same function but duplicated. Bug: T184044 Change-Id: I27d7dc16abfe4b9447d7f3d8bd89f0de3ddeb662 --- includes/libs/filebackend/FileBackend.php | 30 ++++--------------- includes/libs/rdbms/lbfactory/LBFactory.php | 19 +----------- .../libs/rdbms/loadbalancer/LoadBalancer.php | 19 +----------- 3 files changed, 8 insertions(+), 60 deletions(-) diff --git a/includes/libs/filebackend/FileBackend.php b/includes/libs/filebackend/FileBackend.php index 2852265cbe..27e6924476 100644 --- a/includes/libs/filebackend/FileBackend.php +++ b/includes/libs/filebackend/FileBackend.php @@ -427,7 +427,7 @@ abstract class FileBackend implements LoggerAwareInterface { } /** @noinspection PhpUnusedLocalVariableInspection */ - $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts + $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts return $this->doOperationsInternal( $ops, $opts ); } @@ -665,7 +665,7 @@ abstract class FileBackend implements LoggerAwareInterface { } /** @noinspection PhpUnusedLocalVariableInspection */ - $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts + $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts return $this->doQuickOperationsInternal( $ops ); } @@ -812,7 +812,7 @@ abstract class FileBackend implements LoggerAwareInterface { return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly ); } /** @noinspection PhpUnusedLocalVariableInspection */ - $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts + $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts return $this->doPrepare( $params ); } @@ -843,7 +843,7 @@ abstract class FileBackend implements LoggerAwareInterface { return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly ); } /** @noinspection PhpUnusedLocalVariableInspection */ - $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts + $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts return $this->doSecure( $params ); } @@ -876,7 +876,7 @@ abstract class FileBackend implements LoggerAwareInterface { return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly ); } /** @noinspection PhpUnusedLocalVariableInspection */ - $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts + $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts return $this->doPublish( $params ); } @@ -902,7 +902,7 @@ abstract class FileBackend implements LoggerAwareInterface { return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly ); } /** @noinspection PhpUnusedLocalVariableInspection */ - $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts + $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts return $this->doClean( $params ); } @@ -912,24 +912,6 @@ abstract class FileBackend implements LoggerAwareInterface { */ abstract protected function doClean( array $params ); - /** - * Enter file operation scope. - * This just makes PHP ignore user aborts/disconnects until the return - * value leaves scope. This returns null and does nothing in CLI mode. - * - * @return ScopedCallback|null - */ - final protected function getScopedPHPBehaviorForOps() { - if ( PHP_SAPI != 'cli' ) { // https://bugs.php.net/bug.php?id=47540 - $old = ignore_user_abort( true ); // avoid half-finished operations - return new ScopedCallback( function () use ( $old ) { - ignore_user_abort( $old ); - } ); - } - - return null; - } - /** * Check if a file exists at a storage path in the backend. * This returns false if only a directory exists at the path. diff --git a/includes/libs/rdbms/lbfactory/LBFactory.php b/includes/libs/rdbms/lbfactory/LBFactory.php index 1612f41dca..d213dc9e80 100644 --- a/includes/libs/rdbms/lbfactory/LBFactory.php +++ b/includes/libs/rdbms/lbfactory/LBFactory.php @@ -257,7 +257,7 @@ abstract class LBFactory implements ILBFactory { ); } /** @noinspection PhpUnusedLocalVariableInspection */ - $scope = $this->getScopedPHPBehaviorForCommit(); // try to ignore client aborts + $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts // Run pre-commit callbacks and suppress post-commit callbacks, aborting on failure do { $count = 0; // number of callbacks executed this iteration @@ -707,23 +707,6 @@ abstract class LBFactory implements ILBFactory { } } - /** - * Make PHP ignore user aborts/disconnects until the returned - * value leaves scope. This returns null and does nothing in CLI mode. - * - * @return ScopedCallback|null - */ - final protected function getScopedPHPBehaviorForCommit() { - if ( PHP_SAPI != 'cli' ) { // https://bugs.php.net/bug.php?id=47540 - $old = ignore_user_abort( true ); // avoid half-finished operations - return new ScopedCallback( function () use ( $old ) { - ignore_user_abort( $old ); - } ); - } - - return null; - } - function __destruct() { $this->destroy(); } diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index b2b23917e1..7721707a54 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -1395,7 +1395,7 @@ class LoadBalancer implements ILoadBalancer { $failures = []; /** @noinspection PhpUnusedLocalVariableInspection */ - $scope = $this->getScopedPHPBehaviorForCommit(); // try to ignore client aborts + $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts $restore = ( $this->trxRoundId !== false ); $this->trxRoundId = false; @@ -1960,23 +1960,6 @@ class LoadBalancer implements ILoadBalancer { } } - /** - * Make PHP ignore user aborts/disconnects until the returned - * value leaves scope. This returns null and does nothing in CLI mode. - * - * @return ScopedCallback|null - */ - final protected function getScopedPHPBehaviorForCommit() { - if ( PHP_SAPI != 'cli' ) { // https://bugs.php.net/bug.php?id=47540 - $old = ignore_user_abort( true ); // avoid half-finished operations - return new ScopedCallback( function () use ( $old ) { - ignore_user_abort( $old ); - } ); - } - - return null; - } - function __destruct() { // Avoid connection leaks for sanity $this->disable(); -- 2.20.1