MediaWiki
1.34.0
|
FileBackend helper class for representing operations. More...
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 hash a file in storage will have 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 |
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.
Definition at line 36 of file FileOp.php.
|
final |
Build a new batch file operation transaction.
FileBackendStore | $backend | |
array | $params | |
LoggerInterface | $logger | PSR logger instance |
InvalidArgumentException |
Definition at line 82 of file FileOp.php.
References $backend, $logger, $params, allowedParams(), and normalizeIfValidStoragePath().
|
protected |
Get the file operation parameters.
Reimplemented in StoreFileOp, CopyFileOp, DeleteFileOp, DescribeFileOp, MoveFileOp, and CreateFileOp.
Definition at line 336 of file FileOp.php.
Referenced by __construct().
|
final |
Update a dependency tracking array to account for this operation.
array | $deps | Prior path reads/writes; format of FileOp::newPredicates() |
Definition at line 176 of file FileOp.php.
References storagePathsChanged(), and storagePathsRead().
|
final |
Attempt the operation.
Definition at line 291 of file FileOp.php.
References $status, doAttempt(), failed(), logFailure(), StatusValue\newFatal(), StatusValue\newGood(), and STATE_ATTEMPTED.
Referenced by attemptAsync().
|
final |
Attempt the operation in the background.
Definition at line 323 of file FileOp.php.
References attempt().
|
final |
Check if this operation changes files listed in $paths.
array | $deps | Prior path reads/writes; format of FileOp::newPredicates() |
Definition at line 189 of file FileOp.php.
References $path, storagePathsChanged(), and storagePathsRead().
|
protected |
Reimplemented in MoveFileOp, CopyFileOp, StoreFileOp, DeleteFileOp, CreateFileOp, and DescribeFileOp.
Definition at line 314 of file FileOp.php.
References StatusValue\newGood().
Referenced by attempt().
|
protected |
array | &$predicates |
Reimplemented in StoreFileOp, CopyFileOp, MoveFileOp, CreateFileOp, DeleteFileOp, and DescribeFileOp.
Definition at line 282 of file FileOp.php.
References StatusValue\newGood().
Referenced by precheck().
|
final |
Check if this operation failed precheck() or attempt()
Definition at line 148 of file FileOp.php.
References $failed.
Referenced by attempt(), and precheck().
|
finalprotected |
Check if a file will exist in storage when this operation is attempted.
Ideally, the file stat entry should already be preloaded via preloadFileStat(). Otherwise, this will query the backend.
string | $source | Storage path |
array | $predicates |
Definition at line 433 of file FileOp.php.
References $params, $source, and true.
Referenced by DeleteFileOp\doPrecheck(), DescribeFileOp\doPrecheck(), CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), getJournalEntries(), and precheckDestExistence().
|
finalprotected |
Get the SHA-1 hash a file in storage will have when this operation is attempted.
Ideally, file the stat entry should already be preloaded via preloadFileStat() and the backend tracks hashes as extended attributes. Otherwise, this will query the backend.
string | $source | Storage path |
array | $predicates |
Definition at line 453 of file FileOp.php.
References $params, $source, and true.
Referenced by DescribeFileOp\doPrecheck(), getJournalEntries(), and precheckDestExistence().
FileOp::getBackend | ( | ) |
Get the backend this operation is for.
Definition at line 470 of file FileOp.php.
References $backend.
|
final |
Get the file journal entries for this file operation.
array | $oPredicates | Pre-op info about files (format of FileOp::newPredicates) |
array | $nPredicates | Post-op info about files (format of FileOp::newPredicates) |
Definition at line 211 of file FileOp.php.
References $path, fileExists(), fileSha1(), storagePathsChanged(), and storagePathsRead().
|
final |
Get the value of the parameter with the given name.
string | $name |
Definition at line 139 of file FileOp.php.
Referenced by CopyFileOp\doAttempt(), MoveFileOp\doAttempt(), DeleteFileOp\doPrecheck(), CreateFileOp\doPrecheck(), CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), and precheckDestExistence().
|
protected |
precheckDestExistence() helper function to get the source file SHA-1.
Subclasses should overwride this if the source is not in storage.
Reimplemented in StoreFileOp, and CreateFileOp.
Definition at line 419 of file FileOp.php.
Referenced by precheckDestExistence().
|
final |
Log a file operation failure and preserve any temp files.
string | $action |
Definition at line 479 of file FileOp.php.
References $params, and FormatJson\encode().
Referenced by attempt().
|
staticfinal |
Get a new empty dependency tracking array for paths read/written to.
Definition at line 166 of file FileOp.php.
Referenced by FileOpBatch\attempt().
|
staticfinal |
Get a new empty predicates array for precheck()
Definition at line 157 of file FileOp.php.
Referenced by FileOpBatch\attempt().
|
staticprotected |
Normalize a string if it is a valid storage path.
string | $path |
Definition at line 114 of file FileOp.php.
References $path, $res, FileBackend\isStoragePath(), and FileBackend\normalizeStoragePath().
Referenced by __construct().
|
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.
array | &$predicates |
Definition at line 253 of file FileOp.php.
References $status, doPrecheck(), failed(), StatusValue\newFatal(), StatusValue\newGood(), STATE_CHECKED, storagePathsChanged(), and storagePathsRead().
|
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.
array | $predicates |
Definition at line 376 of file FileOp.php.
References $status, fileExists(), fileSha1(), getParam(), getSourceSha1Base36(), and StatusValue\newGood().
Referenced by CreateFileOp\doPrecheck(), CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), and StoreFileOp\doPrecheck().
|
final |
Set the batch UUID this operation belongs to.
string | $batchId |
Definition at line 129 of file FileOp.php.
References $batchId.
|
protected |
Adjust params to FileBackendStore internal file calls.
array | $params |
Definition at line 346 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.
Reimplemented in MoveFileOp, CopyFileOp, StoreFileOp, CreateFileOp, DeleteFileOp, and DescribeFileOp.
Definition at line 364 of file FileOp.php.
Referenced by applyDependencies(), dependsOn(), getJournalEntries(), and precheck().
FileOp::storagePathsRead | ( | ) |
Get a list of storage paths read from for this operation.
Reimplemented in MoveFileOp, and CopyFileOp.
Definition at line 355 of file FileOp.php.
Referenced by applyDependencies(), dependsOn(), getJournalEntries(), and precheck().
|
protected |
Definition at line 52 of file FileOp.php.
Referenced by setFlags().
|
protected |
Definition at line 41 of file FileOp.php.
Referenced by __construct(), and getBackend().
|
protected |
Definition at line 55 of file FileOp.php.
Referenced by setBatchId().
|
protected |
Definition at line 67 of file FileOp.php.
Referenced by CreateFileOp\doPrecheck(), CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), and StoreFileOp\doPrecheck().
|
protected |
Operation is not a no-op.
Definition at line 58 of file FileOp.php.
|
protected |
Definition at line 49 of file FileOp.php.
Referenced by failed().
|
protected |
Definition at line 43 of file FileOp.php.
Referenced by __construct().
|
protected |
Definition at line 64 of file FileOp.php.
|
protected |
Definition at line 38 of file FileOp.php.
Referenced by __construct(), fileExists(), fileSha1(), logFailure(), and setFlags().
|
protected |
Definition at line 61 of file FileOp.php.
Referenced by CreateFileOp\doPrecheck(), CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), and StoreFileOp\doPrecheck().
|
protected |
Definition at line 46 of file FileOp.php.
const FileOp::STATE_ATTEMPTED = 3 |
Definition at line 72 of file FileOp.php.
Referenced by attempt().
const FileOp::STATE_CHECKED = 2 |
Definition at line 71 of file FileOp.php.
Referenced by precheck().
const FileOp::STATE_NEW = 1 |
Definition at line 70 of file FileOp.php.