public function S3fsCommands::copyLocal in S3 File System 4.0.x
Same name and namespace in other branches
- 8.3 src/Commands/S3fsCommands.php \Drupal\s3fs\Commands\S3fsCommands::copyLocal()
Copy local files into your S3 bucket.
Copies files from local public:// or private:// into the S3 bucket.
@command s3fs:copy-local @aliases s3fs-cl, s3fs-copy-local @option scheme Limit the process to an specific scheme. E.g. (public or private), all by default. @option condition Limits when to migrate files one of always,newer,size,newer_size. Default always. @usage drush s3fs-copy-local Copy local files from your public and/or private file system(s) into your S3 bucket. @usage drush s3fs-copy-local --scheme=public Copy local files only from your public file system into your S3 bucket.
File
- src/
Commands/ S3fsCommands.php, line 110
Class
- S3fsCommands
- S3FS Drush commands handler.
Namespace
Drupal\s3fs\CommandsCode
public function copyLocal(array $options = [
'scheme' => 'all',
'condition' => 'always',
]) {
$scheme = $options['scheme'];
$uploadOptions = [];
switch ($options['condition']) {
case 'always':
$uploadOptions['upload_conditions']['always'] = TRUE;
break;
case 'newer_size':
$uploadOptions['upload_conditions']['newer'] = TRUE;
$uploadOptions['upload_conditions']['size'] = TRUE;
break;
case 'newer':
$uploadOptions['upload_conditions']['newer'] = TRUE;
break;
case 'size':
$uploadOptions['upload_conditions']['size'] = TRUE;
break;
}
$this
->logger()
->log(LogLevel::OK, new TranslatableMarkup('You are going to copy @scheme scheme(s).', [
'@scheme' => $scheme,
]));
$this
->logger()
->warning(new TranslatableMarkup('You should have read "Copy local files to S3" section in README.txt.'));
$this
->logger()
->warning(new TranslatableMarkup('This command only is useful if you have or you are going to have enabled s3 for public/private in your setting.php'));
if (!$this
->io()
->confirm(new TranslatableMarkup('Are you sure?'))) {
return new UserAbortException();
}
$config = $this->s3fsConfig
->get();
if ($errors = $this->s3fs
->validate($config)) {
foreach ($errors as $error) {
$this
->logger()
->error($error);
}
throw new \Exception(new TranslatableMarkup('Unable to validate your s3fs configuration settings. Please configure S3 File System from the admin/config/media/s3fs page and try again.'));
}
if ($scheme == 'all' || $scheme == 'public') {
$this
->logger()
->log(LogLevel::OK, new TranslatableMarkup('Including @scheme scheme', [
'@scheme' => 'public',
]));
$this->s3fsFileMigrationBatch
->execute($config, 'public', $uploadOptions);
}
if ($scheme == 'all' || $scheme == 'private') {
if (Settings::get('file_private_path')) {
$this
->logger()
->log(LogLevel::OK, new TranslatableMarkup('Including @scheme scheme', [
'@scheme' => 'private',
]));
$this->s3fsFileMigrationBatch
->execute($config, 'private', $uploadOptions);
}
else {
$this
->logger()
->warning(new TranslatableMarkup('Scheme @scheme is not properly configured, you must enable this scheme in your settings.php', [
'@scheme' => 'private',
]));
}
}
drush_backend_batch_process();
}