1
0
cms11/app/Console/Commands/Bundle/Upgrade.php

87 lines
2.8 KiB
PHP

<?php
namespace App\Console\Commands\Bundle;
use App\Classes\Bundle;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class Upgrade extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'bundle:upgrade { path? : Specific bundle to upgrade }';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Upgrade bundles from previous CMS version';
/**
* Execute the console command.
*/
public function handle()
{
$disk = Storage::disk(env('CONTENT_DISK'));
$path = $this->argument('path') ?? '/';
$bundles = Bundle::findBundles($disk, $path, true);
foreach ($bundles as $bundle) {
$this->output->write(sprintf('Upgrading %s... ', $bundle->getPath()));
$currentOtherKeywords = $bundle->metadata('metadata')->get('Autres mots-clé', []);
$currentKeywords = $bundle->metadata('metadata')->get('Mots-clé', []);
$merged = array_replace_recursive($currentKeywords, $currentOtherKeywords);
if (!empty($merged)) {
$bundle->metadata('metadata')->set('Autres mots-clé', $merged);
$bundle->metadata('metadata')->remove('Mots-clé');
}
$currentPeople = $bundle->metadata('metadata')->get('miscPeople');
if (!empty($currentPeople)) {
$bundle->metadata('metadata')->set('Personnalités', $currentPeople);
$bundle->metadata('metadata')->remove('miscPeople');
}
$currentLinks = $bundle->metadata('metadata')->get('links');
if (!empty($currentLinks)) {
$bundle->metadata('metadata')->set('Liens', $currentLinks);
$bundle->metadata('metadata')->remove('links');
}
$currentDetails = $bundle->metadata('metadata')->get('details');
if (!empty($currentDetails)) {
$bundle->metadata('metadata')->set('Détails', $currentDetails);
$bundle->metadata('metadata')->remove('details');
}
$currentTheme = $bundle->metadata('metadata')->get('theme');
if (!empty($currentTheme)) {
$bundle->metadata('metadata')->set('Thème', $currentTheme);
$bundle->metadata('metadata')->remove('theme');
}
$currentSagas = $bundle->metadata('metadata')->get('sagas');
if (!empty($currentSagas)) {
$bundle->metadata('metadata')->set('Sagas.Fait partie de', $currentSagas);
$bundle->metadata('metadata')->remove('sagas');
}
$bundle->save();
$this->info('OK');
}
}
}