X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilerepo%2Fbackend%2FFileBackend.php;h=3cc902194544f61a9704c2a258c0925f9cfff79c;hb=a7e28d201191e7ca8a51d10140f3f84c266b197d;hp=24c68495ba2f28551df3e2555d0c0fcafbd5bf17;hpb=cb559873daa95b833c67136850a5baa96c3c0c35;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filerepo/backend/FileBackend.php b/includes/filerepo/backend/FileBackend.php index 24c68495ba..3cc9021945 100644 --- a/includes/filerepo/backend/FileBackend.php +++ b/includes/filerepo/backend/FileBackend.php @@ -88,6 +88,7 @@ abstract class FileBackend { * 'concurrency' : How many file operations can be done in parallel. * * @param $config Array + * @throws MWException */ public function __construct( array $config ) { $this->name = $config['name']; @@ -286,8 +287,7 @@ abstract class FileBackend { * @return Status */ final public function create( array $params, array $opts = array() ) { - $params['op'] = 'create'; - return $this->doOperation( $params, $opts ); + return $this->doOperation( array( 'op' => 'create' ) + $params, $opts ); } /** @@ -301,8 +301,7 @@ abstract class FileBackend { * @return Status */ final public function store( array $params, array $opts = array() ) { - $params['op'] = 'store'; - return $this->doOperation( $params, $opts ); + return $this->doOperation( array( 'op' => 'store' ) + $params, $opts ); } /** @@ -316,8 +315,7 @@ abstract class FileBackend { * @return Status */ final public function copy( array $params, array $opts = array() ) { - $params['op'] = 'copy'; - return $this->doOperation( $params, $opts ); + return $this->doOperation( array( 'op' => 'copy' ) + $params, $opts ); } /** @@ -331,8 +329,7 @@ abstract class FileBackend { * @return Status */ final public function move( array $params, array $opts = array() ) { - $params['op'] = 'move'; - return $this->doOperation( $params, $opts ); + return $this->doOperation( array( 'op' => 'move' ) + $params, $opts ); } /** @@ -346,8 +343,164 @@ abstract class FileBackend { * @return Status */ final public function delete( array $params, array $opts = array() ) { - $params['op'] = 'delete'; - return $this->doOperation( $params, $opts ); + return $this->doOperation( array( 'op' => 'delete' ) + $params, $opts ); + } + + /** + * Perform a set of independent file operations on some files. + * + * This does no locking, nor journaling, and possibly no stat calls. + * Any destination files that already exist will be overwritten. + * This should *only* be used on non-original files, like cache files. + * + * Supported operations and their parameters: + * a) Create a new file in storage with the contents of a string + * array( + * 'op' => 'create', + * 'dst' => , + * 'content' => + * ) + * b) Copy a file system file into storage + * array( + * 'op' => 'store', + * 'src' => , + * 'dst' => + * ) + * c) Copy a file within storage + * array( + * 'op' => 'copy', + * 'src' => , + * 'dst' => + * ) + * d) Move a file within storage + * array( + * 'op' => 'move', + * 'src' => , + * 'dst' => + * ) + * e) Delete a file within storage + * array( + * 'op' => 'delete', + * 'src' => , + * 'ignoreMissingSource' => + * ) + * f) Do nothing (no-op) + * array( + * 'op' => 'null', + * ) + * + * Boolean flags for operations (operation-specific): + * 'ignoreMissingSource' : The operation will simply succeed and do + * nothing if the source file does not exist. + * + * Return value: + * This returns a Status, which contains all warnings and fatals that occured + * during the operation. The 'failCount', 'successCount', and 'success' members + * will reflect each operation attempted for the given files. The status will be + * considered "OK" as long as no fatal errors occured. + * + * @param $ops Array Set of operations to execute + * @return Status + * @since 1.20 + */ + final public function doQuickOperations( array $ops ) { + if ( $this->isReadOnly() ) { + return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly ); + } + foreach ( $ops as &$op ) { + $op['overwrite'] = true; // avoids RTTs in key/value stores + } + return $this->doQuickOperationsInternal( $ops ); + } + + /** + * @see FileBackend::doQuickOperations() + * @since 1.20 + */ + abstract protected function doQuickOperationsInternal( array $ops ); + + /** + * Same as doQuickOperations() except it takes a single operation. + * If you are doing a batch of operations, then use that function instead. + * + * @see FileBackend::doQuickOperations() + * + * @param $op Array Operation + * @return Status + * @since 1.20 + */ + final public function doQuickOperation( array $op ) { + return $this->doQuickOperations( array( $op ) ); + } + + /** + * Performs a single quick create operation. + * This sets $params['op'] to 'create' and passes it to doQuickOperation(). + * + * @see FileBackend::doQuickOperation() + * + * @param $params Array Operation parameters + * @return Status + * @since 1.20 + */ + final public function quickCreate( array $params ) { + return $this->doQuickOperation( array( 'op' => 'create' ) + $params ); + } + + /** + * Performs a single quick store operation. + * This sets $params['op'] to 'store' and passes it to doQuickOperation(). + * + * @see FileBackend::doQuickOperation() + * + * @param $params Array Operation parameters + * @return Status + * @since 1.20 + */ + final public function quickStore( array $params ) { + return $this->doQuickOperation( array( 'op' => 'store' ) + $params ); + } + + /** + * Performs a single quick copy operation. + * This sets $params['op'] to 'copy' and passes it to doQuickOperation(). + * + * @see FileBackend::doQuickOperation() + * + * @param $params Array Operation parameters + * @return Status + * @since 1.20 + */ + final public function quickCopy( array $params ) { + return $this->doQuickOperation( array( 'op' => 'copy' ) + $params ); + } + + /** + * Performs a single quick move operation. + * This sets $params['op'] to 'move' and passes it to doQuickOperation(). + * + * @see FileBackend::doQuickOperation() + * + * @param $params Array Operation parameters + * @return Status + * @since 1.20 + */ + final public function quickMove( array $params ) { + return $this->doQuickOperation( array( 'op' => 'move' ) + $params ); + } + + /** + * Performs a single quick delete operation. + * This sets $params['op'] to 'delete' and passes it to doQuickOperation(). + * + * @see FileBackend::doQuickOperation() + * + * @param $params Array Operation parameters + * @return Status + * @since 1.20 + */ + final public function quickDelete( array $params ) { + return $this->doQuickOperation( array( 'op' => 'delete' ) + $params ); } /** @@ -597,6 +750,7 @@ abstract class FileBackend { * $params include: * dir : storage directory * + * @param $params array * @return bool|null Returns null on failure * @since 1.20 */ @@ -616,6 +770,7 @@ abstract class FileBackend { * dir : storage directory * topOnly : only return direct child dirs of the directory * + * @param $params array * @return Traversable|Array|null Returns null on failure * @since 1.20 */ @@ -630,6 +785,7 @@ abstract class FileBackend { * $params include: * dir : storage directory * + * @param $params array * @return Traversable|Array|null Returns null on failure * @since 1.20 */ @@ -651,6 +807,7 @@ abstract class FileBackend { * dir : storage directory * topOnly : only return direct child files of the directory (@since 1.20) * + * @param $params array * @return Traversable|Array|null Returns null on failure */ abstract public function getFileList( array $params ); @@ -664,6 +821,7 @@ abstract class FileBackend { * $params include: * dir : storage directory * + * @param $params array * @return Traversable|Array|null Returns null on failure * @since 1.20 */ @@ -722,6 +880,24 @@ abstract class FileBackend { return ScopedLock::factory( $this->lockManager, $paths, $type, $status ); } + /** + * Get an array of scoped locks needed for a batch of file operations. + * + * Normally, FileBackend::doOperations() handles locking, unless + * the 'nonLocking' param is passed in. This function is useful if you + * want the files to be locked for a broader scope than just when the + * files are changing. For example, if you need to update DB metadata, + * you may want to keep the files locked until finished. + * + * @see FileBackend::doOperations() + * + * @param $ops Array List of file operations to FileBackend::doOperations() + * @param $status Status Status to update on lock/unlock + * @return Array List of ScopedFileLocks or null values + * @since 1.20 + */ + abstract public function getScopedLocksForOps( array $ops, Status $status ); + /** * Get the root storage path of this backend. * All container paths are "subdirectories" of this path. @@ -733,6 +909,15 @@ abstract class FileBackend { return "mwstore://{$this->name}"; } + /** + * Get the file journal object for this backend + * + * @return FileJournal + */ + final public function getJournal() { + return $this->fileJournal; + } + /** * Check if a given path is a "mwstore://" path. * This does not do any further validation or any existence checks.