Some small changes

This commit is contained in:
Isaac 2017-11-28 11:19:36 -08:00
parent cd348dff7d
commit e5c5dec14a
2 changed files with 21 additions and 12 deletions

View file

@ -56,15 +56,20 @@ class RebuildImages extends Command
*/
public function handle()
{
$images = Image::all();
foreach ($images as $image) {
$this->info("Regenerating images for id:".$image->id. " (".$image->filename.")");
$image->clearExisting();
$this->info("Regenerating Images");
$progressBar = $this->output->createProgressBar(Image::count());
$originalFile = new File($image->getFile(Image::ORIGINAL));
foreach (Image::$ImageTypes as $imageType) {
Image::processFile($originalFile, $image->getFile($imageType['id']), $imageType);
Image::chunk(1000, function($images) use ($progressBar) {
foreach ($images as $image) {
$image->clearExisting();
$originalFile = new File($image->getFile(Image::ORIGINAL));
foreach (Image::$ImageTypes as $imageType) {
Image::processFile($originalFile, $image->getFile($imageType['id']), $imageType);
}
$progressBar->advance();
}
}
});
}
}

View file

@ -196,16 +196,20 @@ class Image extends Model
/**
* Deletes any generated files if they exist
* @param bool $includeOriginal Deletes
* @param bool $includeOriginal Set to true if the original image should be deleted as well.
*/
public function clearExisting($includeOriginal = false) {
public function clearExisting(bool $includeOriginal = false) {
$files = scandir($this->getDirectory());
$filePrefix = $this->id.'_';
$originalName = $filePrefix.Image::$ImageTypes[Image::ORIGINAL]['name'];
$files = array_filter($files, function($file) use ($originalName, $includeOriginal, $filePrefix) {
if (Str::startsWith($file,$originalName) && !$includeOriginal) return false;
else return (Str::startsWith($file, $filePrefix));
if (Str::startsWith($file,$originalName) && !$includeOriginal) {
return false;
}
else {
return (Str::startsWith($file, $filePrefix));
}
});
foreach ($files as $file) {