partkeepr

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

commit 2acb5b9eb5ce74598d8b867cc497d32f3f09e978
parent 68669323dcebe82ee37e99bbb29a44bc42037422
Author: Felicitus <felicitus@felicitus.org>
Date:   Tue,  7 Jul 2015 21:44:15 +0200

Don't use a cache warmer for generating the ExtJS models, but a command instead

Diffstat:
Mapp/config/config_dev.yml | 6++----
Mapp/config/config_test.yml | 7++-----
Dsrc/PartKeepr/DoctrineReflectionBundle/CacheWarmer/ModelCacheWarmer.php | 59-----------------------------------------------------------
Asrc/PartKeepr/DoctrineReflectionBundle/Command/GenerateEntityCommand.php | 48++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/PartKeepr/DoctrineReflectionBundle/Resources/config/services.xml | 7-------
Msrc/PartKeepr/ImageBundle/DependencyInjection/Configuration.php | 1-
Msrc/PartKeepr/ImageBundle/DependencyInjection/PartKeeprExtension.php | 1-
7 files changed, 52 insertions(+), 77 deletions(-)

diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml @@ -33,6 +33,4 @@ assetic: use_controller: true #swiftmailer: -# delivery_address: me@example.com -partkeepr: - auto_generate_extjs_models: true- \ No newline at end of file +# delivery_address: me@example.com+ \ No newline at end of file diff --git a/app/config/config_test.yml b/app/config/config_test.yml @@ -33,7 +33,4 @@ doctrine: liip_functional_test: - cache_sqlite_db: true - -partkeepr: - auto_generate_extjs_models: false- \ No newline at end of file + cache_sqlite_db: true+ \ No newline at end of file diff --git a/src/PartKeepr/DoctrineReflectionBundle/CacheWarmer/ModelCacheWarmer.php b/src/PartKeepr/DoctrineReflectionBundle/CacheWarmer/ModelCacheWarmer.php @@ -1,58 +0,0 @@ -<?php -namespace PartKeepr\DoctrineReflectionBundle\CacheWarmer; - - -use Doctrine\Common\Persistence\ManagerRegistry; -use Symfony\Component\DependencyInjection\Container; -use PartKeepr\DoctrineReflectionBundle\Services\ReflectionService; -use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer; - -class ModelCacheWarmer extends CacheWarmer{ - - private $registry; - private $reflectionService; - private $container; - - /** - * Constructor. - * - * @param ManagerRegistry $registry A ManagerRegistry instance - */ - public function __construct(ManagerRegistry $registry, ReflectionService $reflectionService, Container $container) - { - $this->reflectionService = $reflectionService; - $this->registry = $registry; - $this->container = $container; - } - - /** - * This cache warmer is not optional, without proxies fatal error occurs! - * - * @return false - */ - public function isOptional() - { - return false; - } - - /** - * {@inheritdoc} - */ - public function warmUp($cacheDir) - { - if ($this->container->getParameter("partkeepr.auto_generate_extjs_models")) { - echo "FOO"; - $cacheDir .= "/doctrinereflection"; - - $entities = $this->reflectionService->getEntities(); - - foreach ($entities as $entity) { - $model = $this->reflectionService->getEntity($entity); - - @mkdir($cacheDir, 0777, true); - $this->writeCacheFile($cacheDir."/".$entity.'.js', $model); - } - } - - } -}- \ No newline at end of file diff --git a/src/PartKeepr/DoctrineReflectionBundle/Command/GenerateEntityCommand.php b/src/PartKeepr/DoctrineReflectionBundle/Command/GenerateEntityCommand.php @@ -0,0 +1,48 @@ +<?php +namespace PartKeepr\DoctrineReflectionBundle\Command; + +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class GenerateEntityCommand extends ContainerAwareCommand { + public function configure() + { + parent::configure(); + $this->setName('generate:extjs:entities'); + $this->setDescription("Generates Sencha ExtJS models"); + } + + public function execute(InputInterface $input, OutputInterface $output) + { + $cacheDir = $this->getContainer()->get("kernel")->getCacheDir(); + + $cacheDir .= "/doctrinereflection"; + @mkdir($cacheDir, 0777, true); + + $reflectionService = $this->getContainer()->get("doctrine_reflection_service"); + + $entities = $reflectionService->getEntities(); + + foreach ($entities as $entity) { + $model = $reflectionService->getEntity($entity); + + $this->writeCacheFile($cacheDir."/".$entity.'.js', $model); + } + } + + protected function writeCacheFile($file, $content) + { + $tmpFile = tempnam(dirname($file), basename($file)); + if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) { + @chmod($file, 0666 & ~umask()); + + return; + } + + throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file)); + } +} + + + diff --git a/src/PartKeepr/DoctrineReflectionBundle/Resources/config/services.xml b/src/PartKeepr/DoctrineReflectionBundle/Resources/config/services.xml @@ -10,12 +10,5 @@ <argument type="service" id="templating"/> <argument type="service" id="annotation_reader"/> </service> - - <service id="model_cache_warmer" class="PartKeepr\DoctrineReflectionBundle\CacheWarmer\ModelCacheWarmer"> - <tag name="kernel.cache_warmer"/> - <argument type="service" id="doctrine"/> - <argument type="service" id="doctrine_reflection_service"/> - <argument type="service" id="service_container"/> - </service> </services> </container> diff --git a/src/PartKeepr/ImageBundle/DependencyInjection/Configuration.php b/src/PartKeepr/ImageBundle/DependencyInjection/Configuration.php @@ -22,7 +22,6 @@ class Configuration implements ConfigurationInterface $rootNode-> children() - ->booleanNode('auto_generate_extjs_models')->defaultFalse()->end() ->scalarNode('image_cache_directory')->cannotBeEmpty()->isRequired()->info('The image cache directory')->end() ->arrayNode('directories') ->prototype('scalar')->end() diff --git a/src/PartKeepr/ImageBundle/DependencyInjection/PartKeeprExtension.php b/src/PartKeepr/ImageBundle/DependencyInjection/PartKeeprExtension.php @@ -17,7 +17,6 @@ class PartKeeprExtension extends Extension $config = $this->processConfiguration($configuration, $configs); $container->setParameter('partkeepr.image_cache_directory', $config['image_cache_directory']); - $container->setParameter('partkeepr.auto_generate_extjs_models', $config['auto_generate_extjs_models']); foreach ($config["directories"] as $key => $value) { $container->setParameter("partkeepr.directories.".$key, $value);