mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-21 20:48:00 +01:00
Some small changes
This commit is contained in:
parent
cd348dff7d
commit
e5c5dec14a
2 changed files with 21 additions and 12 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue