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

Fix coding style

This commit is contained in:
Unknown 2017-06-02 03:27:22 +02:00
parent 71bb607772
commit 85ec4e5481
28 changed files with 82 additions and 79 deletions

View File

@ -21,7 +21,7 @@ services:
service.set: service.set:
class: AppBundle\Service\SetService class: AppBundle\Service\SetService
arguments: ['@repository.rebrickable.inventorypart'] arguments: ['@repository.rebrickable.inventoryPart']
service.model: service.model:
class: AppBundle\Service\ModelService class: AppBundle\Service\ModelService

View File

@ -38,6 +38,8 @@ class Rebrickable_v3
* @param $uri * @param $uri
* @param array $options * @param array $options
* *
* @throws ApiException
*
* @return string * @return string
*/ */
public function call($method, $uri, $options = []) public function call($method, $uri, $options = [])

View File

@ -20,6 +20,7 @@ class BricksetManager
* BricksetManager constructor. * BricksetManager constructor.
* *
* @param Brickset $bricksetClient * @param Brickset $bricksetClient
* @param CacheProvider $cache
*/ */
public function __construct(Brickset $bricksetClient, CacheProvider $cache) public function __construct(Brickset $bricksetClient, CacheProvider $cache)
{ {

View File

@ -4,7 +4,6 @@ namespace AppBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -20,7 +19,7 @@ class InitDataCommand extends ContainerAwareCommand
->setHelp('This command allows you to load initial data of models and sets into aplication') ->setHelp('This command allows you to load initial data of models and sets into aplication')
->setDefinition( ->setDefinition(
new InputDefinition([ new InputDefinition([
new InputOption('ldraw', 'l',InputOption::VALUE_OPTIONAL, 'Path to LDraw library directory'), new InputOption('ldraw', 'l', InputOption::VALUE_OPTIONAL, 'Path to LDraw library directory'),
]) ])
); );
} }
@ -34,7 +33,7 @@ class InitDataCommand extends ContainerAwareCommand
'--all' => true, '--all' => true,
]; ];
if($ldraw = $input->getOption('ldraw')) { if ($ldraw = $input->getOption('ldraw')) {
$loadModelsInput['--ldraw'] = $ldraw; $loadModelsInput['--ldraw'] = $ldraw;
} }

View File

@ -5,7 +5,6 @@ namespace AppBundle\Command;
use AppBundle\Service\Loader\ModelLoader; use AppBundle\Service\Loader\ModelLoader;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\LockableTrait; use Symfony\Component\Console\Command\LockableTrait;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -50,7 +49,7 @@ class LoadModelsCommand extends ContainerAwareCommand
return 1; return 1;
} }
if($ldraw = $input->getOption('ldraw')) { if ($ldraw = $input->getOption('ldraw')) {
$modelLoader->setLDrawLibraryContext(realpath($ldraw)); $modelLoader->setLDrawLibraryContext(realpath($ldraw));
} else { } else {
$ldraw = $modelLoader->downloadLibrary($this->getContainer()->getParameter('app.ld_library_download_url')); $ldraw = $modelLoader->downloadLibrary($this->getContainer()->getParameter('app.ld_library_download_url'));

View File

@ -20,6 +20,7 @@ class DefaultController extends Controller
/** @var SetRepository $setRepository */ /** @var SetRepository $setRepository */
$setRepository = $this->get('repository.rebrickable.set'); $setRepository = $this->get('repository.rebrickable.set');
return $this->render('default/index.html.twig', [ return $this->render('default/index.html.twig', [
'models' => $modelRepository->count(), 'models' => $modelRepository->count(),
'sets' => $setRepository->count(), 'sets' => $setRepository->count(),

View File

@ -33,7 +33,7 @@ class ModelController extends Controller
$form->handleRequest($request); $form->handleRequest($request);
$elasticaManager = $this->get('fos_elastica.manager'); $elasticaManager = $this->get('fos_elastica.manager');
$results = $elasticaManager->getRepository(Model::class)->search($modelSearch,5000); $results = $elasticaManager->getRepository(Model::class)->search($modelSearch, 5000);
/** @var Paginator $paginator */ /** @var Paginator $paginator */
$paginator = $this->get('knp_paginator'); $paginator = $this->get('knp_paginator');
@ -94,7 +94,7 @@ class ModelController extends Controller
$response->headers->set('Content-Type', 'application/zip'); $response->headers->set('Content-Type', 'application/zip');
// escape forbidden characters from filename // escape forbidden characters from filename
$filename = preg_replace('/[^a-z0-9\.]/i', '_',"model_{$model->getId()}_{$model->getName()}.zip"); $filename = preg_replace('/[^a-z0-9\.]/i', '_', "model_{$model->getId()}_{$model->getName()}.zip");
// Create the disposition of the file // Create the disposition of the file
$disposition = $response->headers->makeDisposition( $disposition = $response->headers->makeDisposition(

View File

@ -4,7 +4,6 @@ namespace AppBundle\Controller;
use AppBundle\Api\Exception\EmptyResponseException; use AppBundle\Api\Exception\EmptyResponseException;
use AppBundle\Entity\Rebrickable\Part; use AppBundle\Entity\Rebrickable\Part;
use AppBundle\Entity\Rebrickable\Set;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
@ -24,8 +23,8 @@ class PartController extends Controller
{ {
$apiPart = null; $apiPart = null;
if ($part) { if ($part) {
if($model = $part->getModel()) { if ($model = $part->getModel()) {
$this->redirectToRoute('model_detail',['id' => $model->getId()]); $this->redirectToRoute('model_detail', ['id' => $model->getId()]);
} }
try { try {

View File

@ -9,9 +9,7 @@ use AppBundle\Model\SetSearch;
use AppBundle\Repository\Search\ModelRepository; use AppBundle\Repository\Search\ModelRepository;
use AppBundle\Repository\Search\SetRepository; use AppBundle\Repository\Search\SetRepository;
use FOS\ElasticaBundle\HybridResult; use FOS\ElasticaBundle\HybridResult;
use FOS\ElasticaBundle\Repository;
use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Cache\Resolver\CacheResolver;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
@ -81,7 +79,7 @@ class SearchController extends Controller
'id' => $id, 'id' => $id,
'name' => $name, 'name' => $name,
'url' => $this->generateUrl('model_detail', ['id' => $model->getTransformed()->getId()]), 'url' => $this->generateUrl('model_detail', ['id' => $model->getTransformed()->getId()]),
'img' => $liip->getBrowserPath('-1/'.$model->getTransformed()->getId().'.png','part_min'), 'img' => $liip->getBrowserPath('-1/'.$model->getTransformed()->getId().'.png', 'part_min'),
]; ];
} }
@ -95,7 +93,7 @@ class SearchController extends Controller
'id' => $id, 'id' => $id,
'name' => $name, 'name' => $name,
'url' => $this->generateUrl('set_detail', ['id' => $set->getTransformed()->getId()]), 'url' => $this->generateUrl('set_detail', ['id' => $set->getTransformed()->getId()]),
'img' => $liip->getBrowserPath($set->getTransformed()->getId().'.jpg','set_min'), 'img' => $liip->getBrowserPath($set->getTransformed()->getId().'.jpg', 'set_min'),
]; ];
} }

View File

@ -34,7 +34,7 @@ class SetController extends Controller
/** @var SetRepository $setRepository */ /** @var SetRepository $setRepository */
$setRepository = $this->get('fos_elastica.manager')->getRepository(Set::class); $setRepository = $this->get('fos_elastica.manager')->getRepository(Set::class);
$results = $setRepository->search($setSearch,5000); $results = $setRepository->search($setSearch, 5000);
$paginator = $this->get('knp_paginator'); $paginator = $this->get('knp_paginator');
$sets = $paginator->paginate( $sets = $paginator->paginate(
@ -90,7 +90,6 @@ class SetController extends Controller
$setService = $this->get('service.set'); $setService = $this->get('service.set');
$inventoryPartRepository = $this->get('repository.rebrickable.inventoryPart'); $inventoryPartRepository = $this->get('repository.rebrickable.inventoryPart');
$models = $setService->getModels($set, false); $models = $setService->getModels($set, false);
$missing = $setService->getParts($set, false, false); $missing = $setService->getParts($set, false, false);
$missingCount = $inventoryPartRepository->getPartCount($set, false, false); $missingCount = $inventoryPartRepository->getPartCount($set, false, false);
@ -163,7 +162,7 @@ class SetController extends Controller
try { try {
$colors = $setService->getModelsGroupedByColor($set, false); $colors = $setService->getModelsGroupedByColor($set, false);
$missing = $setService->getParts($set,false,false); $missing = $setService->getParts($set, false, false);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->addFlash('error', $e->getMessage()); $this->addFlash('error', $e->getMessage());
} }

View File

@ -2,7 +2,6 @@
namespace AppBundle\DataFixtures\ORM; namespace AppBundle\DataFixtures\ORM;
use AppBundle\Entity\Color; use AppBundle\Entity\Color;
use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;

View File

@ -81,7 +81,8 @@ class Theme
return $this; return $this;
} }
public function getFullName() { public function getFullName()
{
$theme = $this; $theme = $this;
$name = []; $name = [];

View File

@ -60,8 +60,9 @@ class SetSearchType extends AbstractType
'choices' => $this->themeRepository->findAll(), 'choices' => $this->themeRepository->findAll(),
'choice_label' => 'fullName', 'choice_label' => 'fullName',
'choice_translation_domain' => false, 'choice_translation_domain' => false,
'group_by' => function($theme, $key, $index) { 'group_by' => function ($theme, $key, $index) {
$parent = $theme->getParent(); $parent = $theme->getParent();
return $parent ? $parent->getParent() ? $parent->getParent()->getName() : $parent->getName() : $theme->getName(); return $parent ? $parent->getParent() ? $parent->getParent()->getName() : $parent->getName() : $theme->getName();
}, },
'choice_value' => 'id', 'choice_value' => 'id',
@ -79,7 +80,7 @@ class SetSearchType extends AbstractType
$resolver->setDefaults([ $resolver->setDefaults([
'csrf_protection' => false, 'csrf_protection' => false,
'data_class' => SetSearch::class, 'data_class' => SetSearch::class,
'method' => 'GET' 'method' => 'GET',
]); ]);
} }

View File

@ -38,8 +38,9 @@ class PartImageLoader extends BaseImageLoader
// try to load image from rebrickable website // try to load image from rebrickable website
try { try {
if ($this->remoteFileExists($this->rebrickableContext.$path)) { if ($this->remoteFileExists($this->rebrickableContext.$path)) {
$context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n'))); $context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]);
return file_get_contents($this->rebrickableContext.strtolower($path),false,$context);
return file_get_contents($this->rebrickableContext.strtolower($path), false, $context);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $path), $e->getCode(), $e); throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $path), $e->getCode(), $e);

View File

@ -32,8 +32,9 @@ class SetImageLoader extends BaseImageLoader
// try to load image from rebrickable website // try to load image from rebrickable website
try { try {
if ($this->remoteFileExists($this->rebrickableContext.strtolower($path))) { if ($this->remoteFileExists($this->rebrickableContext.strtolower($path))) {
$context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n'))); $context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]);
return file_get_contents($this->rebrickableContext.strtolower($path),false,$context);
return file_get_contents($this->rebrickableContext.strtolower($path), false, $context);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $path), $e->getCode(), $e); throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $path), $e->getCode(), $e);

View File

@ -3,7 +3,6 @@
namespace AppBundle\Menu; namespace AppBundle\Menu;
use Knp\Menu\FactoryInterface; use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
class Builder class Builder
@ -26,7 +25,6 @@ class Builder
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
} }
public function mainMenu(array $options) public function mainMenu(array $options)
{ {
$request = $this->requestStack->getCurrentRequest(); $request = $this->requestStack->getCurrentRequest();
@ -37,7 +35,7 @@ class Builder
], ],
]); ]);
$models = $menu->addChild( 'page.model.index', [ $models = $menu->addChild('page.model.index', [
'route' => 'model_index', 'route' => 'model_index',
]); ]);
@ -46,7 +44,7 @@ class Builder
'routeParameters' => ['id' => $request->get('id', 0)], 'routeParameters' => ['id' => $request->get('id', 0)],
'display' => false, 'display' => false,
'extras' => [ 'extras' => [
'value' => $request->get('id', 0) 'value' => $request->get('id', 0),
], ],
]); ]);
@ -54,7 +52,7 @@ class Builder
'route' => 'set_index', 'route' => 'set_index',
'options' => [ 'options' => [
// 'icon' => 'edit', // 'icon' => 'edit',
] ],
]); ]);
$sets->addChild('page.set.detail', [ $sets->addChild('page.set.detail', [
@ -62,7 +60,7 @@ class Builder
'routeParameters' => ['id' => $request->get('id', 0)], 'routeParameters' => ['id' => $request->get('id', 0)],
'display' => false, 'display' => false,
'extras' => [ 'extras' => [
'value' => $request->get('id', 0) 'value' => $request->get('id', 0),
], ],
]); ]);
@ -70,7 +68,7 @@ class Builder
'route' => 'search_results', 'route' => 'search_results',
'display' => false, 'display' => false,
'extras' => [ 'extras' => [
'value' => $request->get('query', 0) 'value' => $request->get('query', 0),
], ],
]); ]);
@ -83,7 +81,7 @@ class Builder
'display' => false, 'display' => false,
'options' => [ 'options' => [
// 'icon' => 'edit', // 'icon' => 'edit',
] ],
]); ]);
$parts->addChild('page.part.detail', [ $parts->addChild('page.part.detail', [
@ -91,11 +89,10 @@ class Builder
'routeParameters' => ['id' => $request->get('id', 0)], 'routeParameters' => ['id' => $request->get('id', 0)],
'display' => false, 'display' => false,
'extras' => [ 'extras' => [
'value' => $request->get('id', 0) 'value' => $request->get('id', 0),
], ],
]); ]);
return $menu; return $menu;
} }
} }

View File

@ -14,6 +14,7 @@ class ModelSearch
/** /**
* ModelSearch constructor. * ModelSearch constructor.
*
* @param string $query * @param string $query
*/ */
public function __construct($query = '') public function __construct($query = '')

View File

@ -20,6 +20,7 @@ class SetSearch
/** /**
* SetSearch constructor. * SetSearch constructor.
*
* @param string $query * @param string $query
*/ */
public function __construct($query = '') public function __construct($query = '')

View File

@ -106,7 +106,8 @@ class ModelRepository extends BaseRepository
return $queryBuilder->getQuery()->getResult(); return $queryBuilder->getQuery()->getResult();
} }
public function count() { public function count()
{
$queryBuilder = $this->createQueryBuilder('model'); $queryBuilder = $this->createQueryBuilder('model');
$queryBuilder->select('count(model)'); $queryBuilder->select('count(model)');

View File

@ -73,7 +73,8 @@ class SetRepository extends BaseRepository
return $queryBuilder->getQuery()->getSingleScalarResult(); return $queryBuilder->getQuery()->getSingleScalarResult();
} }
public function count() { public function count()
{
$queryBuilder = $this->createQueryBuilder('s'); $queryBuilder = $this->createQueryBuilder('s');
$queryBuilder->select('count(s)'); $queryBuilder->select('count(s)');

View File

@ -10,9 +10,11 @@ class ModelRepository extends Repository
{ {
/** /**
* @param ModelSearch $modelSearch * @param ModelSearch $modelSearch
*
* @return \Elastica\Query * @return \Elastica\Query
*/ */
public function getSearchQuery(ModelSearch $modelSearch) { public function getSearchQuery(ModelSearch $modelSearch)
{
$boolQuery = new Query\BoolQuery(); $boolQuery = new Query\BoolQuery();
if ($searchQuery = $modelSearch->getQuery()) { if ($searchQuery = $modelSearch->getQuery()) {
@ -23,7 +25,6 @@ class ModelRepository extends Repository
$query->setFuzziness(0.7); $query->setFuzziness(0.7);
$query->setMinimumShouldMatch('80%'); $query->setMinimumShouldMatch('80%');
$query->setOperator('and'); $query->setOperator('and');
} else { } else {
$query = new Query\MatchAll(); $query = new Query\MatchAll();
} }
@ -42,10 +43,12 @@ class ModelRepository extends Repository
public function search(ModelSearch $modelSearch, $limit = 500) public function search(ModelSearch $modelSearch, $limit = 500)
{ {
$query = $this->getSearchQuery($modelSearch); $query = $this->getSearchQuery($modelSearch);
return $this->find($query, $limit); return $this->find($query, $limit);
} }
public function findHighlighted($query, $limit = 500) { public function findHighlighted($query, $limit = 500)
{
$modelSearch = new ModelSearch(); $modelSearch = new ModelSearch();
$modelSearch->setQuery($query); $modelSearch->setQuery($query);
@ -55,10 +58,10 @@ class ModelRepository extends Repository
$query->setHighlight([ $query->setHighlight([
'pre_tags' => ['<em>'], 'pre_tags' => ['<em>'],
'post_tags' => ['</em>'], 'post_tags' => ['</em>'],
"fields" => [ 'fields' => [
"name" => new \stdClass(), 'name' => new \stdClass(),
"id" => new \stdClass() 'id' => new \stdClass(),
] ],
]); ]);
return $this->findHybrid($query, $limit); return $this->findHybrid($query, $limit);

View File

@ -6,18 +6,18 @@ use AppBundle\Model\SetSearch;
use Elastica\Query; use Elastica\Query;
use Elastica\Query\BoolQuery; use Elastica\Query\BoolQuery;
use Elastica\Query\Match; use Elastica\Query\Match;
use Elastica\Query\MultiMatch;
use Elastica\Query\Range; use Elastica\Query\Range;
use Elastica\Query\Wildcard;
use FOS\ElasticaBundle\Repository; use FOS\ElasticaBundle\Repository;
class SetRepository extends Repository class SetRepository extends Repository
{ {
/** /**
* @param SetSearch $setSearch * @param SetSearch $setSearch
*
* @return Query * @return Query
*/ */
public function getSearchQuery(SetSearch $setSearch) { public function getSearchQuery(SetSearch $setSearch)
{
$boolQuery = new BoolQuery(); $boolQuery = new BoolQuery();
if ($searchQuery = $setSearch->getQuery()) { if ($searchQuery = $setSearch->getQuery()) {
@ -69,7 +69,8 @@ class SetRepository extends Repository
return $this->find($query, $limit); return $this->find($query, $limit);
} }
public function findHighlighted($query, $limit = 500) { public function findHighlighted($query, $limit = 500)
{
$setSearch = new SetSearch(); $setSearch = new SetSearch();
$setSearch->setQuery($query); $setSearch->setQuery($query);
@ -79,10 +80,10 @@ class SetRepository extends Repository
$query->setHighlight([ $query->setHighlight([
'pre_tags' => ['<em>'], 'pre_tags' => ['<em>'],
'post_tags' => ['</em>'], 'post_tags' => ['</em>'],
"fields" => [ 'fields' => [
"name" => new \stdClass(), 'name' => new \stdClass(),
"id" => new \stdClass() 'id' => new \stdClass(),
] ],
]); ]);
return $this->findHybrid($query, $limit); return $this->findHybrid($query, $limit);

View File

@ -10,7 +10,6 @@ use Monolog\Logger;
use Symfony\Bundle\FrameworkBundle\Translation\Translator; use Symfony\Bundle\FrameworkBundle\Translation\Translator;
use Symfony\Component\Asset\Exception\LogicException; use Symfony\Component\Asset\Exception\LogicException;
use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Debug\Exception\ContextErrorException; use Symfony\Component\Debug\Exception\ContextErrorException;

View File

@ -19,8 +19,6 @@ use AppBundle\Util\RelationMapper;
use League\Flysystem\Adapter\Local; use League\Flysystem\Adapter\Local;
use League\Flysystem\Exception; use League\Flysystem\Exception;
use League\Flysystem\Filesystem; use League\Flysystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
class ModelLoader extends BaseLoader class ModelLoader extends BaseLoader
{ {
@ -116,13 +114,13 @@ class ModelLoader extends BaseLoader
} }
/** /**
* Load one model into database * Load one model into database.
* *
* @param string $file Absolute filepath of model to load * @param string $file Absolute filepath of model to load
*/ */
public function loadOne($file) public function loadOne($file)
{ {
if(!$this->ldrawLibraryContext) { if (!$this->ldrawLibraryContext) {
throw new MissingContextException('LDrawLibrary'); throw new MissingContextException('LDrawLibrary');
} }
@ -140,13 +138,12 @@ class ModelLoader extends BaseLoader
} }
} }
/** /**
* Load all models from ldraw library context into database * Load all models from ldraw library context into database.
*/ */
public function loadAll() public function loadAll()
{ {
if(!$this->ldrawLibraryContext) { if (!$this->ldrawLibraryContext) {
throw new MissingContextException('LDrawLibrary'); throw new MissingContextException('LDrawLibrary');
} }
@ -162,7 +159,7 @@ class ModelLoader extends BaseLoader
foreach ($files as $file) { foreach ($files as $file) {
$this->progressBar->setMessage($file['basename']); $this->progressBar->setMessage($file['basename']);
if($file['type'] == 'file' && $file['extension'] == 'dat') { if ($file['type'] == 'file' && $file['extension'] == 'dat') {
$connection = $this->em->getConnection(); $connection = $this->em->getConnection();
$connection->beginTransaction(); $connection->beginTransaction();
@ -217,7 +214,7 @@ class ModelLoader extends BaseLoader
if (($parentId = $this->getParentId($modelArray)) && ($parentModelFile = $this->findSubmodelFile($parentId)) !== null) { if (($parentId = $this->getParentId($modelArray)) && ($parentModelFile = $this->findSubmodelFile($parentId)) !== null) {
if ($parentModel = $this->loadModel($parentModelFile)) { if ($parentModel = $this->loadModel($parentModelFile)) {
// Remove old model if ~moved to // Remove old model if ~moved to
if($this->rewrite && ($old = $modelRepository->find($modelArray['id'])) != null) { if ($this->rewrite && ($old = $modelRepository->find($modelArray['id'])) != null) {
$modelRepository->delete($old); $modelRepository->delete($old);
} }
@ -331,8 +328,7 @@ class ModelLoader extends BaseLoader
// Try to find model in current file's directory // Try to find model in current file's directory
if ($this->fileContext && $this->fileContext->has($filename)) { if ($this->fileContext && $this->fileContext->has($filename)) {
return $this->fileContext->getAdapter()->getPathPrefix().$filename; return $this->fileContext->getAdapter()->getPathPrefix().$filename;
} } elseif ($this->ldrawLibraryContext) {
elseif ($this->ldrawLibraryContext) {
// Try to find model in current LDRAW\PARTS sub-directory // Try to find model in current LDRAW\PARTS sub-directory
if ($this->ldrawLibraryContext->has('parts'.DIRECTORY_SEPARATOR.$filename)) { if ($this->ldrawLibraryContext->has('parts'.DIRECTORY_SEPARATOR.$filename)) {
return $this->ldrawLibraryContext->getAdapter()->getPathPrefix().'parts'.DIRECTORY_SEPARATOR.$filename; return $this->ldrawLibraryContext->getAdapter()->getPathPrefix().'parts'.DIRECTORY_SEPARATOR.$filename;

View File

@ -173,7 +173,7 @@ class StlRendererService
throw new FileNotFoundException($file); throw new FileNotFoundException($file);
} }
if(!file_exists($to)) { if (!file_exists($to)) {
mkdir($to); mkdir($to);
} }

View File

@ -73,12 +73,14 @@ class AppExtension extends \Twig_Extension
return $size; return $size;
} }
public function fileTimestamp($filePath) { public function fileTimestamp($filePath)
{
$changeDate = filemtime($_SERVER['DOCUMENT_ROOT'].'/'.$filePath); $changeDate = filemtime($_SERVER['DOCUMENT_ROOT'].'/'.$filePath);
if (!$changeDate) { if (!$changeDate) {
//Fallback if mtime could not be found: //Fallback if mtime could not be found:
$changeDate = mktime(0, 0, 0, date('m'), date('d'), date('Y')); $changeDate = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
} }
return $filePath.'?'.$changeDate; return $filePath.'?'.$changeDate;
} }

View File

@ -71,7 +71,7 @@ class LDModelParser
$keywords = explode(',', preg_replace('/^!KEYWORDS /', '', $line)); $keywords = explode(',', preg_replace('/^!KEYWORDS /', '', $line));
foreach ($keywords as $keyword) { foreach ($keywords as $keyword) {
$keyword = trim($keyword); $keyword = trim($keyword);
if ($keyword && !in_array($keyword,$model['keywords'])) { if ($keyword && !in_array($keyword, $model['keywords'])) {
$model['keywords'][] = $keyword; $model['keywords'][] = $keyword;
} }
} }