From f4a472998b8b76d5ca6db337d03841f75a0df904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=BCbner?= Date: Sun, 28 May 2017 19:36:00 +0200 Subject: [PATCH] Update readme and commands --- README.md | 42 ++++++++++--- src/AppBundle/Command/InitDataCommand.php | 31 +++++++--- .../Command/LoadModelImagesCommand.php | 8 +-- src/AppBundle/Command/LoadModelsCommand.php | 62 ++++++++----------- 4 files changed, 86 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index cedba1f..48336c7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ A Symfony project ## Install ### System requirements -* PHP needs to be a minimum version of PHP 5.5.9 + +* PHP needs to be a minimum version of PHP 7.0 * PHP Extensions * FTP * SOAP @@ -12,12 +13,21 @@ A Symfony project * PDO * Zip * *date.timezone* setting set in *php.ini* -* LDView OSMesa >= 4.2.1 [source](https://tcobbs.github.io/ldview/). You can check if your system meets requirements by running `$ bin/symfony_requirements` For full requirements see Symfony 3.2 [docs](http://symfony.com/doc/3.2/reference/requirements.html). + +#### Required +* Elasticsearch + + Instructions for installing and deploying Elasticsearch may be found [here](https://www.elastic.co/downloads/elasticsearch). +* POV-Ray +* stl2pov [source](http://www.povray.org/). +* ADMesh [source](https://github.com/rsmith-nl/stltools/releases/tag/3.3). +* LDView OSMesa >= 4.2.1 [source](https://tcobbs.github.io/ldview/). + ### Installing #### Back-end @@ -26,12 +36,26 @@ For full requirements see Symfony 3.2 [docs](http://symfony.com/doc/3.2/referenc #### Front-end 1. Install dependencies via [npm](https://www.npmjs.com/), `$ npm install` -2. Compile assets by running [Gulp](http://gulpjs.com/), `$ gulp` +2. Install bower dependencies via [bower](https://bower.io), `$ bower install` +3. Compile assets by running [Gulp](http://gulpjs.com/), `$ gulp` -#### Database +#### Initialization + +##### Setup database 1. Set application parameters in *app/config/parameters.yml* -2. Generate an empty database by running command (if it does not yet exist) `$ php bin/console doctrine:database:create` -3. Run doctrine migrations by running command`$ bin/console doctrine:migrations:migrate` -3. Load LDraw models into database by running commad `$ php bin/console app:load:models [--all] [--file=FILE] [--update]` -4. Load Rebrickable data into database by running command `$ php bin/console app:load:rebrickable` -5. Load relations between LDraw models and Rebrickable parts by running command `$ php bin/console app:load:relation` \ No newline at end of file +2. Generate an empty database by running command (if it does not yet exist) `$ bin/console doctrine:database:create` +3. Create database tables/schema by running command`$ bin/console doctrine:schema:create` +4. Load database fixtures `$ bin/console doctrine:fixtures:load` + +##### Load data +You can load initial application data by running command `$ bin/console app:init` + +This command consists of multiple subcommands that can be called separately: +1. Load LDraw models into database by running commad `$ bin/console app:load:models [--ldraw=PATH] [--all] [--file=FILE] [--update] ` +2. Load Rebrickable data into database by running command `$ bin/console app:load:rebrickable` +3. Load relations between LDraw models and Rebrickable parts by running command `$ bin/console app:load:relation` +4. Download images of models from rebrickable.com `$ bin/console app:load:images [--color=INT] [--rebrickable] [--missing]` +5. Populate Elastisearch index `$ bin/console fos:elastica:populate` + +## Testing +You can run complete system tests by `$ phpunit`. These should cover the main system functions and the functionality of calling the third-party programs that are required are needed to seamlessly retrieve the necessary application data. diff --git a/src/AppBundle/Command/InitDataCommand.php b/src/AppBundle/Command/InitDataCommand.php index f8c51bc..b5a96f9 100644 --- a/src/AppBundle/Command/InitDataCommand.php +++ b/src/AppBundle/Command/InitDataCommand.php @@ -7,6 +7,7 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class InitDataCommand extends ContainerAwareCommand @@ -15,11 +16,11 @@ class InitDataCommand extends ContainerAwareCommand { $this ->setName('app:init') - ->setDescription('Loads relations between LDraw models and Rebrickable parts.') - ->setHelp('This command allows you to load relation between models and parts into database.') + ->setDescription('Loads initial data') + ->setHelp('This command allows you to load initial data of models and sets into aplication') ->setDefinition( new InputDefinition([ - new InputArgument('ldraw', InputArgument::OPTIONAL, 'Path to LDraw library directory'), + new InputOption('ldraw', 'l',InputOption::VALUE_OPTIONAL, 'Path to LDraw library directory'), ]) ); } @@ -28,11 +29,16 @@ class InitDataCommand extends ContainerAwareCommand { $loadModelsCommand = $this->getApplication()->find('app:load:models'); - $returnCode = $loadModelsCommand->run(new ArrayInput([ + $loadModelsInput = [ 'command' => 'app:load:models', - 'ldraw' => $input->getArgument('ldraw'), '--all' => true, - ]), $output); + ]; + + if($ldraw = $input->getOption('ldraw')) { + $loadModelsInput['--ldraw'] = $ldraw; + } + + $returnCode = $loadModelsCommand->run(new ArrayInput($loadModelsInput), $output); if ($returnCode) { return 1; @@ -58,9 +64,20 @@ class InitDataCommand extends ContainerAwareCommand 'command' => 'app:load:images', '--color' => -1, '--rebrickable' => true, - '--models' => true, + '--missing' => true, ]), $output); + if ($returnCode) { + return 1; + } + + $elasticIndex = $this->getApplication()->find('fos:elastic:populate'); + $returnCode = $elasticIndex->run(null, $output); + + if ($returnCode) { + return 1; + } + return 0; } } diff --git a/src/AppBundle/Command/LoadModelImagesCommand.php b/src/AppBundle/Command/LoadModelImagesCommand.php index bface34..82b1126 100644 --- a/src/AppBundle/Command/LoadModelImagesCommand.php +++ b/src/AppBundle/Command/LoadModelImagesCommand.php @@ -19,9 +19,8 @@ class LoadModelImagesCommand extends ContainerAwareCommand ->setDefinition( new InputDefinition([ new InputOption('color', 'c', InputOption::VALUE_REQUIRED, 'Color ID of images to load.'), - new InputOption('url', 'u', InputOption::VALUE_REQUIRED, 'Url of zip file to load'), new InputOption('rebrickable', 'r', InputOption::VALUE_NONE, 'Download images from Rebicable.com'), - new InputOption('models', 'm', InputOption::VALUE_NONE, 'Load missing images of models'), + new InputOption('missing', 'm', InputOption::VALUE_NONE, 'Load missing images of models'), ]) ); } @@ -32,13 +31,12 @@ class LoadModelImagesCommand extends ContainerAwareCommand $imageLoaderService->setOutput($output); $color = $input->getOption('color'); - $url = $input->getOption('url'); if ($color !== null && $input->getOption('rebrickable')) { - $imageLoaderService->loadColorFromRebrickable($color, $url); + $imageLoaderService->loadColorFromRebrickable($color); } - if ($input->getOption('models')) { + if ($input->getOption('missing')) { $imageLoaderService->loadMissingModelImages(); } } diff --git a/src/AppBundle/Command/LoadModelsCommand.php b/src/AppBundle/Command/LoadModelsCommand.php index f33ad7c..b806640 100644 --- a/src/AppBundle/Command/LoadModelsCommand.php +++ b/src/AppBundle/Command/LoadModelsCommand.php @@ -2,6 +2,7 @@ namespace AppBundle\Command; +use AppBundle\Service\Loader\ModelLoader; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Command\LockableTrait; use Symfony\Component\Console\Input\InputArgument; @@ -22,10 +23,10 @@ class LoadModelsCommand extends ContainerAwareCommand ->setHelp('This command allows you to load LDraw library models into database while converting .dat files to .stl format.') ->setDefinition( new InputDefinition([ - new InputArgument('ldraw', InputArgument::OPTIONAL, 'Path to LDraw library directory'), + new InputOption('ldraw', 'l', InputOption::VALUE_OPTIONAL, 'Path to LDraw library directory'), new InputOption('all', 'a', InputOption::VALUE_NONE, 'Load all models from LDraw libary folder (/parts directory)'), new InputOption('file', 'f', InputOption::VALUE_REQUIRED, 'Load single modle into database'), - new InputOption('update', 'u', InputOption::VALUE_NONE, 'Overwrite already loaded models'), + new InputOption('update', 'u', InputOption::VALUE_NONE, 'Update models'), ]) ); } @@ -38,13 +39,10 @@ class LoadModelsCommand extends ContainerAwareCommand return 1; } + /** @var ModelLoader $modelLoader */ $modelLoader = $this->getContainer()->get('service.loader.model'); $modelLoader->setOutput($output); - $modelLoader->setRewite($input->getOption('update')); - - if (!($ldraw = $input->getArgument('ldraw'))) { - $ldraw = $modelLoader->downloadLibrary(); - } + $modelLoader->setRewrite($input->getOption('update')); if (!$input->getOption('file') && !$input->getOption('all')) { $output->writeln('Either the --all or --file option is required'); @@ -52,46 +50,38 @@ class LoadModelsCommand extends ContainerAwareCommand return 1; } - if ($ldrawPath = realpath($ldraw)) { - $modelLoader->setLDrawLibraryContext($ldrawPath); + if($ldraw = $input->getOption('ldraw')) { + $modelLoader->setLDrawLibraryContext(realpath($ldraw)); + } else { + $ldraw = $modelLoader->downloadLibrary($this->getContainer()->getParameter('app.ld_library_download_url')); + $modelLoader->setLDrawLibraryContext($ldraw); + } - if (($path = $input->getOption('file')) != null) { - if ($file = realpath($path)) { - $output->writeln([ - "Loading model: {$path}", - ]); - - $modelLoader->loadOne($file); - - $errorCount = $this->getContainer()->get('monolog.logger.loader')->countErrors(); - $errors = $errorCount ? ''.$errorCount.'' : '0'; - - $output->writeln(['Done with "'.$errors.'" errors.']); - } else { - $output->writeln("File $path not found"); - } - } - - // Load all models inside ldraw/parts directory - if ($input->getOption('all')) { + if (($path = $input->getOption('file')) != null) { + if ($file = realpath($path)) { $output->writeln([ - '------------------------------------------------------------------------------', - "Loading models from LDraw library: {$ldrawPath}", - '------------------------------------------------------------------------------', + "Loading model: {$path}", ]); - $modelLoader->loadAll(); + $modelLoader->loadOne($file); $errorCount = $this->getContainer()->get('monolog.logger.loader')->countErrors(); $errors = $errorCount ? ''.$errorCount.'' : '0'; $output->writeln(['Done with "'.$errors.'" errors.']); + } else { + $output->writeln("File $path not found"); } - } else { - $output->writeln("{$ldraw} is not a valid path!"); - $this->release(); + } - return 1; + // Load all models inside ldraw/parts directory + if ($input->getOption('all')) { + $modelLoader->loadAll(); + + $errorCount = $this->getContainer()->get('monolog.logger.loader')->countErrors(); + $errors = $errorCount ? ''.$errorCount.'' : '0'; + + $output->writeln(['Done with "'.$errors.'" errors.']); } $this->release();