-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor cli command, drop regions, introduce cache header (#3)
* chore: refactor cli command, drop regions, introduce cache header * Apply fixes from StyleCI * chore: remove tmp notes * Apply fixes from StyleCI * adjust comment * remove debug code --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
de1e181
commit 4fe09e6
Showing
11 changed files
with
136 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/s3-assets. | ||
* | ||
* Copyright (c) FriendsOfFlarum | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\S3Assets\Console; | ||
|
||
use Flarum\Foundation\Console\AssetsPublishCommand; | ||
use Flarum\Foundation\Paths; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Contracts\Container\Container; | ||
use Illuminate\Contracts\Filesystem\Cloud; | ||
use Illuminate\Contracts\Filesystem\Factory; | ||
use Illuminate\Filesystem\Filesystem; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
||
class CopyAssetsCommand extends Command | ||
{ | ||
protected $signature = 'fof:s3:copy | ||
{--move : Delete local files after moving to the S3 disk}'; | ||
|
||
protected $description = 'Copy assets to the S3 disk'; | ||
|
||
public function handle(Container $container, Factory $factory, Paths $paths, AssetsPublishCommand $publishCommand) | ||
{ | ||
/** @var Filesystem $localFilesystem */ | ||
$localFilesystem = $container->make('files'); | ||
|
||
// Determine if files should be deleted after moving | ||
$deleteAfterMove = $this->option('move'); | ||
|
||
// Move assets | ||
$this->info($deleteAfterMove ? 'Moving assets...' : 'Copying assets...'); | ||
$this->moveFilesToDisk($localFilesystem, $paths->public.'/assets', $factory->disk('flarum-assets'), $deleteAfterMove); | ||
|
||
$publishCommand->run( | ||
new ArrayInput([]), | ||
new ConsoleOutput() | ||
); | ||
} | ||
|
||
/** | ||
* Get the registered disks. | ||
* | ||
* @return array | ||
*/ | ||
protected function getFlarumDisks(): array | ||
{ | ||
return resolve('flarum.filesystem.disks'); | ||
} | ||
|
||
protected function moveFilesToDisk(Filesystem $localFilesystem, string $localPath, Cloud $disk, bool $deleteAfterMove): void | ||
{ | ||
$count = count($localFilesystem->allFiles($localPath)); | ||
$this->output->progressStart($count); | ||
|
||
foreach ($localFilesystem->allFiles($localPath) as $file) { | ||
/** @var \Symfony\Component\Finder\SplFileInfo $file */ | ||
$written = $disk->put($file->getRelativePathname(), $file->getContents()); | ||
|
||
if ($written) { | ||
if ($deleteAfterMove) { | ||
$localFilesystem->delete($file->getPathname()); | ||
} | ||
$this->output->progressAdvance(); | ||
} else { | ||
throw new \Exception('File did not copy'); | ||
} | ||
} | ||
|
||
$this->output->progressFinish(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.