diff --git a/app/SymfonyRequirements.php b/app/SymfonyRequirements.php index 4df46d1..0e416b8 100644 --- a/app/SymfonyRequirements.php +++ b/app/SymfonyRequirements.php @@ -500,9 +500,9 @@ function_exists('simplexml_import_dom'), $pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null; $this->addRequirement( - null !== $pcreVersion && $pcreVersion > 8.0, - sprintf('PCRE extension must be available and at least 8.0 (%s installed)', $pcreVersion ? $pcreVersion : 'not'), - 'Upgrade your PCRE extension (8.0+).' + null !== $pcreVersion, + 'PCRE extension must be available', + 'Install the PCRE extension (version 8.0+).' ); /* optional recommendations follow */ @@ -531,6 +531,14 @@ function_exists('simplexml_import_dom'), 'Your project might not work properly due to the PHP bug #61453 ("Cannot dump definitions which have method calls"). Install PHP 5.4.1 or newer.' ); + if (null !== $pcreVersion) { + $this->addRecommendation( + $pcreVersion >= 8.0, + sprintf('PCRE extension should be at least version 8.0 (%s installed)', $pcreVersion), + 'PCRE 8.0+ is preconfigured in PHP since 5.3.2 but you are using an outdated version of it. Symfony probably works anyway but it is recommended to upgrade your PCRE extension.' + ); + } + $this->addRecommendation( class_exists('DomDocument'), 'PHP-XML module should be installed', diff --git a/src/ServerGrove/KbBundle/Controller/Admin/CategoriesController.php b/src/ServerGrove/KbBundle/Controller/Admin/CategoriesController.php index f9ec60b..08c9c2d 100644 --- a/src/ServerGrove/KbBundle/Controller/Admin/CategoriesController.php +++ b/src/ServerGrove/KbBundle/Controller/Admin/CategoriesController.php @@ -6,6 +6,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use ServerGrove\KbBundle\Document\Article; use ServerGrove\KbBundle\Document\Category; @@ -222,14 +223,19 @@ public function updateAction(Category $category) * Deletes a Category document. * * @Route("/{path}/delete", name="sgkb_admin_categories_delete", requirements={"path":".+"}) + * @Route("/{path}/delete/confirmed", name="sgkb_admin_categories_delete_confirmed", requirements={"path":".+"}) * @Method("post") * @ParamConverter("category", class="ServerGroveKbBundle:Category") * */ public function deleteAction(Category $category) { - $form = $this->createDeleteForm($category); $request = $this->getRequest(); + if ('sgkb_admin_categories_delete_confirmed' != $request->get('_route')) { + return $this->forward('ServerGroveKbBundle:Admin/Categories:deleteConfirmation', array('category' => $category)); + } + + $form = $this->createDeleteForm($category); $form->bind($request); @@ -241,11 +247,30 @@ public function deleteAction(Category $category) $dm->remove($category); $dm->flush(); + } else { + var_dump($form->getErrorsAsString()); + exit; } return $this->redirect($this->generateUrl('sgkb_admin_categories_index')); } + /** + * Confirmation action for category removal + * + * @Template + * + * @param Category $category + * + * @return array + */ + public function deleteConfirmationAction(Category $category) + { + $form = $this->createDeleteForm($category); + + return array('category' => $category, 'form' => $form->createView()); + } + /** * Lists all Article documents. * @@ -274,6 +299,7 @@ public function removeArticlesFromCategory() { /** @var $category Category */ $category = func_get_arg(1 == func_num_args() ? 0 : 1); + $this->get('logger')->info(sprintf('Removing articles from category "%s"', $category->getName())); if (!($category instanceof Category)) { throw new \RuntimeException('Expected instance of Category'); @@ -294,14 +320,10 @@ public function removeArticlesFromCategory() public function removeChildrenFromCategory(Category $category) { - $controller = $this; - + $this->get('logger')->info(sprintf('Removing children from category "%s"', $category->getName())); foreach ($category->getChildren() as $child) { - call_user_func(array($controller, 'removeArticlesFromCategory'), $child); - call_user_func(array($controller, 'removeChildrenFromCategory'), $child); - - /** @var $category Category */ - $category->getChildren()->removeElement($child); + call_user_func(array($this, 'removeArticlesFromCategory'), $child); + call_user_func(array($this, 'removeChildrenFromCategory'), $child); } } diff --git a/src/ServerGrove/KbBundle/Document/Category.php b/src/ServerGrove/KbBundle/Document/Category.php index 848d5aa..0a3aa3c 100644 --- a/src/ServerGrove/KbBundle/Document/Category.php +++ b/src/ServerGrove/KbBundle/Document/Category.php @@ -401,4 +401,12 @@ public function getVisibility() { return $this->visibility; } + + /** + * @return bool + */ + public function hasCategoriesOrArticles() + { + return 0 < $this->getArticles()->count() || 0 < $this->getChildren()->count(); + } } diff --git a/src/ServerGrove/KbBundle/Resources/public/js/backend/admin-angular.js b/src/ServerGrove/KbBundle/Resources/public/js/backend/admin-angular.js index 68419ec..1029af7 100644 --- a/src/ServerGrove/KbBundle/Resources/public/js/backend/admin-angular.js +++ b/src/ServerGrove/KbBundle/Resources/public/js/backend/admin-angular.js @@ -53,9 +53,11 @@ method: '@method', confirmation: '@confirmation' }, - link: function (scope, element, attrs) { + link: function (scope, element) { scope.doDelete = function () { - if (window.confirm(scope.confirmation)) { + if (angular.isUndefined(scope.confirmation) || !angular.isString(scope.confirmation)) { + element.find('form').submit(); + } else if (window.confirm(scope.confirmation)) { element.find('form').submit(); } }; @@ -307,11 +309,11 @@ var timeout = null, state, nextCall; - $scope.$watch('categories.values', function (newValue, oldValue) { + $scope.$watch('categories.values', function () { $scope.categories.invalid = 0 === $scope.categories.values.length; }); - $scope.$watch('title.value', function (newValue, oldValue) { + $scope.$watch('title.value', function (newValue) { if ('' === newValue || null === newValue) { window.clearTimeout(timeout); diff --git a/src/ServerGrove/KbBundle/Resources/views/Admin/Articles/edit.html.twig b/src/ServerGrove/KbBundle/Resources/views/Admin/Articles/edit.html.twig index 2f315ac..9ca3cbd 100644 --- a/src/ServerGrove/KbBundle/Resources/views/Admin/Articles/edit.html.twig +++ b/src/ServerGrove/KbBundle/Resources/views/Admin/Articles/edit.html.twig @@ -73,7 +73,7 @@