24use InvalidArgumentException;
29use Shellbox\Command\BoxedCommand;
59 private int $migrationStage;
66 parent::__construct( $config );
67 $this->backend = $config[
'backend'];
68 $this->repoName = $config[
'repoName'];
69 $this->dbHandleFunc = $config[
'dbHandleFactory'];
97 return current( $paths );
115 foreach ( $paths as $i =>
$path ) {
116 if ( !$latest && $this->resolvedPathCache->hasField(
$path,
'target', 10 ) ) {
117 $resolved[$i] = $this->resolvedPathCache->getField(
$path,
'target' );
123 if ( $container ===
"{$this->repoName}-public" ) {
126 if ( str_contains(
$path,
'!' ) ) {
127 $sha1 = $db->newSelectQueryBuilder()
128 ->select(
'oi_sha1' )
130 ->where( [
'oi_archive_name' =>
$name ] )
131 ->caller( __METHOD__ )->fetchField();
133 $sha1 = $db->newSelectQueryBuilder()
134 ->select(
'img_sha1' )
136 ->where( [
'img_name' =>
$name ] )
137 ->caller( __METHOD__ )->fetchField();
140 if ( str_contains(
$path,
'!' ) ) {
141 $sha1 = $db->newSelectQueryBuilder()
142 ->select(
'fr_sha1' )
143 ->from(
'filerevision' )
144 ->where( [
'fr_archive_name' =>
$name ] )
145 ->caller( __METHOD__ )->fetchField();
147 $sha1 = $db->newSelectQueryBuilder()
148 ->select(
'fr_sha1' )
150 ->join(
'filerevision',
null,
'file_latest = fr_id' )
151 ->where( [
'file_name' =>
$name ] )
152 ->caller( __METHOD__ )->fetchField();
156 if ( !is_string( $sha1 ) || $sha1 ===
'' ) {
157 $resolved[$i] =
$path;
161 $this->resolvedPathCache->setField(
$path,
'target', $resolved[$i] );
162 } elseif ( $container ===
"{$this->repoName}-deleted" ) {
164 $sha1 = substr(
$name, 0, strpos(
$name,
'.' ) );
166 $this->resolvedPathCache->setField(
$path,
'target', $resolved[$i] );
168 $resolved[$i] =
$path;
173 foreach ( $paths as $i =>
$path ) {
174 $res[$i] = $resolved[$i];
181 return $this->backend->doOperationsInternal( $this->
mungeOpPaths( $ops ), $opts );
185 return $this->backend->doQuickOperationsInternal( $this->
mungeOpPaths( $ops ), $opts );
189 return $this->backend->doPrepare(
$params );
193 return $this->backend->doSecure(
$params );
197 return $this->backend->doPublish(
$params );
201 return $this->backend->doClean(
$params );
241 $type = StreamFile::contentTypeFromPath(
$params[
'src'] );
242 if ( $type && $type !=
'unknown/unknown' ) {
243 $params[
'headers'][] =
"Content-type: $type";
268 return $this->backend->addShellboxInputFile( $command, $boxedName,
$params );
272 return $this->backend->directoryExists(
$params );
276 return $this->backend->getDirectoryList(
$params );
280 return $this->backend->getFileList(
$params );
284 return $this->backend->getFeatures();
288 $this->backend->clearCache(
null );
293 $this->backend->preloadCache( $paths );
301 return $this->backend->getScopedLocksForOps( $ops, $status );
313 if ( strlen( $sha1 ) < 3 ) {
314 throw new InvalidArgumentException(
"Invalid file SHA-1." );
316 return $this->backend->getContainerStoragePath(
"{$this->repoName}-original" ) .
317 "/{$sha1[0]}/{$sha1[1]}/{$sha1[2]}/{$sha1}";
326 protected function getDB( $index ) {
327 if ( !isset( $this->dbs[$index] ) ) {
329 $this->dbs[$index] = $func( $index );
331 return $this->dbs[$index];
342 $latest = !empty(
$params[
'latest'] );
344 if ( isset(
$params[
'src'] ) ) {
348 if ( isset(
$params[
'srcs'] ) ) {
352 return $this->backend->$function(
$params );
365 $pathMap = array_combine(
$params[
'srcs'], $origPaths );
367 $results = $this->backend->$function(
$params );
370 foreach ( $results as
$path => $result ) {
371 $contents[$pathMap[
$path]] = $result;
387 static $srcRefOps = [
'store',
'copy',
'describe' ];
388 foreach ( $ops as &$op ) {
389 if ( isset( $op[
'src'] ) && in_array( $op[
'op'], $srcRefOps ) ) {
392 if ( isset( $op[
'srcs'] ) ) {
401class_alias( FileBackendDBRepoWrapper::class,
'FileBackendDBRepoWrapper' );
const SCHEMA_COMPAT_READ_OLD
array $params
The job parameters.
Store key-value entries in a size-limited in-memory LRU cache.
A class containing constants representing the names of configuration variables.
const FileSchemaMigrationStage
Name constant for the FileSchemaMigrationStage setting, for use with Config::get()
Generic operation result class Has warning/error list, boolean status and arbitrary value.