コード例 #1
0
	/**
	 * @param array $dstPathsRel
	 * @param string $backendRel
	 * @param FileBackend $dst
	 * @return void
	 */
	protected function delFileBatch(
		array $dstPathsRel, $backendRel, FileBackend $dst
	) {
		$ops = array();
		$deletedRel = array(); // for output message
		$wikiId = $dst->getWikiId();

		// Determine what files need to be copied over...
		foreach ( $dstPathsRel as $dstPathRel ) {
			$dstPath = $dst->getRootStoragePath() . "/$backendRel/$dstPathRel";
			$ops[] = array( 'op' => 'delete', 'src' => $dstPath );
			$deletedRel[] = $dstPathRel;
		}

		// Delete the batch of source files...
		$t_start = microtime( true );
		$status = $dst->doQuickOperations( $ops, array( 'bypassReadOnly' => 1 ) );
		if ( !$status->isOK() ) {
			sleep( 10 ); // wait and retry copy again
			$status = $dst->doQuickOperations( $ops, array( 'bypassReadOnly' => 1 ) );
		}
		$ellapsed_ms = floor( ( microtime( true ) - $t_start ) * 1000 );
		if ( !$status->isOK() ) {
			$this->error( print_r( $status->getErrorsArray(), true ) );
			$this->error( "$wikiId: Could not delete file batch.", 1 ); // die
		} elseif ( count( $deletedRel ) ) {
			$this->output( "\n\tDeleted these file(s) [{$ellapsed_ms}ms]:\n\t" .
				implode( "\n\t", $deletedRel ) . "\n\n" );
		}
	}
コード例 #2
0
ファイル: copyFileBackend.php プロジェクト: mangowi/mediawiki
 protected function copyFileBatch(array $srcPathsRel, $backendRel, FileBackend $src, FileBackend $dst)
 {
     $ops = array();
     $fsFiles = array();
     $copiedRel = array();
     // for output message
     $wikiId = $src->getWikiId();
     // Download the batch of source files into backend cache...
     if ($this->hasOption('missingonly')) {
         $srcPaths = array();
         foreach ($srcPathsRel as $srcPathRel) {
             $srcPaths[] = $src->getRootStoragePath() . "/{$backendRel}/{$srcPathRel}";
         }
         $t_start = microtime(true);
         $fsFiles = $src->getLocalReferenceMulti(array('srcs' => $srcPaths, 'latest' => 1));
         $ellapsed_ms = floor((microtime(true) - $t_start) * 1000);
         $this->output("\nDownloaded these file(s) [{$ellapsed_ms}ms]:\n" . implode("\n", $srcPaths) . "\n\n");
     }
     // Determine what files need to be copied over...
     foreach ($srcPathsRel as $srcPathRel) {
         $srcPath = $src->getRootStoragePath() . "/{$backendRel}/{$srcPathRel}";
         $dstPath = $dst->getRootStoragePath() . "/{$backendRel}/{$srcPathRel}";
         if ($this->hasOption('utf8only') && !mb_check_encoding($srcPath, 'UTF-8')) {
             $this->error("{$wikiId}: Detected illegal (non-UTF8) path for {$srcPath}.");
             continue;
         } elseif (!$this->hasOption('missingonly') && $this->filesAreSame($src, $dst, $srcPath, $dstPath)) {
             $this->output("Already have {$srcPathRel}.\n");
             continue;
             // assume already copied...
         }
         $fsFile = array_key_exists($srcPath, $fsFiles) ? $fsFiles[$srcPath] : $src->getLocalReference(array('src' => $srcPath, 'latest' => 1));
         if (!$fsFile) {
             $src->clearCache(array($srcPath));
             if ($src->fileExists(array('src' => $srcPath, 'latest' => 1)) === false) {
                 $this->error("{$wikiId}: File '{$srcPath}' was listed but does not exist.");
             } else {
                 $this->error("{$wikiId}: Could not get local copy of {$srcPath}.");
             }
             continue;
         } elseif (!$fsFile->exists()) {
             // FSFileBackends just return the path for getLocalReference() and paths with
             // illegal slashes may get normalized to a different path. This can cause the
             // local reference to not exist...skip these broken files.
             $this->error("{$wikiId}: Detected possible illegal path for {$srcPath}.");
             continue;
         }
         $fsFiles[] = $fsFile;
         // keep TempFSFile objects alive as needed
         // Note: prepare() is usually fast for key/value backends
         $status = $dst->prepare(array('dir' => dirname($dstPath), 'bypassReadOnly' => 1));
         if (!$status->isOK()) {
             $this->error(print_r($status->getErrorsArray(), true));
             $this->error("{$wikiId}: Could not copy {$srcPath} to {$dstPath}.", 1);
             // die
         }
         $ops[] = array('op' => 'store', 'src' => $fsFile->getPath(), 'dst' => $dstPath, 'overwrite' => 1);
         $copiedRel[] = $srcPathRel;
     }
     // Copy in the batch of source files...
     $t_start = microtime(true);
     $status = $dst->doQuickOperations($ops, array('bypassReadOnly' => 1));
     if (!$status->isOK()) {
         sleep(10);
         // wait and retry copy again
         $status = $dst->doQuickOperations($ops, array('bypassReadOnly' => 1));
     }
     $ellapsed_ms = floor((microtime(true) - $t_start) * 1000);
     if (!$status->isOK()) {
         $this->error(print_r($status->getErrorsArray(), true));
         $this->error("{$wikiId}: Could not copy file batch.", 1);
         // die
     } elseif (count($copiedRel)) {
         $this->output("\nCopied these file(s) [{$ellapsed_ms}ms]:\n" . implode("\n", $copiedRel) . "\n\n");
     }
 }