partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 0af6de354386172a286e5e553b928dce5fc78772
parent 88a0fbcdf13fe7689fd5302e6e50865395a5b314
Author: Timo A. Hummel <felicitus@felicitus.org>
Date:   Fri,  6 Nov 2015 23:20:14 +0100

Added command to re-generate the category path, added config parameter to define the category path separator, force path re-generation on setup. Related to #459

Diffstat:
Mapp/config/config.yml | 1+
Mapp/config/parameters.php.dist | 4++++
Mconfig.php.template | 130-------------------------------------------------------------------------------
Asrc/PartKeepr/CoreBundle/Command/UpdateCategoryPathCommand.php | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/PartKeepr/CoreBundle/DoctrineMigrations/Version20150719213922.php | 47-----------------------------------------------
Msrc/PartKeepr/DoctrineReflectionBundle/Command/GenerateEntityCommand.php | 6++----
Msrc/PartKeepr/FootprintBundle/Entity/FootprintCategory.php | 4++--
Msrc/PartKeepr/FootprintBundle/Listeners/CategoryPathListener.php | 8+++++++-
Msrc/PartKeepr/PartBundle/Entity/PartCategory.php | 4++--
Msrc/PartKeepr/PartBundle/Listeners/CategoryPathListener.php | 8+++++++-
Msrc/PartKeepr/SetupBundle/Controller/CacheWarmupSetupController.php | 6++++++
Msrc/PartKeepr/StorageLocationBundle/Entity/StorageLocationCategory.php | 4++--
Msrc/PartKeepr/StorageLocationBundle/Listeners/CategoryPathListener.php | 8+++++++-
13 files changed, 95 insertions(+), 190 deletions(-)

diff --git a/app/config/config.yml b/app/config/config.yml @@ -11,6 +11,7 @@ imports: - { resource: config_filesystem.yml } parameters: + partkeepr.category.path_separator: " ➤ " max_users: unlimited fos_rest: diff --git a/app/config/parameters.php.dist b/app/config/parameters.php.dist @@ -45,6 +45,10 @@ $container->setParameter('partkeepr.frontend.auto_login.username', 'admin'); */ $container->setParameter('partkeepr.frontend.auto_login.password', 'admin'); +/** + * Specifies the category path separator + */ +$container->setParameter('partkeepr.category.path_separator', ' ➤ '); $container->setParameter('mailer_transport', null); $container->setParameter('mailer_host', null); diff --git a/config.php.template b/config.php.template @@ -1,133 +1,3 @@ -<?php -namespace PartKeepr; - -use PartKeepr\Util\Configuration; - -/** - * Specifies the username for the database - */ -Configuration::setOption("partkeepr.database.username", "partkeepr"); - -/** - * Specifies the password for the database - */ -Configuration::setOption("partkeepr.database.password", "partkeepr"); - -/** - * Specifies the hostname for the database - */ -Configuration::setOption("partkeepr.database.host", "localhost"); - -/** - * Specifies the database name - */ -Configuration::setOption("partkeepr.database.dbname", "partkeepr"); - -/** - * Specifies the database port. - * Doesn't need to be specified. "null" specifies the default port. - */ -Configuration::setOption("partkeepr.database.port", null); - -/** - * Specifies the MySQL unix socket to use - */ -Configuration::setOption("partkeepr.database.mysql_socket", null); - - - -/** - * Specifies the database driver. - * - * In general, we support any database platform also supported by DBAL. For details, see - * http://www.doctrine-project.org/docs/dbal/2.0/en/reference/configuration.html#driver - * - * Available drivers: - * pdo_mysql MySQL is preferred, as all development happens on that platform. - * pdo_pgsql PostgreSQL should perform well, but could give problems here and there. Be sure to report these bugs! - * pdo_sqlite SQLite driver; mostly untested - * pdo_oci PDO-based Oracle driver; mostly untested. Seems to give problems; try oci8 instead - * pdo_sqlsrv MSSQL driver; mostly untested - * oci8 A driver which uses the PHP oci8 extension - * - * WARNING: Some database drivers require configuration options, which we don't support yet. We currently - * only push the parameters "username", "password", "hostname" and "dbname" into DBAL's configuration. We need to rework - * this; until then, at least pdo_sqlite won't work. - */ -Configuration::setOption("partkeepr.database.driver", "pdo_mysql"); - - -/** - * Specifies a message of the day (MOTD) to display on login. Simply replace false with any string. - */ -Configuration::setOption("partkeepr.frontend.motd", false); - -/*********************************************************************************************************************** - * CONFIGURATION SETTINGS FOR MIGRATING FROM PARTDB TO PARTKEEPR. LEAVE UNTOUCHED IF YOU DON'T HAVE PARTDB TO MIGRATE - **********************************************************************************************************************/ -Configuration::setOption("partkeepr.migration.partdb.hostname", "localhost"); -Configuration::setOption("partkeepr.migration.partdb.username", "partdb"); -Configuration::setOption("partkeepr.migration.partdb.password", "partdb"); -Configuration::setOption("partkeepr.migration.partdb.dbname", "partdb"); - -/*********************************************************************************************************************** - * END OF THE GENERAL CONFIGURATION SECTION - BELOW ARE CONFIGURATION SETTINGS WHICH USUALLY DON'T NEED TO BE ADJUSTED - **********************************************************************************************************************/ - - -/** - * Specifies if doctrine should log the SQL queries by echoing them. If you enable this, all AJAX service calls from the - * frontend will fail because the resulting output isn't JSON anymore. - */ -Configuration::setOption("partkeepr.database.echo_sql_log", false); - -/** - * Specifies the location of the uploaded files - */ -Configuration::setOption("partkeepr.files.path", __DIR__."/data/files/"); - -/** - * Specifies the location of the uploaded images - */ -Configuration::setOption("partkeepr.images.path", __DIR__."/data/images/"); - -/** - * Specifies the cache dir - */ -Configuration::setOption("partkeepr.images.cache", Configuration::getOption("partkeepr.images.path")."cache/"); - -/** - * Specifies if auto login is wanted or not - */ -Configuration::setOption("partkeepr.frontend.autologin.enabled", false); - -/** - * Specifies the auto login username - */ -Configuration::setOption("partkeepr.frontend.autologin.username", null); - -/** - * Specifies the auto login password - */ -Configuration::setOption("partkeepr.frontend.autologin.password", null); - -/** - * Specifies if frontend debugging should be turned on. This will create a non-minified, single JS file - * out of all source files - */ -Configuration::setOption("partkeepr.frontend.debug", false); - -/** - * Specifies if the frontend should load each single JS file individually, in contrast to merging all JS files - * into partkeepr-debug.js. - */ -Configuration::setOption("partkeepr.frontend.debug_all", false); - -/** - * Specifies if cronjobs should be checked. Disable this on Windows unless we have an automatic cronjob runner - * emulation implemented. - */ -Configuration::setOption("partkeepr.cronjobs.disablecheck", false); /** * Specifies if password changing is allowed. diff --git a/src/PartKeepr/CoreBundle/Command/UpdateCategoryPathCommand.php b/src/PartKeepr/CoreBundle/Command/UpdateCategoryPathCommand.php @@ -0,0 +1,55 @@ +<?php +namespace PartKeepr\CoreBundle\Command; + +use Gedmo\Tree\Entity\Repository\NestedTreeRepository; +use PartKeepr\CategoryBundle\Entity\AbstractCategory; +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class UpdateCategoryPathCommand extends ContainerAwareCommand +{ + public function configure() + { + parent::configure(); + $this->setName('partkeepr:update-category-paths'); + $this->setDescription("Updates the category paths for all category trees"); + } + + public function execute(InputInterface $input, OutputInterface $output) + { + $entities = array( + 'PartKeepr\FootprintBundle\Entity\FootprintCategory', + 'PartKeepr\PartBundle\Entity\PartCategory', + 'PartKeepr\StorageLocationBundle\Entity\StorageLocationCategory' + ); + + foreach ($entities as $entity) { + $this->regenerateCategoryPaths($entity); + } + + } + + public function regenerateCategoryPaths ($entity) { + $repository = $this->getContainer()->get("doctrine.orm.default_entity_manager")->getRepository($entity); + + /** + * @var $repository NestedTreeRepository + */ + $rootNodes = $repository->getRootNodes(); + + $pathSeparator = $this->getContainer()->getParameter("partkeepr.category.path_separator"); + + foreach ($rootNodes as $rootNode) { + $rootNode->setCategoryPath(uniqid()); + } + + $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush(); + + foreach ($rootNodes as $rootNode) { + $rootNode->setCategoryPath($rootNode->generateCategoryPath($pathSeparator)); + } + + $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush(); + } +} diff --git a/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20150719213922.php b/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20150719213922.php @@ -1,47 +0,0 @@ -<?php - -namespace PartKeepr\CoreBundle\DoctrineMigrations; - -use Doctrine\DBAL\Schema\Schema; -use Gedmo\Tree\Entity\Repository\NestedTreeRepository; -use PartKeepr\FootprintBundle\Entity\FootprintCategory; - -/** - * Re-generates the category paths. It is enough to trigger an update on the root node, as the event listener - * will recursively update the child categories. - */ -class Version20150719213922 extends BaseMigration -{ - /** - * @param Schema $schema - */ - public function up(Schema $schema) - { - $repository = $this->getEM()->getRepository( - 'PartKeepr\FootprintBundle\Entity\FootprintCategory' - ); - - /** - * @var $repository NestedTreeRepository - */ - $rootNodes = $repository->getRootNodes(); - - foreach ($rootNodes as $rootNode) { - /** - * @var $rootNode FootprintCategory - */ - $rootNode->setCategoryPath($rootNode->generateCategoryPath()); - } - - $this->getEM()->flush(); - } - - /** - * @param Schema $schema - */ - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - - } -} diff --git a/src/PartKeepr/DoctrineReflectionBundle/Command/GenerateEntityCommand.php b/src/PartKeepr/DoctrineReflectionBundle/Command/GenerateEntityCommand.php @@ -20,7 +20,4 @@ class GenerateEntityCommand extends ContainerAwareCommand $cacheDir = $this->getContainer()->get("kernel")->getRootDir()."/../web/bundles/doctrinereflection/"; $reflectionService->createCache($cacheDir); } -} - - - +}+ \ No newline at end of file diff --git a/src/PartKeepr/FootprintBundle/Entity/FootprintCategory.php b/src/PartKeepr/FootprintBundle/Entity/FootprintCategory.php @@ -109,10 +109,10 @@ class FootprintCategory extends AbstractCategory * * @return string The category path */ - public function generateCategoryPath() + public function generateCategoryPath($pathSeparator) { if ($this->getParent() !== null) { - return $this->getParent()->generateCategoryPath()." / ".$this->getName(); + return $this->getParent()->generateCategoryPath($pathSeparator) . $pathSeparator . $this->getName(); } else { return $this->getName(); } diff --git a/src/PartKeepr/FootprintBundle/Listeners/CategoryPathListener.php b/src/PartKeepr/FootprintBundle/Listeners/CategoryPathListener.php @@ -4,10 +4,15 @@ namespace PartKeepr\FootprintBundle\Listeners; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Event\OnFlushEventArgs; use PartKeepr\FootprintBundle\Entity\FootprintCategory; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerAware; class CategoryPathListener extends ContainerAware { + public function __construct (Container $container) { + $this->setContainer($container); + } + /** * Updates the child category paths when their parent name has changed. * @@ -40,8 +45,9 @@ class CategoryPathListener extends ContainerAware public function updateCategoryPaths(FootprintCategory $footprintCategory, OnFlushEventArgs $eventArgs) { $entityManager = $eventArgs->getEntityManager(); + $pathSeparator = $this->container->getParameter("partkeepr.category.path_separator"); - $footprintCategory->setCategoryPath($footprintCategory->generateCategoryPath()); + $footprintCategory->setCategoryPath($footprintCategory->generateCategoryPath($pathSeparator)); $entityManager->getUnitOfWork()->recomputeSingleEntityChangeSet( $entityManager->getClassMetadata(get_class($footprintCategory)), diff --git a/src/PartKeepr/PartBundle/Entity/PartCategory.php b/src/PartKeepr/PartBundle/Entity/PartCategory.php @@ -96,10 +96,10 @@ class PartCategory extends AbstractCategory * * @return string The category path */ - public function generateCategoryPath() + public function generateCategoryPath($pathSeparator) { if ($this->getParent() !== null) { - return $this->getParent()->generateCategoryPath()." / ".$this->getName(); + return $this->getParent()->generateCategoryPath($pathSeparator) . $pathSeparator . $this->getName(); } else { return $this->getName(); } diff --git a/src/PartKeepr/PartBundle/Listeners/CategoryPathListener.php b/src/PartKeepr/PartBundle/Listeners/CategoryPathListener.php @@ -4,10 +4,15 @@ namespace PartKeepr\PartBundle\Listeners; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Event\OnFlushEventArgs; use PartKeepr\PartBundle\Entity\PartCategory; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerAware; class CategoryPathListener extends ContainerAware { + public function __construct (Container $container) { + $this->setContainer($container); + } + /** * Updates the child category paths when their parent name has changed. * @@ -40,8 +45,9 @@ class CategoryPathListener extends ContainerAware public function updateCategoryPaths(PartCategory $partCategory, OnFlushEventArgs $eventArgs) { $entityManager = $eventArgs->getEntityManager(); + $pathSeparator = $this->container->getParameter("partkeepr.category.path_separator"); - $partCategory->setCategoryPath($partCategory->generateCategoryPath()); + $partCategory->setCategoryPath($partCategory->generateCategoryPath($pathSeparator)); $entityManager->getUnitOfWork()->recomputeSingleEntityChangeSet( $entityManager->getClassMetadata(get_class($partCategory)), diff --git a/src/PartKeepr/SetupBundle/Controller/CacheWarmupSetupController.php b/src/PartKeepr/SetupBundle/Controller/CacheWarmupSetupController.php @@ -58,6 +58,12 @@ class CacheWarmupSetupController extends SetupController $application->run($input, $output); + $input = new ArrayInput(array( + 'command' => 'partkeepr:update-category-paths', + )); + + $application->run($input, $output); + } catch (\Exception $e) { $response["success"] = false; $response["message"] = "Cache warm up error"; diff --git a/src/PartKeepr/StorageLocationBundle/Entity/StorageLocationCategory.php b/src/PartKeepr/StorageLocationBundle/Entity/StorageLocationCategory.php @@ -108,10 +108,10 @@ class StorageLocationCategory extends AbstractCategory * * @return string The category path */ - public function generateCategoryPath() + public function generateCategoryPath($pathSeparator) { if ($this->getParent() !== null) { - return $this->getParent()->generateCategoryPath()." / ".$this->getName(); + return $this->getParent()->generateCategoryPath($pathSeparator) . $pathSeparator . $this->getName(); } else { return $this->getName(); } diff --git a/src/PartKeepr/StorageLocationBundle/Listeners/CategoryPathListener.php b/src/PartKeepr/StorageLocationBundle/Listeners/CategoryPathListener.php @@ -4,10 +4,15 @@ namespace PartKeepr\StorageLocationBundle\Listeners; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Event\OnFlushEventArgs; use PartKeepr\StorageLocationBundle\Entity\StorageLocationCategory; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerAware; class CategoryPathListener extends ContainerAware { + public function __construct (Container $container) { + $this->setContainer($container); + } + /** * Updates the child category paths when their parent name has changed. * @@ -40,8 +45,9 @@ class CategoryPathListener extends ContainerAware public function updateCategoryPaths(StorageLocationCategory $storageLocationCategory, OnFlushEventArgs $eventArgs) { $entityManager = $eventArgs->getEntityManager(); + $pathSeparator = $this->container->getParameter("partkeepr.category.path_separator"); - $storageLocationCategory->setCategoryPath($storageLocationCategory->generateCategoryPath()); + $storageLocationCategory->setCategoryPath($storageLocationCategory->generateCategoryPath($pathSeparator)); $entityManager->getUnitOfWork()->recomputeSingleEntityChangeSet( $entityManager->getClassMetadata(get_class($storageLocationCategory)),