96 lines
3.3 KiB
PHP
96 lines
3.3 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()));
|
|
|
|
$disk->move($bundle->getPath() . 'images', $bundle->getDataDir() . 'attachments/images');
|
|
$disk->move($bundle->getPath() . 'sounds', $bundle->getDataDir() . 'attachments/sounds');
|
|
$disk->move($bundle->getPath() . 'videos', $bundle->getDataDir() . 'attachments/videos');
|
|
$disk->move($bundle->getPath() . 'index.json', $bundle->getDataDir() . 'index.json');
|
|
$disk->move($bundle->getPath() . 'metadata.json', $bundle->getDataDir() . 'metadata.json');
|
|
|
|
if ($disk->exists($bundle->getPath() . 'attachments.json')) {
|
|
$attachments = json_decode($disk->get($bundle->getPath() . 'attachments.json'), true);
|
|
$images = [];
|
|
$sounds = [];
|
|
$videos = [];
|
|
|
|
foreach ($attachments as $ref => $data) {
|
|
$kind = $data['kind'];
|
|
|
|
$data['filename'] = 'attachments/' . $data['url'];
|
|
|
|
unset($data['url']);
|
|
unset($data['kind']);
|
|
|
|
switch ($kind) {
|
|
case 'images':
|
|
$images['files'][$ref] = $data;
|
|
break;
|
|
case 'sounds':
|
|
$sounds['files'][$ref] = $data;
|
|
break;
|
|
case 'videos':
|
|
$videos['files'][$ref] = $data;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!empty($images)) {
|
|
$disk->put($bundle->getDataDir() . 'images.json', json_encode($images, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
|
}
|
|
|
|
if (!empty($sounds)) {
|
|
$disk->put($bundle->getDataDir() . 'sounds.json', json_encode($sounds, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
|
}
|
|
|
|
if (!empty($videos)) {
|
|
$disk->put($bundle->getDataDir() . 'videos.json', json_encode($videos, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
|
}
|
|
}
|
|
|
|
$filesToDelete = [
|
|
'links.json',
|
|
'attachments.json',
|
|
];
|
|
|
|
$filesToDelete = array_map(fn ($filename) => $bundle->getPath() . $filename, $filesToDelete);
|
|
|
|
$disk->delete($filesToDelete);
|
|
|
|
$this->info('OK');
|
|
}
|
|
}
|
|
}
|