oc-resizer-plugin/console/ClearOld.php

64 lines
1.5 KiB
PHP

<?php namespace Aweos\Resizer\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class ClearOld extends Command
{
/**
* @var string The console command name.
*/
protected $name = 'resizer:clearold';
/**
* @var string The console command description.
*/
protected $description = 'No description provided yet...';
/**
* Execute the console command.
* @return void
*/
public function handle()
{
foreach (\Aweos\Base\Models\OfferKitchen::get() as $k) {
$newImages = collect($k->images)->map(function($image) {
if (!strpos($image['image'], 'cropped-images')) {
return $image;
}
$n = preg_replace('/-(\d+-){4}\d+/', '', $image['image']);
$n = str_replace('cropped-images/', '', $n);
if (!\Storage::has('media'.$n)) {
return $image;
}
$image['image'] = $n;
return $image;
});
$k->update(['images' => $newImages]);
}
}
/**
* Get the console command arguments.
* @return array
*/
protected function getArguments()
{
return [];
}
/**
* Get the console command options.
* @return array
*/
protected function getOptions()
{
return [];
}
}