69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Console\Commands\Bundle;
|
||
|
|
||
|
use App\Classes\Bundle;
|
||
|
use App\Exceptions\BundleUpdaterCannotBeFound;
|
||
|
use App\Exceptions\UnableToFindWikidataEntityId;
|
||
|
use App\Services\BundleUpdaters\Facades\BundleUpdater;
|
||
|
use Illuminate\Console\Command;
|
||
|
use Illuminate\Support\Facades\Storage;
|
||
|
|
||
|
class Update extends Command
|
||
|
{
|
||
|
/**
|
||
|
* The name and signature of the console command.
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $signature = 'bundle:update { path? : Path to a specific bundle to update }';
|
||
|
|
||
|
/**
|
||
|
* The console command description.
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $description = 'Update bundles extended metadata';
|
||
|
|
||
|
/**
|
||
|
* Execute the console command.
|
||
|
*/
|
||
|
public function handle()
|
||
|
{
|
||
|
$path = $this->argument('path') ?? '/';
|
||
|
$bundles = Bundle::findBundles(Storage::disk(env('CONTENT_DISK')), $path, true);
|
||
|
|
||
|
foreach ($bundles as $bundle) {
|
||
|
$this->output->write(sprintf('Updating %s... ', $bundle->getPath()));
|
||
|
|
||
|
try {
|
||
|
$updater = BundleUpdater::getBundleUpdaterFor($bundle);
|
||
|
} catch (BundleUpdaterCannotBeFound $ex) {
|
||
|
$this->line('Not updatable');
|
||
|
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
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->comment('Unable to find wikidata entity Id');
|
||
|
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
$updater->update();
|
||
|
|
||
|
$this->info('OK');
|
||
|
}
|
||
|
}
|
||
|
}
|