signature = 'bundle:repair { --r|recursive : Also repair sub-bundles } { --source-disk= : Use specified content disk - Defaults to ' . env('CONTENT_DISK') . ' } { path? : Path to a specific bundle to repair - Default to / } '; parent::__construct(); } /** * Execute the console command. */ public function handle() { $this->selectDisk() ->selectBundles() ->repair(); foreach (['blog', 'liens-interessants'] as $section) { $this->createIntermediateBundles($section); } } /** * Create intermediary bundles */ private function createIntermediateBundles($parent) { $disk = $this->sourceDisk; foreach ($disk->directories($parent) as $dir) { if (basename($dir) === 'data') { continue; } $bundle = new Bundle($dir, $disk); if (!$bundle->exists()) { $bundle->markdown()->set(''); $parts = preg_split('#/#', $bundle->getPath(), -1, PREG_SPLIT_NO_EMPTY); $count = count($parts); switch ($count) { case 2: // A year is specified $date = sprintf('%s-%s-%s', $parts[1], '01', '01'); $date = Carbon::parse($date); $articleTitle = sprintf('Publiés en %s', $date->isoFormat('YYYY')); break; case 3: // A month is specified $date = sprintf('%s-%s-%s', $parts[1], $parts[2], '01'); $date = Carbon::parse($date); $articleTitle = sprintf('Publiés en %s', $date->isoFormat('MMMM YYYY')); break; case 4: // A day is specified $date = sprintf('%s-%s-%s', $parts[1], $parts[2], $parts[3]); $date = Carbon::parse($date); $articleTitle = sprintf('Publiés le %s', $date->isoFormat('DD MMMM YYYY')); break; } if (!empty($articleTitle)) { $bundle->metadata()->set('title', $articleTitle); } $bundle->save(); } $this->createIntermediateBundles($bundle->getPath()); } } /** * Repair bundles */ private function repair() { progress('Repairing bundles...', $this->bundles, function (Bundle $bundle, $progress) { $this->handleBundle($bundle, $progress); }); } /** * Repair specific bundle */ private function handleBundle(Bundle $bundle, $progress) { $bundle->repair(); $progress->label(sprintf('Repaired %s', $bundle->getPath())); } }