mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-17 21:00:09 -07:00
Add loader exceptions
This commit is contained in:
parent
814138aeb2
commit
59eff0e0bd
@ -7,7 +7,7 @@ services:
|
|||||||
|
|
||||||
service.ldview:
|
service.ldview:
|
||||||
class: AppBundle\Service\LDViewService
|
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:
|
service.loader.rebrickable:
|
||||||
class: AppBundle\Service\Loader\RebrickableLoaderService
|
class: AppBundle\Service\Loader\RebrickableLoaderService
|
||||||
|
36
src/AppBundle/Exception/ConvertingFailedException.php
Normal file
36
src/AppBundle/Exception/ConvertingFailedException.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AppBundle\Exception;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class ConvertingFailedException extends \Exception
|
||||||
|
{
|
||||||
|
private $filepath;
|
||||||
|
|
||||||
|
public function __construct($filepath = "", $message = "", $code = 0, Exception $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
|
||||||
|
$this->filepath = $filepath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getFilepath()
|
||||||
|
{
|
||||||
|
return $this->filepath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $filepath
|
||||||
|
*/
|
||||||
|
public function setFilepath($filepath)
|
||||||
|
{
|
||||||
|
$this->filepath = $filepath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: hubnedav
|
|
||||||
* Date: 4/6/17
|
|
||||||
* Time: 2:31 PM
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace AppBundle\Exception;
|
namespace AppBundle\Exception;
|
||||||
|
|
||||||
|
|
||||||
class FileNotFoundException extends \Exception
|
class FileNotFoundException extends \Symfony\Component\Filesystem\Exception\FileNotFoundException
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
32
src/AppBundle/Exception/ParseErrorException.php
Normal file
32
src/AppBundle/Exception/ParseErrorException.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AppBundle\Exception;
|
||||||
|
|
||||||
|
|
||||||
|
class ParseErrorException extends \Exception
|
||||||
|
{
|
||||||
|
private $filepath;
|
||||||
|
|
||||||
|
public function __construct($filepath = "", $message = "", $code = 0, Exception $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
|
||||||
|
$this->filepath = $filepath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getFilepath()
|
||||||
|
{
|
||||||
|
return $this->filepath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $filepath
|
||||||
|
*/
|
||||||
|
public function setFilepath($filepath)
|
||||||
|
{
|
||||||
|
$this->filepath = $filepath;
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,19 @@
|
|||||||
|
|
||||||
namespace AppBundle\Repository\Rebrickable;
|
namespace AppBundle\Repository\Rebrickable;
|
||||||
|
|
||||||
|
use AppBundle\Entity\Rebrickable\Set;
|
||||||
use AppBundle\Repository\BaseRepository;
|
use AppBundle\Repository\BaseRepository;
|
||||||
|
|
||||||
class InventoryRepository extends 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,13 @@
|
|||||||
|
|
||||||
namespace AppBundle\Service;
|
namespace AppBundle\Service;
|
||||||
|
|
||||||
|
use AppBundle\Exception\ConvertingFailedException;
|
||||||
|
use AppBundle\Exception\FileNotFoundException;
|
||||||
use League\Flysystem\File;
|
use League\Flysystem\File;
|
||||||
use League\Flysystem\Filesystem;
|
use League\Flysystem\Filesystem;
|
||||||
use Symfony\Component\Asset\Exception\LogicException;
|
use Symfony\Component\Asset\Exception\LogicException;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
|
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||||
use Symfony\Component\Process\ProcessBuilder;
|
use Symfony\Component\Process\ProcessBuilder;
|
||||||
|
|
||||||
//TODO enable file overwrite
|
//TODO enable file overwrite
|
||||||
@ -33,13 +36,11 @@ class LDViewService
|
|||||||
*
|
*
|
||||||
* @param string $ldview Path to LDView OSMesa binary file
|
* @param string $ldview Path to LDView OSMesa binary file
|
||||||
* @param Filesystem $mediaFilesystem Filesystem for generated web assets
|
* @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->ldview = $ldview;
|
||||||
$this->mediaFilesystem = $mediaFilesystem;
|
$this->mediaFilesystem = $mediaFilesystem;
|
||||||
$this->ldrawLibraryFilesystem = $ldrawLibraryFilesystem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,9 +55,10 @@ class LDViewService
|
|||||||
* Convert LDraw model from .dat format to .stl by using LDView
|
* Convert LDraw model from .dat format to .stl by using LDView
|
||||||
* stores created file to $stlStorage filesystem.
|
* stores created file to $stlStorage filesystem.
|
||||||
*
|
*
|
||||||
* @param Filesystem $LDrawDir
|
* @param $file
|
||||||
*
|
*
|
||||||
* @return File
|
* @return File
|
||||||
|
* @throws ConvertingFailedException
|
||||||
*/
|
*/
|
||||||
public function datToStl($file)
|
public function datToStl($file)
|
||||||
{
|
{
|
||||||
@ -79,7 +81,7 @@ class LDViewService
|
|||||||
|
|
||||||
// Check if file created successfully
|
// Check if file created successfully
|
||||||
if (!$this->mediaFilesystem->has($newFile)) {
|
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
|
* Convert LDraw model from .dat format to .stl by using LDView
|
||||||
* stores created file to $stlStorage filesystem.
|
* stores created file to $stlStorage filesystem.
|
||||||
*
|
*
|
||||||
* @param Filesystem $LDrawDir
|
* @param $file
|
||||||
*
|
*
|
||||||
* @return File
|
* @return File
|
||||||
|
* @throws ConvertingFailedException
|
||||||
*/
|
*/
|
||||||
public function datToPng($file)
|
public function datToPng($file)
|
||||||
{
|
{
|
||||||
@ -124,7 +127,7 @@ class LDViewService
|
|||||||
|
|
||||||
// Check if file created successfully
|
// Check if file created successfully
|
||||||
if (!$this->mediaFilesystem->has($newFile)) {
|
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();
|
$process->run();
|
||||||
|
|
||||||
if (!$process->isSuccessful()) {
|
if (!$process->isSuccessful()) {
|
||||||
throw new LogicException($process->getOutput()); //TODO
|
throw new ProcessFailedException($process); //TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user