MediaWiki  1.28.1
FileOp Class Reference

FileBackend helper class for representing operations. More...

Inheritance diagram for FileOp:
Collaboration diagram for FileOp:

Public Member Functions

 __construct (FileBackendStore $backend, array $params, LoggerInterface $logger)
 Build a new batch file operation transaction. More...
 
 applyDependencies (array $deps)
 Update a dependency tracking array to account for this operation. More...
 
 attempt ()
 Attempt the operation. More...
 
 attemptAsync ()
 Attempt the operation in the background. More...
 
 dependsOn (array $deps)
 Check if this operation changes files listed in $paths. More...
 
 failed ()
 Check if this operation failed precheck() or attempt() More...
 
 getBackend ()
 Get the backend this operation is for. More...
 
 getJournalEntries (array $oPredicates, array $nPredicates)
 Get the file journal entries for this file operation. More...
 
 getParam ($name)
 Get the value of the parameter with the given name. More...
 
 logFailure ($action)
 Log a file operation failure and preserve any temp files. More...
 
 precheck (array &$predicates)
 Check preconditions of the operation without writing anything. More...
 
 setBatchId ($batchId)
 Set the batch UUID this operation belongs to. More...
 
 storagePathsChanged ()
 Get a list of storage paths written to for this operation. More...
 
 storagePathsRead ()
 Get a list of storage paths read from for this operation. More...
 

Static Public Member Functions

static newDependencies ()
 Get a new empty dependency tracking array for paths read/written to. More...
 
static newPredicates ()
 Get a new empty predicates array for precheck() More...
 

Public Attributes

const STATE_ATTEMPTED = 3
 
const STATE_CHECKED = 2
 
const STATE_NEW = 1
 

Protected Member Functions

 allowedParams ()
 Get the file operation parameters. More...
 
 doAttempt ()
 
 doPrecheck (array &$predicates)
 
 fileExists ($source, array $predicates)
 Check if a file will exist in storage when this operation is attempted. More...
 
 fileSha1 ($source, array $predicates)
 Get the SHA-1 of a file in storage when this operation is attempted. More...
 
 getSourceSha1Base36 ()
 precheckDestExistence() helper function to get the source file SHA-1. More...
 
 precheckDestExistence (array $predicates)
 Check for errors with regards to the destination file already existing. More...
 
 setFlags (array $params)
 Adjust params to FileBackendStore internal file calls. More...
 

Static Protected Member Functions

static normalizeIfValidStoragePath ($path)
 Normalize a string if it is a valid storage path. More...
 

Protected Attributes

bool $async = false
 
FileBackendStore $backend
 
string $batchId
 
bool $destExists
 
bool $doOperation = true
 Operation is not a no-op. More...
 
bool $failed = false
 
LoggerInterface $logger
 
bool $overwriteSameCase
 
array $params = []
 
string $sourceSha1
 
int $state = self::STATE_NEW
 

Detailed Description

FileBackend helper class for representing operations.

Do not use this class from places outside FileBackend.

Methods called from FileOpBatch::attempt() should avoid throwing exceptions at all costs. FileOp objects should be lightweight in order to support large arrays in memory and serialization.

Since
1.19

Definition at line 37 of file FileOp.php.

Constructor & Destructor Documentation

FileOp::__construct ( FileBackendStore  $backend,
array  $params,
LoggerInterface  $logger 
)
final

Build a new batch file operation transaction.

Parameters
FileBackendStore$backend
array$params
LoggerInterface$loggerPSR logger instance
Exceptions
FileBackendError

Definition at line 83 of file FileOp.php.

References $backend, $logger, $name, allowedParams(), as, and list.

Member Function Documentation

FileOp::allowedParams ( )
protected

Get the file operation parameters.

Returns
array (required params list, optional params list, list of params that are paths)

Definition at line 325 of file FileOp.php.

Referenced by __construct().

FileOp::applyDependencies ( array  $deps)
final

Update a dependency tracking array to account for this operation.

Parameters
array$depsPrior path reads/writes; format of FileOp::newPredicates()
Returns
array

Definition at line 177 of file FileOp.php.

References storagePathsChanged(), and storagePathsRead().

FileOp::attempt ( )
final

Attempt the operation.

Returns
StatusValue

Definition at line 280 of file FileOp.php.

References $status, doAttempt(), failed(), logFailure(), StatusValue\newFatal(), and StatusValue\newGood().

Referenced by attemptAsync().

FileOp::attemptAsync ( )
final

Attempt the operation in the background.

Returns
StatusValue

Definition at line 312 of file FileOp.php.

References attempt().

FileOp::dependsOn ( array  $deps)
final

Check if this operation changes files listed in $paths.

Parameters
array$depsPrior path reads/writes; format of FileOp::newPredicates()
Returns
bool

Definition at line 190 of file FileOp.php.

References $path, as, storagePathsChanged(), and storagePathsRead().

FileOp::doAttempt ( )
protected
Returns
StatusValue

Definition at line 303 of file FileOp.php.

References StatusValue\newGood().

Referenced by attempt().

FileOp::doPrecheck ( array $predicates)
protected
Parameters
array$predicates
Returns
StatusValue

Definition at line 271 of file FileOp.php.

References StatusValue\newGood().

Referenced by precheck().

FileOp::failed ( )
final

Check if this operation failed precheck() or attempt()

Returns
bool

Definition at line 149 of file FileOp.php.

References $failed.

Referenced by attempt(), and precheck().

FileOp::fileExists (   $source,
array  $predicates 
)
finalprotected

Check if a file will exist in storage when this operation is attempted.

Parameters
string$sourceStorage path
array$predicates
Returns
bool

Definition at line 417 of file FileOp.php.

References $source, and true.

Referenced by DeleteFileOp\doPrecheck(), DescribeFileOp\doPrecheck(), CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), getJournalEntries(), and precheckDestExistence().

FileOp::fileSha1 (   $source,
array  $predicates 
)
finalprotected

Get the SHA-1 of a file in storage when this operation is attempted.

Parameters
string$sourceStorage path
array$predicates
Returns
string|bool False on failure

Definition at line 434 of file FileOp.php.

References $source, and true.

Referenced by DescribeFileOp\doPrecheck(), getJournalEntries(), and precheckDestExistence().

FileOp::getBackend ( )

Get the backend this operation is for.

Returns
FileBackendStore

Definition at line 451 of file FileOp.php.

References $backend.

FileOp::getJournalEntries ( array  $oPredicates,
array  $nPredicates 
)
final

Get the file journal entries for this file operation.

Parameters
array$oPredicatesPre-op info about files (format of FileOp::newPredicates)
array$nPredicatesPost-op info about files (format of FileOp::newPredicates)
Returns
array

Definition at line 212 of file FileOp.php.

References $path, as, fileExists(), fileSha1(), storagePathsChanged(), and storagePathsRead().

FileOp::getParam (   $name)
final

Get the value of the parameter with the given name.

Parameters
string$name
Returns
mixed Returns null if the parameter is not set

Definition at line 140 of file FileOp.php.

References $name.

Referenced by CopyFileOp\doAttempt(), MoveFileOp\doAttempt(), DeleteFileOp\doPrecheck(), CreateFileOp\doPrecheck(), CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), and precheckDestExistence().

FileOp::getSourceSha1Base36 ( )
protected

precheckDestExistence() helper function to get the source file SHA-1.

Subclasses should overwride this if the source is not in storage.

Returns
string|bool Returns false on failure

Definition at line 406 of file FileOp.php.

Referenced by precheckDestExistence().

FileOp::logFailure (   $action)
final

Log a file operation failure and preserve any temp files.

Parameters
string$action

Definition at line 460 of file FileOp.php.

References $e, $params, and FormatJson\encode().

Referenced by attempt().

static FileOp::newDependencies ( )
staticfinal

Get a new empty dependency tracking array for paths read/written to.

Returns
array

Definition at line 167 of file FileOp.php.

Referenced by FileOpBatch\attempt().

static FileOp::newPredicates ( )
staticfinal

Get a new empty predicates array for precheck()

Returns
array

Definition at line 158 of file FileOp.php.

Referenced by FileOpBatch\attempt().

static FileOp::normalizeIfValidStoragePath (   $path)
staticprotected

Normalize a string if it is a valid storage path.

Parameters
string$path
Returns
string

Definition at line 115 of file FileOp.php.

References $path, $res, FileBackend\isStoragePath(), and FileBackend\normalizeStoragePath().

FileOp::precheck ( array $predicates)
final

Check preconditions of the operation without writing anything.

This must update $predicates for each path that the op can change except when a failing StatusValue object is returned.

Parameters
array$predicates
Returns
StatusValue

Definition at line 254 of file FileOp.php.

References $status, doPrecheck(), failed(), and StatusValue\newFatal().

FileOp::precheckDestExistence ( array  $predicates)
protected

Check for errors with regards to the destination file already existing.

Also set the destExists, overwriteSameCase and sourceSha1 member variables. A bad StatusValue will be returned if there is no chance it can be overwritten.

Parameters
array$predicates
Returns
StatusValue

Definition at line 365 of file FileOp.php.

References $status, fileExists(), fileSha1(), getParam(), getSourceSha1Base36(), and StatusValue\newGood().

Referenced by CreateFileOp\doPrecheck(), StoreFileOp\doPrecheck(), MoveFileOp\doPrecheck(), and CopyFileOp\doPrecheck().

FileOp::setBatchId (   $batchId)
final

Set the batch UUID this operation belongs to.

Parameters
string$batchId

Definition at line 130 of file FileOp.php.

References $batchId.

FileOp::setFlags ( array  $params)
protected

Adjust params to FileBackendStore internal file calls.

Parameters
array$params
Returns
array (required params list, optional params list)

Definition at line 335 of file FileOp.php.

References $async, and $params.

Referenced by DescribeFileOp\doAttempt(), CreateFileOp\doAttempt(), DeleteFileOp\doAttempt(), StoreFileOp\doAttempt(), CopyFileOp\doAttempt(), and MoveFileOp\doAttempt().

FileOp::storagePathsChanged ( )

Get a list of storage paths written to for this operation.

Returns
array

Definition at line 353 of file FileOp.php.

Referenced by applyDependencies(), dependsOn(), and getJournalEntries().

FileOp::storagePathsRead ( )

Get a list of storage paths read from for this operation.

Returns
array

Definition at line 344 of file FileOp.php.

Referenced by applyDependencies(), dependsOn(), and getJournalEntries().

Member Data Documentation

bool FileOp::$async = false
protected

Definition at line 53 of file FileOp.php.

Referenced by setFlags().

FileBackendStore FileOp::$backend
protected

Definition at line 42 of file FileOp.php.

Referenced by __construct(), and getBackend().

string FileOp::$batchId
protected

Definition at line 56 of file FileOp.php.

Referenced by setBatchId().

bool FileOp::$destExists
protected
bool FileOp::$doOperation = true
protected

Operation is not a no-op.

Definition at line 59 of file FileOp.php.

bool FileOp::$failed = false
protected

Definition at line 50 of file FileOp.php.

Referenced by failed().

LoggerInterface FileOp::$logger
protected

Definition at line 44 of file FileOp.php.

Referenced by __construct().

bool FileOp::$overwriteSameCase
protected

Definition at line 65 of file FileOp.php.

array FileOp::$params = []
protected

Definition at line 39 of file FileOp.php.

Referenced by logFailure(), and setFlags().

string FileOp::$sourceSha1
protected
int FileOp::$state = self::STATE_NEW
protected

Definition at line 47 of file FileOp.php.

const FileOp::STATE_ATTEMPTED = 3

Definition at line 73 of file FileOp.php.

const FileOp::STATE_CHECKED = 2

Definition at line 72 of file FileOp.php.

const FileOp::STATE_NEW = 1

Definition at line 71 of file FileOp.php.


The documentation for this class was generated from the following file: