From b20b9c4a528e4126a55a811e0e2ace960fbc372d Mon Sep 17 00:00:00 2001 From: Tyler Sommer Date: Thu, 22 Jan 2015 08:30:37 -0700 Subject: [PATCH 01/25] Packages now depends on nice/templating --- composer.json | 3 ++- src/Application.php | 2 ++ src/Controller/DefaultController.php | 4 ++-- src/Controller/ManageController.php | 2 +- src/Controller/PackageController.php | 4 ++-- src/Controller/RemoteController.php | 6 +++--- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index a7aa5d4..895bffb 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "nice/framework": "~1.0", "nice/security": "~1.0", "nice/doctrine-orm": "~1.0", - "nice/twig": "~1.0", + "nice/twig": "2.0.x-dev", + "nice/templating": "1.0.x-dev", "chrisboulton/php-resque": "dev-master", "doctrine/migrations": "1.0.x-dev", "symfony/debug": "~2.4", diff --git a/src/Application.php b/src/Application.php index ab48e33..b6047f5 100644 --- a/src/Application.php +++ b/src/Application.php @@ -13,6 +13,7 @@ use Nice\Extension\DoctrineOrmExtension; use Nice\Extension\SecurityExtension; use Nice\Extension\SessionExtension; +use Nice\Extension\TemplatingExtension; use Nice\Extension\TwigExtension; use Symfony\Component\Yaml\Yaml; use Terramar\Packages\DependencyInjection\PackagesExtension; @@ -48,6 +49,7 @@ protected function registerDefaultExtensions() ))); $this->appendExtension(new DoctrineOrmExtension($doctrine)); $this->appendExtension(new SessionExtension()); + $this->appendExtension(new TemplatingExtension()); $this->appendExtension(new TwigExtension($this->getRootDir() . '/views')); $this->appendExtension(new SecurityExtension(array( 'authenticator' => array( diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 73ee245..0ab54d6 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -27,7 +27,7 @@ public function indexAction(Application $app, Request $request) } return new Response( - $app->get('twig')->render('Default/index.html.twig', array( + $app->get('templating')->render('Default/index.html.twig', array( 'updatedAt' => $mtime ))); } @@ -41,6 +41,6 @@ public function loginAction(Application $app, Request $request) $session->remove(AuthenticationFailureSubscriber::AUTHENTICATION_ERROR); } - return new Response($app->get('twig')->render('Default/login.html.twig', array('error' => $error))); + return new Response($app->get('templating')->render('Default/login.html.twig', array('error' => $error))); } } diff --git a/src/Controller/ManageController.php b/src/Controller/ManageController.php index 1d68d29..2719289 100644 --- a/src/Controller/ManageController.php +++ b/src/Controller/ManageController.php @@ -31,7 +31,7 @@ public function indexAction(Application $app, Request $request) ->where('c.enabled = true') ->getQuery()->getSingleScalarResult(); - return new Response($app->get('twig')->render('Manage/index.html.twig', array( + return new Response($app->get('templating')->render('Manage/index.html.twig', array( 'packages' => $packages, 'remotes' => $remotes, ))); diff --git a/src/Controller/PackageController.php b/src/Controller/PackageController.php index 7f84b69..4122df7 100644 --- a/src/Controller/PackageController.php +++ b/src/Controller/PackageController.php @@ -28,7 +28,7 @@ public function indexAction(Application $app, Request $request) $packages = $entityManager->getRepository('Terramar\Packages\Entity\Package')->findAll(); - return new Response($app->get('twig')->render('Package/index.html.twig', array( + return new Response($app->get('templating')->render('Package/index.html.twig', array( 'packages' => $packages ))); } @@ -42,7 +42,7 @@ public function editAction(Application $app, $id) throw new \RuntimeException('Oops'); } - return new Response($app->get('twig')->render('Package/edit.html.twig', array( + return new Response($app->get('templating')->render('Package/edit.html.twig', array( 'package' => $package, 'remotes' => $this->getRemotes($app->get('doctrine.orm.entity_manager')) ))); diff --git a/src/Controller/RemoteController.php b/src/Controller/RemoteController.php index 797cf6a..911f079 100644 --- a/src/Controller/RemoteController.php +++ b/src/Controller/RemoteController.php @@ -25,7 +25,7 @@ public function indexAction(Application $app, Request $request) $remotes = $entityManager->getRepository('Terramar\Packages\Entity\Remote')->findAll(); - return new Response($app->get('twig')->render('Remote/index.html.twig', array( + return new Response($app->get('templating')->render('Remote/index.html.twig', array( 'remotes' => $remotes ))); } @@ -34,7 +34,7 @@ public function newAction(Application $app) { $adapters = $app->get('packages.helper.sync')->getAdapters(); - return new Response($app->get('twig')->render('Remote/new.html.twig', array( + return new Response($app->get('templating')->render('Remote/new.html.twig', array( 'adapters' => $adapters, 'remote' => new Remote() ))); @@ -69,7 +69,7 @@ public function editAction(Application $app, $id) throw new \RuntimeException('Oops'); } - return new Response($app->get('twig')->render('Remote/edit.html.twig', array( + return new Response($app->get('templating')->render('Remote/edit.html.twig', array( 'remote' => $remote ))); } From 8435220550d0fe4d809144067961f77f3a6c0e4f Mon Sep 17 00:00:00 2001 From: Tyler Sommer Date: Tue, 27 Jan 2015 17:16:27 -0700 Subject: [PATCH 02/25] Revert "Removed Sami and CloneProject plugins" This reverts commit 3956b9e88000d6cd5debb1ad94fe3168cd65f877. --- src/Application.php | 4 + src/Plugin/CloneProject/CloneProjectJob.php | 85 +++++++++++++++ src/Plugin/CloneProject/Controller.php | 46 ++++++++ src/Plugin/CloneProject/EventSubscriber.php | 86 +++++++++++++++ src/Plugin/CloneProject/Events.php | 15 +++ src/Plugin/CloneProject/PackageCloneEvent.php | 42 +++++++ .../CloneProject/PackageConfiguration.php | 78 +++++++++++++ src/Plugin/CloneProject/Plugin.php | 69 ++++++++++++ src/Plugin/Sami/Controller.php | 47 ++++++++ src/Plugin/Sami/EventSubscriber.php | 92 ++++++++++++++++ src/Plugin/Sami/PackageConfiguration.php | 99 +++++++++++++++++ src/Plugin/Sami/Plugin.php | 59 ++++++++++ src/Plugin/Sami/UpdateJob.php | 103 ++++++++++++++++++ views/Plugin/CloneProject/edit.html.twig | 14 +++ views/Plugin/Sami/edit.html.twig | 44 ++++++++ 15 files changed, 883 insertions(+) create mode 100644 src/Plugin/CloneProject/CloneProjectJob.php create mode 100644 src/Plugin/CloneProject/Controller.php create mode 100644 src/Plugin/CloneProject/EventSubscriber.php create mode 100644 src/Plugin/CloneProject/Events.php create mode 100644 src/Plugin/CloneProject/PackageCloneEvent.php create mode 100644 src/Plugin/CloneProject/PackageConfiguration.php create mode 100644 src/Plugin/CloneProject/Plugin.php create mode 100644 src/Plugin/Sami/Controller.php create mode 100644 src/Plugin/Sami/EventSubscriber.php create mode 100644 src/Plugin/Sami/PackageConfiguration.php create mode 100644 src/Plugin/Sami/Plugin.php create mode 100644 src/Plugin/Sami/UpdateJob.php create mode 100644 views/Plugin/CloneProject/edit.html.twig create mode 100644 views/Plugin/Sami/edit.html.twig diff --git a/src/Application.php b/src/Application.php index b6047f5..7ec4ba4 100644 --- a/src/Application.php +++ b/src/Application.php @@ -17,7 +17,9 @@ use Nice\Extension\TwigExtension; use Symfony\Component\Yaml\Yaml; use Terramar\Packages\DependencyInjection\PackagesExtension; +use Terramar\Packages\Plugin\CloneProject\Plugin as CloneProjectPlugin; use Terramar\Packages\Plugin\GitLab\Plugin as GitLabPlugin; +use Terramar\Packages\Plugin\Sami\Plugin as SamiPlugin; use Terramar\Packages\Plugin\Satis\Plugin as SatisPlugin; use Terramar\Packages\Plugin\GitHub\Plugin as GitHubPlugin; use Terramar\Packages\Plugin\PluginInterface; @@ -71,6 +73,8 @@ protected function registerDefaultPlugins() { $this->registerPlugin(new GitLabPlugin()); $this->registerPlugin(new GitHubPlugin()); + $this->registerPlugin(new CloneProjectPlugin()); + $this->registerPlugin(new SamiPlugin()); $this->registerPlugin(new SatisPlugin()); } diff --git a/src/Plugin/CloneProject/CloneProjectJob.php b/src/Plugin/CloneProject/CloneProjectJob.php new file mode 100644 index 0000000..9713d96 --- /dev/null +++ b/src/Plugin/CloneProject/CloneProjectJob.php @@ -0,0 +1,85 @@ +getContainer()->getParameter('app.cache_dir') . '/cloned_project/' . $package->getFqn(); + } + + /** + * @return EntityManager + */ + private function getEntityManager() + { + return $this->getContainer()->get('doctrine.orm.entity_manager'); + } + + /** + * @return EventDispatcherInterface + */ + private function getEventDispatcher() + { + return $this->getContainer()->get('event_dispatcher'); + } + + public function run($args) + { + $package = $this->getEntityManager()->find('Terramar\Packages\Entity\Package', $args['id']); + if (!$package) { + throw new \RuntimeException('Invalid project'); + } + + $directory = $this->getCacheDir($package); + + if (file_exists($directory) || is_dir($directory)) { + $this->emptyAndRemoveDirectory($directory); + } + + mkdir($directory, 0777, true); + + $builder = new ProcessBuilder(array('clone', $package->getSshUrl(), $directory)); + $builder->setPrefix('git'); + + $process = $builder->getProcess(); + $process->run(function($type, $message) { + echo $message; + }); + + if ($process->isSuccessful()) { + $event = new PackageCloneEvent($package, $directory); + $this->getEventDispatcher()->dispatch(Events::PACKAGE_CLONED, $event); + } + } + + private function emptyAndRemoveDirectory($directory) + { + $files = array_diff(scandir($directory), array('.','..')); + foreach ($files as $file) { + (is_dir("$directory/$file")) ? $this->emptyAndRemoveDirectory("$directory/$file") : unlink("$directory/$file"); + } + + return rmdir($directory); + } +} \ No newline at end of file diff --git a/src/Plugin/CloneProject/Controller.php b/src/Plugin/CloneProject/Controller.php new file mode 100644 index 0000000..a568162 --- /dev/null +++ b/src/Plugin/CloneProject/Controller.php @@ -0,0 +1,46 @@ +get('doctrine.orm.entity_manager'); + $config = $entityManager->getRepository('Terramar\Packages\Plugin\CloneProject\PackageConfiguration')->findOneBy(array( + 'package' => $id + )); + + return new Response($app->get('twig')->render('Plugin/CloneProject/edit.html.twig', array( + 'config' => $config + ))); + } + + public function updateAction(Application $app, Request $request, $id) + { + /** @var \Doctrine\ORM\EntityManager $entityManager */ + $entityManager = $app->get('doctrine.orm.entity_manager'); + $config = $entityManager->getRepository('Terramar\Packages\Plugin\CloneProject\PackageConfiguration')->findOneBy(array( + 'package' => $id + )); + + $config->setEnabled($request->get('cloneproject_enabled') ? true : false); + $entityManager->persist($config); + + return new Response(); + } +} diff --git a/src/Plugin/CloneProject/EventSubscriber.php b/src/Plugin/CloneProject/EventSubscriber.php new file mode 100644 index 0000000..b77ef28 --- /dev/null +++ b/src/Plugin/CloneProject/EventSubscriber.php @@ -0,0 +1,86 @@ +resqueHelper = $resqueHelper; + $this->entityManager = $entityManager; + } + + /** + * @param PackageUpdateEvent $event + */ + public function onUpdatePackage(PackageUpdateEvent $event) + { + $package = $event->getPackage(); + $config = $this->entityManager->getRepository('Terramar\Packages\Plugin\CloneProject\PackageConfiguration') + ->findOneBy(array('package' => $package)); + + if (!$config || !$config->isEnabled() || !$package->isEnabled()) { + return; + } + + $this->resqueHelper->enqueue('default', 'Terramar\Packages\Plugin\CloneProject\CloneProjectJob', array('id' => $event->getPackage()->getId())); + } + + /** + * @param PackageEvent $event + */ + public function onCreatePackage(PackageEvent $event) + { + $package = $event->getPackage(); + $config = $this->entityManager->getRepository('Terramar\Packages\Plugin\CloneProject\PackageConfiguration') + ->findOneBy(array('package' => $package)); + + if (!$config) { + $config = new PackageConfiguration(); + $config->setPackage($package); + } + + $this->entityManager->persist($config); + } + + /** + * @return array + */ + public static function getSubscribedEvents() + { + return array( + Events::PACKAGE_CREATE => array('onCreatePackage', 0), + Events::PACKAGE_UPDATE => array('onUpdatePackage', 0) + ); + } +} \ No newline at end of file diff --git a/src/Plugin/CloneProject/Events.php b/src/Plugin/CloneProject/Events.php new file mode 100644 index 0000000..44fec3d --- /dev/null +++ b/src/Plugin/CloneProject/Events.php @@ -0,0 +1,15 @@ +repositoryPath = $repositoryPath; + + parent::__construct($package); + } + + /** + * @return string + */ + public function getRepositoryPath() + { + return $this->repositoryPath; + } +} \ No newline at end of file diff --git a/src/Plugin/CloneProject/PackageConfiguration.php b/src/Plugin/CloneProject/PackageConfiguration.php new file mode 100644 index 0000000..4e20877 --- /dev/null +++ b/src/Plugin/CloneProject/PackageConfiguration.php @@ -0,0 +1,78 @@ +enabled = (bool) $enabled; + } + + /** + * @return boolean + */ + public function isEnabled() + { + return $this->enabled; + } + + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } + + /** + * @return Package + */ + public function getPackage() + { + return $this->package; + } + + /** + * @param Package $package + */ + public function setPackage(Package $package) + { + $this->package = $package; + } +} \ No newline at end of file diff --git a/src/Plugin/CloneProject/Plugin.php b/src/Plugin/CloneProject/Plugin.php new file mode 100644 index 0000000..6f77b57 --- /dev/null +++ b/src/Plugin/CloneProject/Plugin.php @@ -0,0 +1,69 @@ +register('packages.plugin.clone_project.subscriber', 'Terramar\Packages\Plugin\CloneProject\EventSubscriber') + ->addArgument(new Reference('packages.helper.resque')) + ->addArgument(new Reference('doctrine.orm.entity_manager')) + ->addTag('kernel.event_subscriber'); + + $container->getDefinition('packages.controller_manager') + ->addMethodCall('registerController', array(Actions::PACKAGE_EDIT, 'Terramar\Packages\Plugin\CloneProject\Controller::editAction')) + ->addMethodCall('registerController', array(Actions::PACKAGE_UPDATE, 'Terramar\Packages\Plugin\CloneProject\Controller::updateAction')); + } + + /** + * Get the plugin name + * + * @return string + */ + public function getName() + { + return 'git-clone'; + } + + /** + * @return string + */ + public function getVersion() + { + if (!$this->version) { + $matches = array(); + preg_match('/version (\d\.\d\.\d(\.\d)?)/', exec('git --version'), $matches); + $this->version = $matches[1]; + } + + return $this->version; + } +} \ No newline at end of file diff --git a/src/Plugin/Sami/Controller.php b/src/Plugin/Sami/Controller.php new file mode 100644 index 0000000..ee4173b --- /dev/null +++ b/src/Plugin/Sami/Controller.php @@ -0,0 +1,47 @@ +get('doctrine.orm.entity_manager'); + $config = $entityManager->getRepository('Terramar\Packages\Plugin\Sami\PackageConfiguration')->findOneBy(array( + 'package' => $id + )); + + return new Response($app->get('twig')->render('Plugin/Sami/edit.html.twig', array( + 'config' => $config, + ))); + } + + public function updateAction(Application $app, Request $request, $id) + { + /** @var \Doctrine\ORM\EntityManager $entityManager */ + $entityManager = $app->get('doctrine.orm.entity_manager'); + $config = $entityManager->getRepository('Terramar\Packages\Plugin\Sami\PackageConfiguration')->findOneBy(array( + 'package' => $id + )); + + $config->setEnabled($request->get('sami_enabled') ? true : false); + + $entityManager->persist($config); + + return new Response(); + } +} diff --git a/src/Plugin/Sami/EventSubscriber.php b/src/Plugin/Sami/EventSubscriber.php new file mode 100644 index 0000000..27b5df7 --- /dev/null +++ b/src/Plugin/Sami/EventSubscriber.php @@ -0,0 +1,92 @@ +resqueHelper = $resqueHelper; + $this->entityManager = $entityManager; + } + + /** + * @param PackageCloneEvent $event + */ + public function onClonePackage(PackageCloneEvent $event) + { + $package = $event->getPackage(); + $config = $this->entityManager->getRepository('Terramar\Packages\Plugin\Sami\PackageConfiguration') + ->findOneBy(array('package' => $package)); + + if (!$config || !$config->isEnabled() || !$package->isEnabled()) { + return; + } + + $config->setRepositoryPath($event->getRepositoryPath()); + + $this->entityManager->persist($config); + $this->entityManager->flush($config); + + $this->resqueHelper->enqueue('default', 'Terramar\Packages\Plugin\Sami\UpdateJob', array('id' => $package->getId())); + } + + /** + * @param PackageEvent $event + */ + public function onCreatePackage(PackageEvent $event) + { + $package = $event->getPackage(); + $config = $this->entityManager->getRepository('Terramar\Packages\Plugin\Sami\PackageConfiguration') + ->findOneBy(array('package' => $package)); + + if (!$config) { + $config = new PackageConfiguration(); + $config->setPackage($package); + } + + $this->entityManager->persist($config); + } + + /** + * @return array + */ + public static function getSubscribedEvents() + { + return array( + Events::PACKAGE_CREATE => array('onCreatePackage', 0), + CloneProjectEvents::PACKAGE_CLONED => array('onClonePackage', 0) + ); + } +} \ No newline at end of file diff --git a/src/Plugin/Sami/PackageConfiguration.php b/src/Plugin/Sami/PackageConfiguration.php new file mode 100644 index 0000000..2d1f9cc --- /dev/null +++ b/src/Plugin/Sami/PackageConfiguration.php @@ -0,0 +1,99 @@ +enabled = (bool) $enabled; + } + + /** + * @return boolean + */ + public function isEnabled() + { + return $this->enabled; + } + + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } + + /** + * @return Package + */ + public function getPackage() + { + return $this->package; + } + + /** + * @param Package $package + */ + public function setPackage(Package $package) + { + $this->package = $package; + } + + /** + * @return mixed + */ + public function getRepositoryPath() + { + return $this->repositoryPath; + } + + /** + * @param mixed $repositoryPath + */ + public function setRepositoryPath($repositoryPath) + { + $this->repositoryPath = (string) $repositoryPath; + } +} \ No newline at end of file diff --git a/src/Plugin/Sami/Plugin.php b/src/Plugin/Sami/Plugin.php new file mode 100644 index 0000000..5aaff0b --- /dev/null +++ b/src/Plugin/Sami/Plugin.php @@ -0,0 +1,59 @@ +register('packages.plugin.sami.subscriber', 'Terramar\Packages\Plugin\Sami\EventSubscriber') + ->addArgument(new Reference('packages.helper.resque')) + ->addArgument(new Reference('doctrine.orm.entity_manager')) + ->addTag('kernel.event_subscriber'); + + $container->getDefinition('packages.controller_manager') + ->addMethodCall('registerController', array(Actions::PACKAGE_EDIT, 'Terramar\Packages\Plugin\Sami\Controller::editAction')) + ->addMethodCall('registerController', array(Actions::PACKAGE_UPDATE, 'Terramar\Packages\Plugin\Sami\Controller::updateAction')); + } + + /** + * Get the plugin name + * + * @return string + */ + public function getName() + { + return 'Sami'; + } + + /** + * @return string + */ + public function getVersion() + { + return Sami::VERSION; + } +} \ No newline at end of file diff --git a/src/Plugin/Sami/UpdateJob.php b/src/Plugin/Sami/UpdateJob.php new file mode 100644 index 0000000..08c5fc8 --- /dev/null +++ b/src/Plugin/Sami/UpdateJob.php @@ -0,0 +1,103 @@ +getContainer()->getParameter('app.cache_dir') . '/sami/' . $package->getFqn(); + } + + /** + * @return EntityManager + */ + private function getEntityManager() + { + return $this->getContainer()->get('doctrine.orm.entity_manager'); + } + + public function run($args) + { + $package = $this->getEntityManager()->find('Terramar\Packages\Entity\Package', $args['id']); + if (!$package) { + throw new \RuntimeException('Invalid project'); + } + + $config = $this->getEntityManager()->getRepository('Terramar\Packages\Plugin\Sami\PackageConfiguration') + ->findOneBy(array('package' => $package)); + + if (!$config) { + throw new \RuntimeException('Invalid project configuration'); + } + + $cachePath = $this->getCacheDir($package); + + if (!is_dir($cachePath)) { + mkdir($cachePath, 0777, true); + } + + $configFilePath = $this->getCacheDir($package) . '/config.php'; + $this->writeConfig($configFilePath, $package, $config); + + $finder = new PhpExecutableFinder(); + $builder = new ProcessBuilder(array('vendor/bin/sami.php', 'update', $configFilePath)); + $builder->setEnv('HOME', $this->getContainer()->getParameter('app.root_dir')); + $builder->setPrefix($finder->find()); + + $process = $builder->getProcess(); + $process->run(function($type, $message) { + echo $message; + }); + } + + private function writeConfig($configFilePath, Package $package, PackageConfiguration $config) + { + $cachePath = $this->getCacheDir($package); + + $code = <<getRepositoryPath()}') + ->addFromTags() + ->add('master', 'master branch') + ->add('develop', 'develop branch') +; + +return new Sami\Sami('{$config->getRepositoryPath()}', array( + 'title' => '{$package->getName()}', + 'build_dir' => '$cachePath/build/%version%', + 'cache_dir' => '$cachePath/cache/%version%', + 'default_opened_level' => 2, + 'theme' => 'enhanced', + 'versions' => \$versions +)); +END; + + file_put_contents($configFilePath, $code); + } +} \ No newline at end of file diff --git a/views/Plugin/CloneProject/edit.html.twig b/views/Plugin/CloneProject/edit.html.twig new file mode 100644 index 0000000..4312687 --- /dev/null +++ b/views/Plugin/CloneProject/edit.html.twig @@ -0,0 +1,14 @@ +{% extends 'Plugin/_box.html.twig' %} + +{% block title %}Clone Project{% endblock %} + +{% block body %} +
+ Clone this project locally after each code push. +
+
+ +
+{% endblock %} \ No newline at end of file diff --git a/views/Plugin/Sami/edit.html.twig b/views/Plugin/Sami/edit.html.twig new file mode 100644 index 0000000..d862f3e --- /dev/null +++ b/views/Plugin/Sami/edit.html.twig @@ -0,0 +1,44 @@ +{% extends 'Plugin/_box.html.twig' %} + +{% block title %}Sami{% endblock %} + +{% block body %} +
+ Automatically generate documentation for this project using Sami +
+
+ +
+ +{% endblock %} + +{% block javascripts %} + +{% endblock %} From 6d069fdc0fee7ce0eb4a747d38f9acf7d43ab0dd Mon Sep 17 00:00:00 2001 From: Tyler Sommer Date: Tue, 27 Jan 2015 18:56:16 -0700 Subject: [PATCH 03/25] Added additional fields to sami configuration --- migrations.yml | 2 +- src/Application.php | 2 +- src/Console/Application.php | 2 + src/Migration/Version3100.php | 32 +++++++ src/Plugin/Sami/Controller.php | 5 ++ src/Plugin/Sami/PackageConfiguration.php | 107 ++++++++++++++++++++++- src/Plugin/Sami/UpdateJob.php | 19 ++-- views/Plugin/Sami/edit.html.twig | 32 ++++++- 8 files changed, 187 insertions(+), 14 deletions(-) create mode 100644 src/Migration/Version3100.php diff --git a/migrations.yml b/migrations.yml index cd3732b..8de5670 100644 --- a/migrations.yml +++ b/migrations.yml @@ -1,3 +1,3 @@ name: Terramar Labs Packages migrations_namespace: Terramar\Packages\Migration -migrations_directory: src/Terramar/Packages/Migration \ No newline at end of file +migrations_directory: src/Migration diff --git a/src/Application.php b/src/Application.php index 7ec4ba4..91d49f9 100644 --- a/src/Application.php +++ b/src/Application.php @@ -52,7 +52,7 @@ protected function registerDefaultExtensions() $this->appendExtension(new DoctrineOrmExtension($doctrine)); $this->appendExtension(new SessionExtension()); $this->appendExtension(new TemplatingExtension()); - $this->appendExtension(new TwigExtension($this->getRootDir() . '/views')); + $this->appendExtension(new TwigExtension()); $this->appendExtension(new SecurityExtension(array( 'authenticator' => array( 'type' => 'username', diff --git a/src/Console/Application.php b/src/Console/Application.php index ce0e7f3..9b646f8 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -12,6 +12,7 @@ use Doctrine\ORM\Tools\Console\ConsoleRunner; use Symfony\Component\Console\Application as BaseApplication; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\DialogHelper; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Terramar\Packages\Application as AppKernel; @@ -50,6 +51,7 @@ public function doRun(InputInterface $input, OutputInterface $output) { $this->setHelperSet(ConsoleRunner::createHelperSet($this->app->get('doctrine.orm.entity_manager'))); $this->getHelperSet()->set(new QuestionHelper()); + $this->getHelperSet()->set(new DialogHelper()); $this->registerCommands(); $this->io = new ConsoleIO($input, $output, $this->getHelperSet()); diff --git a/src/Migration/Version3100.php b/src/Migration/Version3100.php new file mode 100644 index 0000000..0d71a16 --- /dev/null +++ b/src/Migration/Version3100.php @@ -0,0 +1,32 @@ +getTable('packages_sami_configurations'); + $table->addColumn('remote_repo_path', 'string', array('default' => '')); + $table->addColumn('title', 'string', array('default' => '')); + $table->addColumn('theme', 'string', array('default' => '')); + $table->addColumn('tags', 'string', array('default' => '')); + $table->addColumn('refs', 'string', array('default' => '')); + } + + public function down(Schema $schema) + { + $table = $schema->getTable('packages_sami_configurations'); + $table->dropColumn('remote_repo_path'); + $table->dropColumn('title'); + $table->dropColumn('theme'); + $table->dropColumn('tags'); + $table->dropColumn('refs'); + } +} diff --git a/src/Plugin/Sami/Controller.php b/src/Plugin/Sami/Controller.php index ee4173b..f3d6d81 100644 --- a/src/Plugin/Sami/Controller.php +++ b/src/Plugin/Sami/Controller.php @@ -39,6 +39,11 @@ public function updateAction(Application $app, Request $request, $id) )); $config->setEnabled($request->get('sami_enabled') ? true : false); + $config->setTitle($request->get('sami_title')); + $config->setTheme($request->get('sami_theme')); + $config->setRemoteRepoPath($request->get('sami_remote_repo_path')); + $config->setTags($request->get('sami_tags')); + $config->setRefs($request->get('sami_refs')); $entityManager->persist($config); diff --git a/src/Plugin/Sami/PackageConfiguration.php b/src/Plugin/Sami/PackageConfiguration.php index 2d1f9cc..4aa0e7a 100644 --- a/src/Plugin/Sami/PackageConfiguration.php +++ b/src/Plugin/Sami/PackageConfiguration.php @@ -35,6 +35,31 @@ class PackageConfiguration */ private $repositoryPath = ''; + /** + * @ORM\Column(name="remote_repo_path", type="string") + */ + private $remoteRepoPath = ''; + + /** + * @ORM\Column(name="title", type="string") + */ + private $title = ''; + + /** + * @ORM\Column(name="theme", type="string") + */ + private $theme = 'symfony'; + + /** + * @ORM\Column(name="tags", type="string") + */ + private $tags = ''; + + /** + * @ORM\Column(name="refs", type="string") + */ + private $refs = ''; + /** * @ORM\ManyToOne(targetEntity="Terramar\Packages\Entity\Package") * @ORM\JoinColumn(name="package_id", referencedColumnName="id") @@ -96,4 +121,84 @@ public function setRepositoryPath($repositoryPath) { $this->repositoryPath = (string) $repositoryPath; } -} \ No newline at end of file + + /** + * @return mixed + */ + public function getRemoteRepoPath() + { + return $this->remoteRepoPath; + } + + /** + * @param mixed $remoteRepoPath + */ + public function setRemoteRepoPath($remoteRepoPath) + { + $this->remoteRepoPath = (string) $remoteRepoPath; + } + + /** + * @return mixed + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param mixed $title + */ + public function setTitle($title) + { + $this->title = (string) $title; + } + + /** + * @return mixed + */ + public function getTheme() + { + return $this->theme; + } + + /** + * @param mixed $theme + */ + public function setTheme($theme) + { + $this->theme = (string) $theme; + } + + /** + * @return mixed + */ + public function getTags() + { + return $this->tags; + } + + /** + * @param mixed $tags + */ + public function setTags($tags) + { + $this->tags = (string) $tags; + } + + /** + * @return mixed + */ + public function getRefs() + { + return $this->refs; + } + + /** + * @param mixed $refs + */ + public function setRefs($refs) + { + $this->refs = (string) $refs; + } +} diff --git a/src/Plugin/Sami/UpdateJob.php b/src/Plugin/Sami/UpdateJob.php index 08c5fc8..5e37f3d 100644 --- a/src/Plugin/Sami/UpdateJob.php +++ b/src/Plugin/Sami/UpdateJob.php @@ -71,7 +71,13 @@ public function run($args) private function writeConfig($configFilePath, Package $package, PackageConfiguration $config) { $cachePath = $this->getCacheDir($package); - + $tagsCode = $config->getTags() ? ' ->addFromTags(\'' . implode('\',\'', explode(',', $config->getTags())) . '\)'.PHP_EOL : ''; + $refsCode = ''; + foreach (explode(',', $config->getRefs()) as $ref) { + $parts = explode(':', $ref); + $refsCode .= ' ->add(\'' . $parts[0] . '\', \'' . $parts[1] . '\')'.PHP_EOL; + } + $code = <<getRepositoryPath()}') - ->addFromTags() - ->add('master', 'master branch') - ->add('develop', 'develop branch') -; +$tagsCode$refsCode; return new Sami\Sami('{$config->getRepositoryPath()}', array( - 'title' => '{$package->getName()}', + 'title' => '{$config->getTitle()}', 'build_dir' => '$cachePath/build/%version%', 'cache_dir' => '$cachePath/cache/%version%', 'default_opened_level' => 2, - 'theme' => 'enhanced', + 'theme' => '{$config->getTheme()}', 'versions' => \$versions )); END; file_put_contents($configFilePath, $code); } -} \ No newline at end of file +} diff --git a/views/Plugin/Sami/edit.html.twig b/views/Plugin/Sami/edit.html.twig index d862f3e..698599f 100644 --- a/views/Plugin/Sami/edit.html.twig +++ b/views/Plugin/Sami/edit.html.twig @@ -14,6 +14,26 @@ + + + + + {% endblock %} {% block javascripts %} @@ -23,12 +43,18 @@ var $enabled = $(document.getElementById('sami_enabled')); var $cloneEnabled = $(document.getElementById('cloneproject_enabled')); var $fix = $(document.getElementById('fix_cloneproject')); + var $fields = $('.sami-enabled'); $cloneEnabled.add($enabled).on('change', function() { - if ($enabled.is(':checked') && !$cloneEnabled.is(':checked')) { - $error.slideDown(); + if ($enabled.is(':checked')) { + $fields.slideDown(); + if (!$cloneEnabled.is(':checked')) { + $error.slideDown(); + } else { + $error.slideUp(); + } } else { - $error.slideUp(); + $fields.slideUp(); } }); From d2c236618f505e22dea1d5ee3318facbfc6c78cf Mon Sep 17 00:00:00 2001 From: Tyler Sommer Date: Tue, 27 Jan 2015 20:42:17 -0700 Subject: [PATCH 04/25] Updated migration, finished basic sami integration --- src/Migration/Version3100.php | 34 ++++--- src/Plugin/Sami/Controller.php | 1 + src/Plugin/Sami/PackageConfiguration.php | 21 +++++ src/Plugin/Sami/UpdateJob.php | 111 +++++++++++++++++++++-- views/Plugin/Sami/edit.html.twig | 4 + 5 files changed, 150 insertions(+), 21 deletions(-) diff --git a/src/Migration/Version3100.php b/src/Migration/Version3100.php index 0d71a16..e4069ec 100644 --- a/src/Migration/Version3100.php +++ b/src/Migration/Version3100.php @@ -12,21 +12,31 @@ class Version3100 extends AbstractMigration { public function up(Schema $schema) { - $table = $schema->getTable('packages_sami_configurations'); - $table->addColumn('remote_repo_path', 'string', array('default' => '')); - $table->addColumn('title', 'string', array('default' => '')); - $table->addColumn('theme', 'string', array('default' => '')); - $table->addColumn('tags', 'string', array('default' => '')); - $table->addColumn('refs', 'string', array('default' => '')); + $table = $schema->createTable('packages_sami_configurations'); + $table->addColumn('id', 'integer'); + $table->setPrimaryKey(array('id')); + $table->addColumn('enabled', 'boolean'); + $table->addColumn('package_id', 'integer'); + $table->addColumn('docs_path', 'string'); + $table->addColumn('repo_path', 'string'); + $table->addColumn('remote_repo_path', 'string'); + $table->addColumn('title', 'string'); + $table->addColumn('theme', 'string'); + $table->addColumn('tags', 'string'); + $table->addColumn('refs', 'string'); + $table->addForeignKeyConstraint('packages', array('package_id'), array('id')); + + $table = $schema->createTable('packages_cloneproject_configurations'); + $table->addColumn('id', 'integer'); + $table->setPrimaryKey(array('id')); + $table->addColumn('enabled', 'boolean'); + $table->addColumn('package_id', 'integer'); + $table->addForeignKeyConstraint('packages', array('package_id'), array('id')); } public function down(Schema $schema) { - $table = $schema->getTable('packages_sami_configurations'); - $table->dropColumn('remote_repo_path'); - $table->dropColumn('title'); - $table->dropColumn('theme'); - $table->dropColumn('tags'); - $table->dropColumn('refs'); + $schema->dropTable('packages_sami_configurations'); + $schema->dropTable('packages_cloneproject_configurations'); } } diff --git a/src/Plugin/Sami/Controller.php b/src/Plugin/Sami/Controller.php index f3d6d81..6b81851 100644 --- a/src/Plugin/Sami/Controller.php +++ b/src/Plugin/Sami/Controller.php @@ -44,6 +44,7 @@ public function updateAction(Application $app, Request $request, $id) $config->setRemoteRepoPath($request->get('sami_remote_repo_path')); $config->setTags($request->get('sami_tags')); $config->setRefs($request->get('sami_refs')); + $config->setDocsPath($request->get('sami_docs_path')); $entityManager->persist($config); diff --git a/src/Plugin/Sami/PackageConfiguration.php b/src/Plugin/Sami/PackageConfiguration.php index 4aa0e7a..9317266 100644 --- a/src/Plugin/Sami/PackageConfiguration.php +++ b/src/Plugin/Sami/PackageConfiguration.php @@ -40,6 +40,11 @@ class PackageConfiguration */ private $remoteRepoPath = ''; + /** + * @ORM\Column(name="docs_path", type="string") + */ + private $docsPath = 'src/'; + /** * @ORM\Column(name="title", type="string") */ @@ -201,4 +206,20 @@ public function setRefs($refs) { $this->refs = (string) $refs; } + + /** + * @return mixed + */ + public function getDocsPath() + { + return $this->docsPath; + } + + /** + * @param mixed $docsPath + */ + public function setDocsPath($docsPath) + { + $this->docsPath = (string) $docsPath; + } } diff --git a/src/Plugin/Sami/UpdateJob.php b/src/Plugin/Sami/UpdateJob.php index 5e37f3d..cb4021d 100644 --- a/src/Plugin/Sami/UpdateJob.php +++ b/src/Plugin/Sami/UpdateJob.php @@ -49,14 +49,14 @@ public function run($args) } $cachePath = $this->getCacheDir($package); - + if (!is_dir($cachePath)) { mkdir($cachePath, 0777, true); } - - $configFilePath = $this->getCacheDir($package) . '/config.php'; + + $configFilePath = $cachePath . '/config.php'; $this->writeConfig($configFilePath, $package, $config); - + $finder = new PhpExecutableFinder(); $builder = new ProcessBuilder(array('vendor/bin/sami.php', 'update', $configFilePath)); $builder->setEnv('HOME', $this->getContainer()->getParameter('app.root_dir')); @@ -66,6 +66,90 @@ public function run($args) $process->run(function($type, $message) { echo $message; }); + + if ($config->getRemoteRepoPath()) { + $localRepoPath = $cachePath . '/remote'; + $this->emptyAndRemoveDirectory($localRepoPath); + $buildPath = $cachePath . '/build'; + + $builder = new ProcessBuilder(array( + 'clone', + $config->getRemoteRepoPath(), + $localRepoPath + )); + $builder->setPrefix('git'); + $process = $builder->getProcess(); + $process->run(function ($type, $message) { + echo $message; + }); + + foreach ($this->getRefs($config) as $ref) { + $builder = new ProcessBuilder(array( + 'checkout', + $ref[0] + )); + $builder->setPrefix('git'); + $process = $builder->getProcess(); + $process->setWorkingDirectory($localRepoPath); + $process->run(function ($type, $message) { + echo $message; + }); + + $builder = new ProcessBuilder(array( + '-R', + $buildPath.'/'.$ref[0].'/', + '.' + )); + $builder->setPrefix('cp'); + $process = $builder->getProcess(); + $process->setWorkingDirectory($localRepoPath); + $process->run(function ($type, $message) { + echo $message; + }); + + $builder = new ProcessBuilder(array( + 'add', + '.' + )); + $builder->setPrefix('git'); + $process = $builder->getProcess(); + $process->setWorkingDirectory($localRepoPath); + $process->run(function ($type, $message) { + echo $message; + }); + + $builder = new ProcessBuilder(array( + 'commit', + '-m', + 'Automated commit' + )); + $builder->setPrefix('git'); + $process = $builder->getProcess(); + $process->setWorkingDirectory($localRepoPath); + $process->run(function ($type, $message) { + echo $message; + }); + + $builder = new ProcessBuilder(array( + 'push', + 'origin', + $ref[0] + )); + $builder->setPrefix('git'); + $process = $builder->getProcess(); + $process->setWorkingDirectory($localRepoPath); + $process->run(function ($type, $message) { + echo $message; + }); + } + } + } + + private function getRefs(PackageConfiguration $config) + { + return array_map(function($value) { + return explode(':', $value); + }, explode(',', $config->getRefs())); } private function writeConfig($configFilePath, Package $package, PackageConfiguration $config) @@ -73,9 +157,8 @@ private function writeConfig($configFilePath, Package $package, PackageConfigura $cachePath = $this->getCacheDir($package); $tagsCode = $config->getTags() ? ' ->addFromTags(\'' . implode('\',\'', explode(',', $config->getTags())) . '\)'.PHP_EOL : ''; $refsCode = ''; - foreach (explode(',', $config->getRefs()) as $ref) { - $parts = explode(':', $ref); - $refsCode .= ' ->add(\'' . $parts[0] . '\', \'' . $parts[1] . '\')'.PHP_EOL; + foreach ($this->getRefs($config) as $ref) { + $refsCode .= ' ->add(\'' . $ref[0] . '\', \'' . $ref[1] . '\')'.PHP_EOL; } $code = <<getRepositoryPath()}') +\$versions = Sami\Version\GitVersionCollection::create('{$config->getRepositoryPath()}/{$config->getDocsPath()}') $tagsCode$refsCode; -return new Sami\Sami('{$config->getRepositoryPath()}', array( +return new Sami\Sami('{$config->getRepositoryPath()}/{$config->getDocsPath()}', array( 'title' => '{$config->getTitle()}', 'build_dir' => '$cachePath/build/%version%', 'cache_dir' => '$cachePath/cache/%version%', @@ -103,4 +186,14 @@ private function writeConfig($configFilePath, Package $package, PackageConfigura file_put_contents($configFilePath, $code); } + + private function emptyAndRemoveDirectory($directory) + { + $files = array_diff(scandir($directory), array('.','..')); + foreach ($files as $file) { + (is_dir("$directory/$file")) ? $this->emptyAndRemoveDirectory("$directory/$file") : unlink("$directory/$file"); + } + + return rmdir($directory); + } } diff --git a/views/Plugin/Sami/edit.html.twig b/views/Plugin/Sami/edit.html.twig index 698599f..5a0b10b 100644 --- a/views/Plugin/Sami/edit.html.twig +++ b/views/Plugin/Sami/edit.html.twig @@ -30,6 +30,10 @@ + +
{% if packages|length %} - +
@@ -51,3 +51,11 @@ {% endblock %} + +{% block javascripts %} + +{% endblock %} diff --git a/views/base.html.twig b/views/base.html.twig index dab658b..3c20504 100644 --- a/views/base.html.twig +++ b/views/base.html.twig @@ -13,6 +13,16 @@ + + + + + + + + + + + - - - - - - {% endblock %} diff --git a/views/Plugin/Sami/edit.html.twig b/views/Plugin/Sami/edit.html.twig index 389c2f0..31518b0 100644 --- a/views/Plugin/Sami/edit.html.twig +++ b/views/Plugin/Sami/edit.html.twig @@ -52,10 +52,12 @@ var $cloneEnabled = $(document.getElementById('cloneproject_enabled')); var $fix = $(document.getElementById('fix_cloneproject')); var $fields = $('.sami-enabled'); + var $requiredFields = $fields.find('[required]'); $cloneEnabled.add($enabled).on('change', function() { if ($enabled.is(':checked')) { $fields.slideDown(); + $requiredFields.attr('required', true); if (!$cloneEnabled.is(':checked')) { $error.slideDown(); } else { @@ -63,6 +65,8 @@ } } else { $fields.slideUp(); + $error.slideUp(); + $requiredFields.removeAttr('required'); } }); diff --git a/views/Remote/index.html.twig b/views/Remote/index.html.twig index 1ce469f..520a9d5 100644 --- a/views/Remote/index.html.twig +++ b/views/Remote/index.html.twig @@ -16,12 +16,12 @@
{% if remotes|length %} -
Name
+
- + @@ -50,3 +50,16 @@ {% endblock %} + +{% block javascripts %} + +{% endblock %} diff --git a/views/base.html.twig b/views/base.html.twig index 2d59fa5..34d026d 100644 --- a/views/base.html.twig +++ b/views/base.html.twig @@ -11,13 +11,14 @@ - - - + + + + - - - + - - -
Name EnabledActions