diff --git a/app/config/service/loader.yml b/app/config/service/loader.yml index 583be0c..2fb30a7 100644 --- a/app/config/service/loader.yml +++ b/app/config/service/loader.yml @@ -7,7 +7,7 @@ services: service.ldview: class: AppBundle\Service\LDViewService - arguments: ['%ldview_bin%', '@oneup_flysystem.media_filesystem', '@oneup_flysystem.ldraw_library_filesystem'] + arguments: ['%ldview_bin%', '@oneup_flysystem.media_filesystem'] service.loader.rebrickable: class: AppBundle\Service\Loader\RebrickableLoaderService diff --git a/src/AppBundle/Exception/ConvertingFailedException.php b/src/AppBundle/Exception/ConvertingFailedException.php new file mode 100644 index 0000000..d16c2be --- /dev/null +++ b/src/AppBundle/Exception/ConvertingFailedException.php @@ -0,0 +1,36 @@ +filepath = $filepath; + } + + /** + * @return mixed + */ + public function getFilepath() + { + return $this->filepath; + } + + /** + * @param mixed $filepath + */ + public function setFilepath($filepath) + { + $this->filepath = $filepath; + } + + +} \ No newline at end of file diff --git a/src/AppBundle/Exception/FileNotFoundException.php b/src/AppBundle/Exception/FileNotFoundException.php index dbacf85..3e12a65 100644 --- a/src/AppBundle/Exception/FileNotFoundException.php +++ b/src/AppBundle/Exception/FileNotFoundException.php @@ -1,15 +1,9 @@ filepath = $filepath; + } + + /** + * @return mixed + */ + public function getFilepath() + { + return $this->filepath; + } + + /** + * @param mixed $filepath + */ + public function setFilepath($filepath) + { + $this->filepath = $filepath; + } +} \ No newline at end of file diff --git a/src/AppBundle/Repository/Rebrickable/InventoryRepository.php b/src/AppBundle/Repository/Rebrickable/InventoryRepository.php index 6776c3b..0158186 100644 --- a/src/AppBundle/Repository/Rebrickable/InventoryRepository.php +++ b/src/AppBundle/Repository/Rebrickable/InventoryRepository.php @@ -2,8 +2,19 @@ namespace AppBundle\Repository\Rebrickable; +use AppBundle\Entity\Rebrickable\Set; use AppBundle\Repository\BaseRepository; class InventoryRepository extends BaseRepository { + public function findNewestInventoryBySetNumber($number) { + + $queryBuilder = $this->createQueryBuilder('inventory') + ->where('inventory.set = :setNumber') + ->setParameter('setNumber', $number) + ->orderBy('inventory.version','DESC') + ->setMaxResults(1); + + return $queryBuilder->getQuery()->getOneOrNullResult(); + } } diff --git a/src/AppBundle/Service/LDViewService.php b/src/AppBundle/Service/LDViewService.php index 033dbb5..8f1631f 100644 --- a/src/AppBundle/Service/LDViewService.php +++ b/src/AppBundle/Service/LDViewService.php @@ -2,10 +2,13 @@ namespace AppBundle\Service; +use AppBundle\Exception\ConvertingFailedException; +use AppBundle\Exception\FileNotFoundException; use League\Flysystem\File; use League\Flysystem\Filesystem; use Symfony\Component\Asset\Exception\LogicException; use Symfony\Component\Finder\Finder; +use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\ProcessBuilder; //TODO enable file overwrite @@ -33,13 +36,11 @@ class LDViewService * * @param string $ldview Path to LDView OSMesa binary file * @param Filesystem $mediaFilesystem Filesystem for generated web assets - * @param Filesystem $ldrawLibraryFilesystem Filesystem with ldraw source files library */ - public function __construct($ldview, $mediaFilesystem, $ldrawLibraryFilesystem) + public function __construct($ldview, $mediaFilesystem) { $this->ldview = $ldview; $this->mediaFilesystem = $mediaFilesystem; - $this->ldrawLibraryFilesystem = $ldrawLibraryFilesystem; } /** @@ -54,9 +55,10 @@ class LDViewService * Convert LDraw model from .dat format to .stl by using LDView * stores created file to $stlStorage filesystem. * - * @param Filesystem $LDrawDir + * @param $file * * @return File + * @throws ConvertingFailedException */ public function datToStl($file) { @@ -79,7 +81,7 @@ class LDViewService // Check if file created successfully if (!$this->mediaFilesystem->has($newFile)) { - throw new LogicException($newFile.': new file not found'); //TODO + throw new ConvertingFailedException($newFile); } } @@ -90,9 +92,10 @@ class LDViewService * Convert LDraw model from .dat format to .stl by using LDView * stores created file to $stlStorage filesystem. * - * @param Filesystem $LDrawDir + * @param $file * * @return File + * @throws ConvertingFailedException */ public function datToPng($file) { @@ -124,7 +127,7 @@ class LDViewService // Check if file created successfully if (!$this->mediaFilesystem->has($newFile)) { - throw new LogicException($newFile.': new file not found'); //TODO + throw new ConvertingFailedException($newFile); } } @@ -147,7 +150,7 @@ class LDViewService $process->run(); if (!$process->isSuccessful()) { - throw new LogicException($process->getOutput()); //TODO + throw new ProcessFailedException($process); //TODO } } }