Commit 1def1ae5 authored by Nicolas Widart's avatar Nicolas Widart

Adding a refresh thumbnail command

parent 6ae7f9f3
<?php namespace Modules\Media\Console;
use Illuminate\Console\Command;
use Modules\Media\Image\Imagy;
use Modules\Media\Repositories\FileRepository;
class RefreshThumbnailCommand extends Command
{
protected $name = 'media:thumb-refresh';
protected $description = 'Create and or refresh the thumbnails';
/**
* @var Imagy
*/
private $imagy;
/**
* @var FileRepository
*/
private $file;
public function __construct(Imagy $imagy, FileRepository $file)
{
parent::__construct();
$this->imagy = $imagy;
$this->file = $file;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$this->line('Preparing to regenerate all thumbnails...');
foreach ($this->file->all() as $file) {
$this->imagy->createAll($file->path);
}
$this->info('All thumbnails refreshed');
}
}
<?php namespace Modules\Media\Providers;
use Illuminate\Support\ServiceProvider;
use Modules\Media\Console\RefreshThumbnailCommand;
use Modules\Media\Entities\File;
use Modules\Media\Image\Imagy;
use Modules\Media\Image\Intervention\InterventionFactory;
use Modules\Media\Image\ThumbnailsManager;
use Modules\Media\Repositories\Eloquent\EloquentFileRepository;
class MediaServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
......@@ -24,6 +27,7 @@ class MediaServiceProvider extends ServiceProvider
$this->app->booted(function () {
$this->registerBindings();
});
$this->registerCommands();
}
/**
......@@ -46,4 +50,27 @@ class MediaServiceProvider extends ServiceProvider
);
}
/**
* Register all commands for this module
*/
private function registerCommands()
{
$this->registerRefreshCommand();
}
/**
* Register the refresh thumbnails command
*/
private function registerRefreshCommand()
{
$this->app->bindShared('command.media.refresh', function($app) {
$thumbnailManager = new ThumbnailsManager($app['config'], $app['modules']);
$imagy = new Imagy(new InterventionFactory, $thumbnailManager);
return new RefreshThumbnailCommand($imagy, $app['Modules\Media\Repositories\FileRepository']);
});
$this->commands(
'command.media.refresh'
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment