From 78507d28357b132237ad35ecdf0704d1ca56dfaa Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 6 Nov 2015 23:39:19 +0100 Subject: Fix deprecated helper in command --- src/Wallabag/CoreBundle/Command/InstallCommand.php | 45 +++++++------- .../Tests/Command/InstallCommandTest.php | 72 +++++++++------------- 2 files changed, 54 insertions(+), 63 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 6ebbd93c..808baaf6 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -8,6 +8,9 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\NullOutput; +use Symfony\Component\Console\Question\Question; +use Symfony\Component\Console\Question\ConfirmationQuestion; +use Symfony\Component\Console\Helper\Table; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Config; @@ -85,10 +88,11 @@ class InstallCommand extends ContainerAwareCommand } $rows[] = array($label, $status, $help); - $this->getHelper('table') + $table = new Table($this->defaultOutput); + $table ->setHeaders(array('Checked', 'Status', 'Recommendation')) ->setRows($rows) - ->render($this->defaultOutput); + ->render(); if (!$fulfilled) { throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.'); @@ -130,9 +134,10 @@ class InstallCommand extends ContainerAwareCommand return $this; } - $dialog = $this->getHelper('dialog'); + $questionHelper = $this->getHelper('question'); + $question = new ConfirmationQuestion('It appears that your database already exists. Would you like to reset it? (y/N)', false); - if ($dialog->askConfirmation($this->defaultOutput, 'It appears that your database already exists. Would you like to reset it? (y/N) ', false)) { + if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { $this->defaultOutput->writeln('Droping database, creating database and schema'); $this @@ -141,7 +146,8 @@ class InstallCommand extends ContainerAwareCommand ->runCommand('doctrine:schema:create') ; } elseif ($this->isSchemaPresent()) { - if ($dialog->askConfirmation($this->defaultOutput, 'Seems like your database contains schema. Do you want to reset it? (y/N) ', false)) { + $question = new ConfirmationQuestion('Seems like your database contains schema. Do you want to reset it? (y/N)', false); + if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { $this->defaultOutput->writeln('Droping schema and creating schema'); $this @@ -160,17 +166,6 @@ class InstallCommand extends ContainerAwareCommand $this->defaultOutput->writeln('Clearing the cache'); $this->runCommand('cache:clear'); - /* - if ($this->getHelperSet()->get('dialog')->askConfirmation($this->defaultOutput, 'Load fixtures (Y/N)?', false)) { - $doctrineConfig = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection()->getConfiguration(); - $logger = $doctrineConfig->getSQLLogger(); - // speed up fixture load - $doctrineConfig->setSQLLogger(null); - $this->runCommand('doctrine:fixtures:load'); - $doctrineConfig->setSQLLogger($logger); - } - */ - $this->defaultOutput->writeln(''); return $this; @@ -180,9 +175,10 @@ class InstallCommand extends ContainerAwareCommand { $this->defaultOutput->writeln('Step 3 of 4. Administration setup.'); - $dialog = $this->getHelperSet()->get('dialog'); + $questionHelper = $this->getHelperSet()->get('question'); + $question = new ConfirmationQuestion('Would you like to create a new user ? (y/N)', false); - if (false === $dialog->askConfirmation($this->defaultOutput, 'Would you like to create a new user ? (y/N)', true)) { + if (!$questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { return $this; } @@ -190,9 +186,16 @@ class InstallCommand extends ContainerAwareCommand $userManager = $this->getContainer()->get('fos_user.user_manager'); $user = $userManager->createUser(); - $user->setUsername($dialog->ask($this->defaultOutput, 'Username (default: wallabag) :', 'wallabag')); - $user->setPlainPassword($dialog->ask($this->defaultOutput, 'Password (default: wallabag) :', 'wallabag')); - $user->setEmail($dialog->ask($this->defaultOutput, 'Email:', '')); + + $question = new Question('Username (default: wallabag) :', 'wallabag'); + $user->setUsername($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); + + $question = new Question('Password (default: wallabag) :', 'wallabag'); + $user->setPlainPassword($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); + + $question = new Question('Email:', ''); + $user->setEmail($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); + $user->setEnabled(true); $em->persist($user); diff --git a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php index 24910e60..e98dd202 100644 --- a/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php +++ b/src/Wallabag/CoreBundle/Tests/Command/InstallCommandTest.php @@ -35,19 +35,16 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->any()) + $question->expects($this->any()) ->method('ask') - ->will($this->returnValue('test_'.uniqid('', true))); - $dialog->expects($this->any()) - ->method('askConfirmation') - ->will($this->returnValue(true)); + ->will($this->returnValue('yes_'.uniqid('', true))); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( @@ -69,19 +66,16 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->any()) + $question->expects($this->any()) ->method('ask') - ->will($this->returnValue('test_'.uniqid('', true))); - $dialog->expects($this->any()) - ->method('askConfirmation') - ->will($this->returnValue(true)); + ->will($this->returnValue('yes_'.uniqid('', true))); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( @@ -119,19 +113,16 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->any()) + $question->expects($this->any()) ->method('ask') - ->will($this->returnValue('test_'.uniqid('', true))); - $dialog->expects($this->any()) - ->method('askConfirmation') - ->will($this->returnValue(true)); + ->will($this->returnValue('yes_'.uniqid('', true))); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( @@ -156,13 +147,13 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->exactly(3)) - ->method('askConfirmation') + $question->expects($this->exactly(3)) + ->method('ask') ->will($this->onConsecutiveCalls( false, // don't want to reset the entire database true, // do want to reset the schema @@ -170,7 +161,7 @@ class InstallCommandTest extends WallabagCoreTestCase )); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( @@ -216,20 +207,20 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->exactly(2)) - ->method('askConfirmation') + $question->expects($this->exactly(2)) + ->method('ask') ->will($this->onConsecutiveCalls( false, // don't want to reset the entire database false // don't want to create a new user )); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( @@ -253,19 +244,16 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the DialogHelper - $dialog = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper') + // We mock the QuestionHelper + $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') ->disableOriginalConstructor() ->getMock(); - $dialog->expects($this->any()) + $question->expects($this->any()) ->method('ask') - ->will($this->returnValue('test_'.uniqid('', true))); - $dialog->expects($this->any()) - ->method('askConfirmation') - ->will($this->returnValue(true)); + ->will($this->returnValue('yes_'.uniqid('', true))); // We override the standard helper with our mock - $command->getHelperSet()->set($dialog, 'dialog'); + $command->getHelperSet()->set($question, 'question'); $tester = new CommandTester($command); $tester->execute(array( -- cgit v1.2.3 From 18f8f32f70a3f76b307f4255eee0f51187b07283 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 7 Nov 2015 00:17:37 +0100 Subject: Fix security.context deprecation --- src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 4 ++-- src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php | 6 +++--- src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php | 12 ++++++------ src/Wallabag/CoreBundle/Resources/config/services.yml | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 1fee56ad..74bfe4dc 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -40,7 +40,7 @@ class WallabagRestController extends FOSRestController private function validateAuthentication() { - if (false === $this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) { + if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { throw new AccessDeniedException(); } } @@ -347,7 +347,7 @@ class WallabagRestController extends FOSRestController */ private function validateUserAccess($requestUserId) { - $user = $this->get('security.context')->getToken()->getUser(); + $user = $this->get('security.token_storage')->getToken()->getUser(); if ($requestUserId != $user->getId()) { throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$requestUserId.', logged user id: '.$user->getId()); } diff --git a/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php b/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php index 119889b3..09cde0f6 100644 --- a/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php @@ -25,7 +25,6 @@ abstract class AbstractControllerTest extends WebTestCase $client = static::createClient(); $container = $client->getContainer(); - $session = $container->get('session'); /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ $userManager = $container->get('fos_user.user_manager'); /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ @@ -36,9 +35,10 @@ abstract class AbstractControllerTest extends WebTestCase $loginManager->loginUser($firewallName, $user); // save the login token into the session and put it in a cookie - $container->get('session')->set('_security_'.$firewallName, - serialize($container->get('security.context')->getToken())); + $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); $container->get('session')->save(); + + $session = $container->get('session'); $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId())); return $client; diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php index 054a3752..489f39d1 100644 --- a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php +++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php @@ -3,7 +3,7 @@ namespace Wallabag\CoreBundle\Helper; use Liip\ThemeBundle\Helper\DeviceDetectionInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\UserBundle\Entity\User; /** @@ -14,16 +14,16 @@ use Wallabag\UserBundle\Entity\User; */ class DetectActiveTheme implements DeviceDetectionInterface { - protected $securityContext; + protected $tokenStorage; protected $defaultTheme; /** - * @param SecurityContextInterface $securityContext Needed to retrieve the current user + * @param TokenStorageInterface $tokenStorage Needed to retrieve the current user * @param string $defaultTheme Default theme when user isn't logged in */ - public function __construct(SecurityContextInterface $securityContext, $defaultTheme) + public function __construct(TokenStorageInterface $tokenStorage, $defaultTheme) { - $this->securityContext = $securityContext; + $this->tokenStorage = $tokenStorage; $this->defaultTheme = $defaultTheme; } @@ -42,7 +42,7 @@ class DetectActiveTheme implements DeviceDetectionInterface */ public function getType() { - $token = $this->securityContext->getToken(); + $token = $this->tokenStorage->getToken(); if (is_null($token)) { return $this->defaultTheme; diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 3c479ff6..debbf39e 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -2,7 +2,7 @@ services: wallabag_core.helper.detect_active_theme: class: Wallabag\CoreBundle\Helper\DetectActiveTheme arguments: - - @security.context + - @security.token_storage - %theme% # default theme from parameters.yml # custom form type -- cgit v1.2.3 From 33fe61f92f4165f5e100499013c141df1e663e60 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 7 Nov 2015 00:18:06 +0100 Subject: Fix form_enctype deprecation Use form_start instead --- src/Wallabag/CoreBundle/Controller/ConfigController.php | 16 +++++++++++----- .../Resources/views/themes/baggy/Config/index.html.twig | 10 +++++----- .../views/themes/material/Config/index.html.twig | 14 +++++--------- 3 files changed, 21 insertions(+), 19 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index ca4acc6a..8bbe4ca0 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -29,7 +29,7 @@ class ConfigController extends Controller $user = $this->getUser(); // handle basic config detail (this form is defined as a service) - $configForm = $this->createForm('config', $config); + $configForm = $this->createForm('config', $config, array('action' => $this->generateUrl('config'))); $configForm->handleRequest($request); if ($configForm->isValid()) { @@ -49,7 +49,7 @@ class ConfigController extends Controller } // handle changing password - $pwdForm = $this->createForm(new ChangePasswordType()); + $pwdForm = $this->createForm(new ChangePasswordType(), null, array('action' => $this->generateUrl('config').'#set4')); $pwdForm->handleRequest($request); if ($pwdForm->isValid()) { @@ -65,7 +65,10 @@ class ConfigController extends Controller } // handle changing user information - $userForm = $this->createForm(new UserInformationType(), $user, array('validation_groups' => array('Profile'))); + $userForm = $this->createForm(new UserInformationType(), $user, array( + 'validation_groups' => array('Profile'), + 'action' => $this->generateUrl('config').'#set3', + )); $userForm->handleRequest($request); if ($userForm->isValid()) { @@ -80,7 +83,7 @@ class ConfigController extends Controller } // handle rss information - $rssForm = $this->createForm(new RssType(), $config); + $rssForm = $this->createForm(new RssType(), $config, array('action' => $this->generateUrl('config').'#set2')); $rssForm->handleRequest($request); if ($rssForm->isValid()) { @@ -99,7 +102,10 @@ class ConfigController extends Controller $newUser = $userManager->createUser(); // enable created user by default $newUser->setEnabled(true); - $newUserForm = $this->createForm(new NewUserType(), $newUser, array('validation_groups' => array('Profile'))); + $newUserForm = $this->createForm(new NewUserType(), $newUser, array( + 'validation_groups' => array('Profile'), + 'action' => $this->generateUrl('config').'#set5', + )); $newUserForm->handleRequest($request); if ($newUserForm->isValid() && $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) { diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig index abe5dc9e..7a7d6af1 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Config/index.html.twig @@ -5,7 +5,7 @@ {% block content %}

{% trans %}Wallabag configuration{% endtrans %}

-
+ {{ form_start(form.config) }} {{ form_errors(form.config) }}
@@ -37,7 +37,7 @@

{% trans %}RSS configuration{% endtrans %}

- + {{ form_start(form.rss) }} {{ form_errors(form.rss) }}
@@ -81,7 +81,7 @@

{% trans %}User information{% endtrans %}

- + {{ form_start(form.user) }} {{ form_errors(form.user) }}
@@ -115,7 +115,7 @@

{% trans %}Change your password{% endtrans %}

- + {{ form_start(form.pwd) }} {{ form_errors(form.pwd) }}
@@ -148,7 +148,7 @@ {% if is_granted('ROLE_SUPER_ADMIN') %}

{% trans %}Add a user{% endtrans %}

- + {{ form_start(form.new_user) }} {{ form_errors(form.new_user) }}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig index ab24d4ef..8f121a2b 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Config/index.html.twig @@ -21,9 +21,8 @@ -
- + {{ form_start(form.config) }} {{ form_errors(form.config) }}
@@ -57,9 +56,8 @@
-
-
+ {{ form_start(form.rss) }} {{ form_errors(form.rss) }}
@@ -111,9 +109,8 @@
-
-
+ {{ form_start(form.user) }} {{ form_errors(form.user) }}
@@ -150,9 +147,8 @@
-
-
+ {{ form_start(form.pwd) }} {{ form_errors(form.pwd) }}
@@ -189,7 +185,7 @@ {% if is_granted('ROLE_SUPER_ADMIN') %}
- + {{ form_start(form.new_user) }} {{ form_errors(form.new_user) }}
-- cgit v1.2.3 From 164d260c498a74b6b97a17dd63f9dd6088702ebc Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 7 Nov 2015 00:27:41 +0100 Subject: CS Also force SYMFONY_DEPRECATIONS_HELPER for travis --- src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php index 489f39d1..23e98042 100644 --- a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php +++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php @@ -18,8 +18,8 @@ class DetectActiveTheme implements DeviceDetectionInterface protected $defaultTheme; /** - * @param TokenStorageInterface $tokenStorage Needed to retrieve the current user - * @param string $defaultTheme Default theme when user isn't logged in + * @param TokenStorageInterface $tokenStorage Needed to retrieve the current user + * @param string $defaultTheme Default theme when user isn't logged in */ public function __construct(TokenStorageInterface $tokenStorage, $defaultTheme) { -- cgit v1.2.3