| @@ 9-66 (lines=58) @@ | ||
| 6 | ||
| 7 | use function App\Lib\mb_normalise as normalise; |
|
| 8 | ||
| 9 | class ExportCategories extends AbstractExportCommand |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * The name and signature of the console command. |
|
| 13 | * |
|
| 14 | * @var string |
|
| 15 | */ |
|
| 16 | protected $signature = 'export:categories |
|
| 17 | {--ci : No interaction (no progess, no confirmation)} |
|
| 18 | {output? : Target location for export (default Storage)}'; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The console command description. |
|
| 22 | * |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | protected $description = 'Export proxy categories of accounts'; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * The export folder location. |
|
| 29 | * |
|
| 30 | * @var string |
|
| 31 | */ |
|
| 32 | protected $exportFolder = 'categories'; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Execute the console command. |
|
| 36 | * |
|
| 37 | * @return mixed |
|
| 38 | */ |
|
| 39 | public function handle() |
|
| 40 | { |
|
| 41 | $categories = Category::get(); |
|
| 42 | ||
| 43 | if ($categories->isEmpty()) { |
|
| 44 | $this->info("No categories to export"); |
|
| 45 | return; |
|
| 46 | } |
|
| 47 | ||
| 48 | foreach ($categories as $category){ |
|
| 49 | $accounts = $this->fecthAccounts(['category_id' => $category->id]); |
|
| 50 | ||
| 51 | $name = normalise($category->name); |
|
| 52 | $filename = "{$this->exportFolder}/{$name}{$this->exportFileExt}"; |
|
| 53 | ||
| 54 | $count = $this->exportAccounts($accounts, $filename, false, $this->option('ci')); |
|
| 55 | ||
| 56 | try { |
|
| 57 | $url = $this->exportToLocation($filename); |
|
| 58 | } catch(\Exception $e) { |
|
| 59 | $this->error('Export cancelled by user!'); |
|
| 60 | return; |
|
| 61 | } |
|
| 62 | ||
| 63 | $this->info("{$count} accounts '{$category->name}' exported into file '{$url}'"); |
|
| 64 | } |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||
| @@ 9-66 (lines=58) @@ | ||
| 6 | ||
| 7 | use function App\Lib\mb_normalise as normalise; |
|
| 8 | ||
| 9 | class ExportGroups extends AbstractExportCommand |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * The name and signature of the console command. |
|
| 13 | * |
|
| 14 | * @var string |
|
| 15 | */ |
|
| 16 | protected $signature = 'export:groups |
|
| 17 | {--ci : No interaction (no progess, no confirmation)} |
|
| 18 | {output? : Target location for export (default Storage)}'; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The console command description. |
|
| 22 | * |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | protected $description = 'Export proxy groups of accounts'; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * The export folder location. |
|
| 29 | * |
|
| 30 | * @var string |
|
| 31 | */ |
|
| 32 | protected $exportFolder = 'groups'; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Execute the console command. |
|
| 36 | * |
|
| 37 | * @return mixed |
|
| 38 | */ |
|
| 39 | public function handle() |
|
| 40 | { |
|
| 41 | $groups = Group::get(); |
|
| 42 | ||
| 43 | if ($groups->isEmpty()) { |
|
| 44 | $this->info("No groups to export"); |
|
| 45 | return; |
|
| 46 | } |
|
| 47 | ||
| 48 | foreach ($groups as $group){ |
|
| 49 | $accounts = $this->fecthAccounts(['group_id' => $group->id]); |
|
| 50 | ||
| 51 | $name = normalise($group->name); |
|
| 52 | $filename = "{$this->exportFolder}/{$name}{$this->exportFileExt}"; |
|
| 53 | ||
| 54 | $count = $this->exportAccounts($accounts, $filename, false, $this->option('ci')); |
|
| 55 | ||
| 56 | try { |
|
| 57 | $url = $this->exportToLocation($filename); |
|
| 58 | } catch(\Exception $e) { |
|
| 59 | $this->error('Export cancelled by user!'); |
|
| 60 | return; |
|
| 61 | } |
|
| 62 | ||
| 63 | $this->info("{$count} accounts '{$group->name}' exported into file '{$url}'"); |
|
| 64 | } |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||