1 <?php
2
3 namespace Skimia\Assets\Console\Commands;
4
5 use Illuminate\Console\Command;
6 use Illuminate\Contracts\Bus\SelfHandling;
7 use Config;
8 use Skimia\Foundation\Testing\TestablePromptCommandInterface;
9 use Skimia\Foundation\Testing\Traits\TestableCommandTrait;
10
11 class DumpCollectionsCommand extends Command implements SelfHandling,TestablePromptCommandInterface
12 {
13 use TestableCommandTrait;
14 15 16 17 18
19 protected $name = 'asset:dump-collections';
20
21 22 23 24 25
26 protected $signature = 'asset:dump-collections {--s|silent}';
27
28 29 30 31 32
33 protected $description = 'Regenerate collection & copy files to public dir.';
34
35 36 37 38 39 40 41
42 public function __construct()
43 {
44 parent::__construct();
45
46
47
48
49
50
51
52 $this->app = app();
53 $this->config = app(Config::class);
54 }
55
56 57 58 59 60
61 public function fire()
62 {
63 $this->comment('Regeneration of assets collections...');
64 $directories = $this->getDirectories();
65 if (empty($directories)) {
66 $this->comment('no directories to scan, abort');
67
68 return;
69 }
70
71
72 $scanner = $this->getScanner();
73
74 $scanner->setDirectoriesToScan($directories);
75
76 $scanner->scan();
77 $added = $scanner->getNewlyBuildedCollections();
78 $removed = $scanner->getRemovedBuildedCollections();
79 if (count($added) > 0) {
80 $this->comment('added collections : '.implode(', ', $added));
81 }
82 if (count($removed) > 0) {
83 $this->comment('removed collections : '.implode(', ', $removed));
84 }
85 if ((count($added) + count($removed)) > 0 && $this->option('silent') !== true) {
86 $update = $this->ask('Update Assets groups with the new or removed collections ? y/n', 'y');
87 $this->comment('sorry in the new release ;)');
88 }
89 $this->comment('done');
90 }
91
92 93 94
95 protected function getDirectories()
96 {
97 return $this->app['config']->get('assets.directories', []);
98 }
99
100 101 102 103
104 protected function getScanner()
105 {
106 return $this->app->make('skimia.assets.scanner');
107 }
108 }
109