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))) { if (false === file_put_contents($temp, fopen($url, 'r', 0, $ctx))) {
throw new WriteErrorException($temp); throw new WriteErrorException($temp);
} }
} catch (ContextErrorException $e) { } catch (\ErrorException $e) {
throw new FileNotFoundException($url); throw new FileNotFoundException($url);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new LogicException($e); throw new LogicException($e);

View File

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