Go to the documentation of this file.
23 use Psr\Log\LoggerInterface;
87 list( $required, $optional, $paths ) = $this->
allowedParams();
88 foreach ( $required as $name ) {
89 if ( isset(
$params[$name] ) ) {
90 $this->params[$name] =
$params[$name];
92 throw new InvalidArgumentException(
"File operation missing parameter '$name'." );
95 foreach ( $optional as $name ) {
96 if ( isset(
$params[$name] ) ) {
97 $this->params[$name] =
$params[$name];
100 foreach ( $paths as $name ) {
101 if ( isset( $this->params[$name] ) ) {
140 return $this->params[$name] ??
null;
158 return [
'exists' => [],
'sha1' => [] ];
167 return [
'read' => [],
'write' => [] ];
191 if ( isset( $deps[
'read'][
$path] ) || isset( $deps[
'write'][
$path] ) ) {
196 if ( isset( $deps[
'write'][
$path] ) ) {
212 if ( !$this->doOperation ) {
219 foreach ( array_unique( $pathsUsed ) as
$path ) {
223 'newSha1' => $this->
fileSha1( $path, $oPredicates )
227 if ( $nPredicates[
'sha1'][
$path] ===
false ) {
235 'op' => $this->
fileExists( $path, $oPredicates ) ?
'update' :
'create',
237 'newSha1' => $nPredicates[
'sha1'][
$path]
242 return array_merge( $nullEntries, $updateEntries, $deleteEntries );
253 final public function precheck( array &$predicates ) {
254 if ( $this->state !== self::STATE_NEW ) {
261 foreach ( array_unique( $storagePaths ) as $storagePath ) {
262 if ( !$this->backend->isPathUsableInternal( $storagePath ) ) {
263 $status->fatal(
'backend-fail-usable', $storagePath );
292 if ( $this->state !== self::STATE_CHECKED ) {
294 } elseif ( $this->
failed ) {
298 if ( $this->doOperation ) {
326 $this->async =
false;
337 return [ [], [], [] ];
380 if ( $this->sourceSha1 ===
null ) {
381 $this->sourceSha1 = $this->
fileSha1( $this->params[
'src'], $predicates );
383 $this->overwriteSameCase =
false;
384 $this->destExists = $this->
fileExists( $this->params[
'dst'], $predicates );
385 if ( $this->destExists ) {
386 if ( $this->
getParam(
'overwrite' ) ) {
388 } elseif ( $this->
getParam(
'overwriteSame' ) ) {
389 $dhash = $this->
fileSha1( $this->params[
'dst'], $predicates );
391 if ( !strlen( $this->sourceSha1 ) || !strlen( $dhash ) ) {
392 $status->fatal(
'backend-fail-hashes' );
393 } elseif ( $this->sourceSha1 !== $dhash ) {
395 $status->fatal(
'backend-fail-notsame', $this->params[
'dst'] );
397 $this->overwriteSameCase =
true;
402 $status->fatal(
'backend-fail-alreadyexists', $this->params[
'dst'] );
406 } elseif ( $this->destExists === FileBackend::EXISTENCE_ERROR ) {
407 $status->fatal(
'backend-fail-stat', $this->params[
'dst'] );
434 if ( isset( $predicates[
'exists'][
$source] ) ) {
435 return $predicates[
'exists'][
$source];
439 return $this->backend->fileExists(
$params );
454 if ( isset( $predicates[
'sha1'][
$source] ) ) {
455 return $predicates[
'sha1'][
$source];
456 } elseif ( isset( $predicates[
'exists'][
$source] ) && !$predicates[
'exists'][
$source] ) {
461 return $this->backend->getFileSha1Base36(
$params );
481 $params[
'failedAction'] = $action;
483 $this->logger->error( static::class .
485 }
catch ( Exception $e ) {
logFailure( $action)
Log a file operation failure and preserve any temp files.
setBatchId( $batchId)
Set the batch UUID this operation belongs to.
bool $doOperation
Operation is not a no-op.
fileSha1( $source, array $predicates)
Get the SHA-1 hash a file in storage will have when this operation is attempted.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
allowedParams()
Get the file operation parameters.
FileBackend helper class for representing operations.
precheck(array &$predicates)
Check preconditions of the operation without writing anything.
static normalizeStoragePath( $storagePath)
Normalize a storage path by cleaning up directory separators.
getJournalEntries(array $oPredicates, array $nPredicates)
Get the file journal entries for this file operation.
doPrecheck(array &$predicates)
storagePathsChanged()
Get a list of storage paths written to for this operation.
applyDependencies(array $deps)
Update a dependency tracking array to account for this operation.
attemptAsync()
Attempt the operation in the background.
__construct(FileBackendStore $backend, array $params, LoggerInterface $logger)
Build a new batch file operation transaction.
getBackend()
Get the backend this operation is for.
failed()
Check if this operation failed precheck() or attempt()
static isStoragePath( $path)
Check if a given path is a "mwstore://" path.
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
FileBackendStore $backend
attempt()
Attempt the operation.
getParam( $name)
Get the value of the parameter with the given name.
dependsOn(array $deps)
Check if this operation changes files listed in $paths.
static newGood( $value=null)
Factory function for good results.
Base class for all backends using particular storage medium.
getSourceSha1Base36()
precheckDestExistence() helper function to get the source file SHA-1.
fileExists( $source, array $predicates)
Check if a file will exist in storage when this operation is attempted.
precheckDestExistence(array $predicates)
Check for errors with regards to the destination file already existing.
static newDependencies()
Get a new empty dependency tracking array for paths read/written to.
static normalizeIfValidStoragePath( $path)
Normalize a string if it is a valid storage path.
static newPredicates()
Get a new empty predicates array for precheck()
storagePathsRead()
Get a list of storage paths read from for this operation.