|
| 1 | +<?php |
| 2 | +use Illuminate\Console\Command; |
| 3 | +use Symfony\Component\Console\Input\InputOption; |
| 4 | +use Symfony\Component\Console\Input\InputArgument; |
| 5 | +use Locker\Repository\File\Factory as FileFactory; |
| 6 | + |
| 7 | +class FileRepositoryCommand extends Command { |
| 8 | + protected $name = 'll:file-repo'; |
| 9 | + protected $description = 'Migrates files from one file repository (i.e. Local) to another (i.e. Rackspace).'; |
| 10 | + |
| 11 | + public function fire() { |
| 12 | + $from_var = $this->option('from'); |
| 13 | + $to_var = $this->argument('to'); |
| 14 | + $from_repo = FileFactory::createRepo($from_var); |
| 15 | + $to_repo = FileFactory::createRepo($to_var); |
| 16 | + $files = $from_repo->index([]); |
| 17 | + |
| 18 | + $count = 0; |
| 19 | + foreach ($files as $file) { |
| 20 | + $path = $file['path']; |
| 21 | + if ($file['type'] === 'file' && !$to_repo->has($path, [])) { |
| 22 | + $count += 1; |
| 23 | + $to_repo->update($path, ['content' => $from_repo->show($path, [])], []); |
| 24 | + echo "Migrated '{$path}' from '{$from_var}' to '{$to_var}'.".PHP_EOL; |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + echo "Migrated $count files and ignored ".(count($files) - $count).".".PHP_EOL; |
| 29 | + } |
| 30 | + |
| 31 | + protected function getArguments() { |
| 32 | + return [ |
| 33 | + ['to', InputArgument::REQUIRED, 'The repository to migrate to.'] |
| 34 | + ]; |
| 35 | + } |
| 36 | + |
| 37 | + protected function getOptions() { |
| 38 | + return [ |
| 39 | + ['from', 'f', InputOption::VALUE_OPTIONAL, 'The repository to migrate from.', 'Local'], |
| 40 | + ]; |
| 41 | + } |
| 42 | + |
| 43 | +} |
0 commit comments