signature = 'bundle:update { --r|recursive : Also update sub-bundles } { --source-disk= : Use specified content disk - Defaults to ' . env('CONTENT_DISK') . ' } { path? : Path to a specific bundle to update - Default to / } '; parent::__construct(); } /** * Execute the console command. */ public function handle() { $this->selectDisk() ->selectBundles() ->update() ->showReport(); } /** * Updates specific bundle */ private function handleBundle(Bundle $bundle, $progress) { $progress->hint(sprintf('Updated %s', $bundle->getPath())); try { $updater = BundleUpdater::getBundleUpdaterFor($bundle); } catch (BundleUpdaterCannotBeFound $ex) { return; } try { while (!$updater->canUpdateBundle()) { $specs = $updater->formSpecs(); foreach ($specs as $key => $func) { $result = $func(); $bundle->metadata()->set($key, $result); $bundle->save(); } } } catch (UnableToFindWikidataEntityId $ex) { $this->notUpdatable[$bundle->getPath()] = 'Missing Wikidata Entity Id'; return; } $result = $updater->update(); if ($result) { $this->updatedCount++; } else { $this->notUpdatedCount++; } } /** * Performs update on selected bundles */ private function update(): self { progress('Updating bundles...', $this->bundles, function (Bundle $bundle, $progress) { $this->handleBundle($bundle, $progress); }); return $this; } /** * Show a report of update procedure */ private function showReport() { $this->line(sprintf('Updated bundles: %d', $this->updatedCount)); $this->line(sprintf('Update not needed: %d', $this->notUpdatedCount)); $this->reportNonUpdatable(); } /** * Show report of non updatable bundles */ private function reportNonUpdatable() { $count = count($this->notUpdatable); if ($count === 0) { return; } $this->newLine(); $this->line(sprintf('Not updatable bundles: %d', $count)); foreach ($this->notUpdatable as $bundle => $reason) { $this->newLine(); $this->comment($bundle); $this->line(sprintf(' > %s', $reason)); } } }