1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-17 21:00:09 -07:00

Improve ImageLoader

This commit is contained in:
Unknown 2017-06-08 18:06:07 +02:00
parent 11f1d9eec1
commit f1d1f3df62
2 changed files with 27 additions and 14 deletions

View File

@ -117,7 +117,7 @@ abstract class BaseLoader
if (false === file_put_contents($temp, fopen($url, 'r', 0, $ctx))) {
throw new WriteErrorException($temp);
}
} catch (ContextErrorException $e) {
} catch (\ErrorException $e) {
throw new FileNotFoundException($url);
} catch (\Exception $e) {
throw new LogicException($e);

View File

@ -29,8 +29,9 @@ class ImageLoader extends BaseLoader
}
/**
* @param $color
* @param null $path
* Download ZIP file with part images from rebrickable and unzip file to filesystem
*
* @param integer $color color id used by rebrickable
*/
public function loadColorFromRebrickable($color)
{
@ -47,34 +48,46 @@ class ImageLoader extends BaseLoader
$zip->close();
$this->output->writeln(['Done!']);
} else {
$this->output->writeln(['<error>Extraction of file failed!</error>']);
$this->logger->error('Extraction of file failed!');
}
}
/**
* Load images of models.
* Load missing images of models
*/
public function loadMissingModelImages()
{
// Get models without image
$missing = [];
$models = $this->em->getRepository(Model::class)->findAll();
$this->initProgressBar(count($models));
foreach ($models as $model) {
$this->progressBar->setMessage($model->getId());
if (!$this->mediaFilesystem->has('images'.DIRECTORY_SEPARATOR.'-1'.DIRECTORY_SEPARATOR.$model->getId().'.png')) {
try {
$this->loadModelImage($this->mediaFilesystem->getAdapter()->getPathPrefix().$model->getPath());
} catch (\Exception $e) {
dump($e->getMessage());
}
$missing[] = $model;
}
}
unset($models);
// Render images
$this->output->writeln([
"Rendering missing images of models",
]);
$this->initProgressBar(count($missing));
foreach ($missing as $model) {
$this->progressBar->setMessage($model->getId());
try {
$this->loadModelImage($this->mediaFilesystem->getAdapter()->getPathPrefix().$model->getPath());
} catch (\Exception $e) {
$this->logger->error('Error rendering model '.$model->getId().' image', $e);
}
$this->progressBar->advance();
}
$this->progressBar->finish();
}
/**
* Render model and save image into co.
* Render model and save image into
*
* @param $file
*/