mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 06:27:59 +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()
|
public function handle()
|
||||||
{
|
{
|
||||||
$images = Image::all();
|
$this->info("Regenerating Images");
|
||||||
|
$progressBar = $this->output->createProgressBar(Image::count());
|
||||||
|
|
||||||
|
Image::chunk(1000, function($images) use ($progressBar) {
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
$this->info("Regenerating images for id:".$image->id. " (".$image->filename.")");
|
|
||||||
$image->clearExisting();
|
$image->clearExisting();
|
||||||
|
|
||||||
$originalFile = new File($image->getFile(Image::ORIGINAL));
|
$originalFile = new File($image->getFile(Image::ORIGINAL));
|
||||||
foreach (Image::$ImageTypes as $imageType) {
|
foreach (Image::$ImageTypes as $imageType) {
|
||||||
Image::processFile($originalFile, $image->getFile($imageType['id']), $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
|
* 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());
|
$files = scandir($this->getDirectory());
|
||||||
$filePrefix = $this->id.'_';
|
$filePrefix = $this->id.'_';
|
||||||
$originalName = $filePrefix.Image::$ImageTypes[Image::ORIGINAL]['name'];
|
$originalName = $filePrefix.Image::$ImageTypes[Image::ORIGINAL]['name'];
|
||||||
|
|
||||||
$files = array_filter($files, function($file) use ($originalName, $includeOriginal, $filePrefix) {
|
$files = array_filter($files, function($file) use ($originalName, $includeOriginal, $filePrefix) {
|
||||||
if (Str::startsWith($file,$originalName) && !$includeOriginal) return false;
|
if (Str::startsWith($file,$originalName) && !$includeOriginal) {
|
||||||
else return (Str::startsWith($file, $filePrefix));
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return (Str::startsWith($file, $filePrefix));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|
Loading…
Reference in a new issue