aboutsummaryrefslogtreecommitdiffstats
path: root/includes/filebackend/FSFileBackend.php
diff options
context:
space:
mode:
authorAaron Schulz <aschulz@wikimedia.org>2014-06-12 13:40:03 -0700
committerAaron Schulz <aschulz@wikimedia.org>2014-06-12 13:40:03 -0700
commitc36eb818f8cbd21d42153a5afbb216626ac006ee (patch)
treeebc180996072c2a18cab87e012eb150605e92131 /includes/filebackend/FSFileBackend.php
parent0f787e74f6e66a16ef4bc23937ee7ec647f4ab8b (diff)
downloadmediawikicore-c36eb818f8cbd21d42153a5afbb216626ac006ee.tar.gz
mediawikicore-c36eb818f8cbd21d42153a5afbb216626ac006ee.zip
Made FSFileBackend use closures for doExecuteOpHandlesInternal()
Change-Id: I8401a92384cb454eb79a4607b350c50d432a9510
Diffstat (limited to 'includes/filebackend/FSFileBackend.php')
-rw-r--r--includes/filebackend/FSFileBackend.php94
1 files changed, 37 insertions, 57 deletions
diff --git a/includes/filebackend/FSFileBackend.php b/includes/filebackend/FSFileBackend.php
index 9586657493d0..8a2dc4a016d9 100644
--- a/includes/filebackend/FSFileBackend.php
+++ b/includes/filebackend/FSFileBackend.php
@@ -213,7 +213,13 @@ class FSFileBackend extends FileBackendStore {
wfEscapeShellArg( $this->cleanPathSlashes( $tempFile->getPath() ) ),
wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
) );
- $status->value = new FSFileOpHandle( $this, $params, 'Create', $cmd, $dest );
+ $handler = function( $errors, Status $status, array $params, $cmd ) {
+ if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
+ $status->fatal( 'backend-fail-create', $params['dst'] );
+ trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
+ }
+ };
+ $status->value = new FSFileOpHandle( $this, $params, $handler, $cmd, $dest );
$tempFile->bind( $status->value );
} else { // immediate write
$this->trapWarnings();
@@ -230,16 +236,6 @@ class FSFileBackend extends FileBackendStore {
return $status;
}
- /**
- * @see FSFileBackend::doExecuteOpHandlesInternal()
- */
- protected function getResponseCreate( $errors, Status $status, array $params, $cmd ) {
- if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
- $status->fatal( 'backend-fail-create', $params['dst'] );
- trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
- }
- }
-
protected function doStoreInternal( array $params ) {
$status = Status::newGood();
@@ -256,7 +252,13 @@ class FSFileBackend extends FileBackendStore {
wfEscapeShellArg( $this->cleanPathSlashes( $params['src'] ) ),
wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
) );
- $status->value = new FSFileOpHandle( $this, $params, 'Store', $cmd, $dest );
+ $handler = function( $errors, Status $status, array $params, $cmd ) {
+ if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
+ $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
+ trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
+ }
+ };
+ $status->value = new FSFileOpHandle( $this, $params, $handler, $cmd, $dest );
} else { // immediate write
$this->trapWarnings();
$ok = copy( $params['src'], $dest );
@@ -277,16 +279,6 @@ class FSFileBackend extends FileBackendStore {
return $status;
}
- /**
- * @see FSFileBackend::doExecuteOpHandlesInternal()
- */
- protected function getResponseStore( $errors, Status $status, array $params, $cmd ) {
- if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
- $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
- trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
- }
- }
-
protected function doCopyInternal( array $params ) {
$status = Status::newGood();
@@ -318,7 +310,13 @@ class FSFileBackend extends FileBackendStore {
wfEscapeShellArg( $this->cleanPathSlashes( $source ) ),
wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
) );
- $status->value = new FSFileOpHandle( $this, $params, 'Copy', $cmd, $dest );
+ $handler = function( $errors, Status $status, array $params, $cmd ) {
+ if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
+ $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
+ trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
+ }
+ };
+ $status->value = new FSFileOpHandle( $this, $params, $handler, $cmd, $dest );
} else { // immediate write
$this->trapWarnings();
$ok = ( $source === $dest ) ? true : copy( $source, $dest );
@@ -341,16 +339,6 @@ class FSFileBackend extends FileBackendStore {
return $status;
}
- /**
- * @see FSFileBackend::doExecuteOpHandlesInternal()
- */
- protected function getResponseCopy( $errors, Status $status, array $params, $cmd ) {
- if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
- $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
- trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
- }
- }
-
protected function doMoveInternal( array $params ) {
$status = Status::newGood();
@@ -382,7 +370,13 @@ class FSFileBackend extends FileBackendStore {
wfEscapeShellArg( $this->cleanPathSlashes( $source ) ),
wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
) );
- $status->value = new FSFileOpHandle( $this, $params, 'Move', $cmd );
+ $handler = function( $errors, Status $status, array $params, $cmd ) {
+ if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
+ $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
+ trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
+ }
+ };
+ $status->value = new FSFileOpHandle( $this, $params, $handler, $cmd );
} else { // immediate write
$this->trapWarnings();
$ok = ( $source === $dest ) ? true : rename( $source, $dest );
@@ -398,16 +392,6 @@ class FSFileBackend extends FileBackendStore {
return $status;
}
- /**
- * @see FSFileBackend::doExecuteOpHandlesInternal()
- */
- protected function getResponseMove( $errors, Status $status, array $params, $cmd ) {
- if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
- $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
- trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
- }
- }
-
protected function doDeleteInternal( array $params ) {
$status = Status::newGood();
@@ -431,7 +415,13 @@ class FSFileBackend extends FileBackendStore {
wfIsWindows() ? 'DEL' : 'unlink',
wfEscapeShellArg( $this->cleanPathSlashes( $source ) )
) );
- $status->value = new FSFileOpHandle( $this, $params, 'Copy', $cmd );
+ $handler = function( $errors, Status $status, array $params, $cmd ) {
+ if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
+ $status->fatal( 'backend-fail-delete', $params['src'] );
+ trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
+ }
+ };
+ $status->value = new FSFileOpHandle( $this, $params, $handler, $cmd );
} else { // immediate write
$this->trapWarnings();
$ok = unlink( $source );
@@ -447,16 +437,6 @@ class FSFileBackend extends FileBackendStore {
}
/**
- * @see FSFileBackend::doExecuteOpHandlesInternal()
- */
- protected function getResponseDelete( $errors, Status $status, array $params, $cmd ) {
- if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
- $status->fatal( 'backend-fail-delete', $params['src'] );
- trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
- }
- }
-
- /**
* @param string $fullCont
* @param string $dirRel
* @param array $params
@@ -716,8 +696,8 @@ class FSFileBackend extends FileBackendStore {
foreach ( $fileOpHandles as $index => $fileOpHandle ) {
$status = Status::newGood();
- $function = 'getResponse' . $fileOpHandle->call;
- $this->$function( $errs[$index], $status, $fileOpHandle->params, $fileOpHandle->cmd );
+ $function = $fileOpHandle->call;
+ $function( $errs[$index], $status, $fileOpHandle->params, $fileOpHandle->cmd );
$statuses[$index] = $status;
if ( $status->isOK() && $fileOpHandle->chmodPath ) {
$this->chmod( $fileOpHandle->chmodPath );