From 78cba61cd56938cdde781278a3c515daffdcd7ec Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 30 Oct 2013 15:33:25 +0100 Subject: [PATCH] finish admin update password command line --- core/lib/Thelia/Action/Administrator.php | 7 ++-- ...ord.php => AdminUpdatePasswordCommand.php} | 41 ++++++++++++++++++- core/lib/Thelia/Config/Resources/config.xml | 1 + .../AdministratorUpdatePasswordEvent.php | 23 ++++++----- local/modules/Cheque/Config/config.xml | 2 +- 5 files changed, 57 insertions(+), 17 deletions(-) rename core/lib/Thelia/Command/{AdminUpdatePassword.php => AdminUpdatePasswordCommand.php} (70%) diff --git a/core/lib/Thelia/Action/Administrator.php b/core/lib/Thelia/Action/Administrator.php index 23167dd40..15940082a 100644 --- a/core/lib/Thelia/Action/Administrator.php +++ b/core/lib/Thelia/Action/Administrator.php @@ -95,10 +95,9 @@ class Administrator extends BaseAction implements EventSubscriberInterface public function updatePassword(AdministratorUpdatePasswordEvent $event) { - if (null !== $admin = AdminQuery::create()->filterByLogin($event->getLogin())->findOne()) { - $admin->setPassword($event->getPassword()) - ->save(); - } + $admin = $event->getAdmin(); + $admin->setPassword($event->getPassword()) + ->save(); } /** diff --git a/core/lib/Thelia/Command/AdminUpdatePassword.php b/core/lib/Thelia/Command/AdminUpdatePasswordCommand.php similarity index 70% rename from core/lib/Thelia/Command/AdminUpdatePassword.php rename to core/lib/Thelia/Command/AdminUpdatePasswordCommand.php index f6cf8ee64..035dc75e3 100644 --- a/core/lib/Thelia/Command/AdminUpdatePassword.php +++ b/core/lib/Thelia/Command/AdminUpdatePasswordCommand.php @@ -22,8 +22,15 @@ /*************************************************************************************/ namespace Thelia\Command; + use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\AdminQuery; +use Thelia\Tools\Password; /** @@ -31,11 +38,11 @@ use Symfony\Component\Console\Input\InputOption; * * php Thelia admin:updatePassword * - * Class AdminUpdatePassword + * Class AdminUpdatePasswordCommand * @package Thelia\Command * @author Manuel Raynaud */ -class AdminUpdatePassword extends ContainerAwareCommand +class AdminUpdatePasswordCommand extends ContainerAwareCommand { /** @@ -60,4 +67,34 @@ class AdminUpdatePassword extends ContainerAwareCommand ) ; } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $login = $input->getArgument('login'); + + + if (null === $admin = AdminQuery::create()->filterByLogin($login)->findOne()) { + throw new \RuntimeException(sprintf('Admin with login %s does not exists', $login)); + } + + + $password = $input->getOption('password') ?: Password::generateRandom(); + + $event = new AdministratorUpdatePasswordEvent($admin); + $event->setPassword($password); + + + $this-> + getContainer() + ->get('event_dispatcher') + ->dispatch(TheliaEvents::ADMINISTRATOR_UPDATEPASSWORD, $event); + + $output->writeln(array( + '', + sprintf('admin %s password updated', $login), + sprintf('new password is : %s', $password), + '' + )); + + } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index c0af99896..255f70dfd 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -182,6 +182,7 @@ + diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php index b41b83a06..e6a5894ac 100644 --- a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -23,6 +23,7 @@ namespace Thelia\Core\Event\Administrator; use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Admin; /** @@ -34,18 +35,18 @@ class AdministratorUpdatePasswordEvent extends ActionEvent { /** - * @var string administrator login + * @var \Thelia\Model\Admin */ - protected $login; + protected $admin; /** * @var string new administrator password */ protected $password; - public function __construct($login) + public function __construct(Admin $admin) { - $this->login = $login; + $this->admin = $admin; } /** @@ -65,20 +66,22 @@ class AdministratorUpdatePasswordEvent extends ActionEvent } /** - * @param string $login + * @param \Thelia\Model\Admin $admin */ - public function setLogin($login) + public function setAdmin(Admin $admin) { - $this->login = $login; + $this->admin = $admin; } /** - * @return string + * @return \Thelia\Model\Admin */ - public function getLogin() + public function getAdmin() { - return $this->login; + return $this->admin; } + + } \ No newline at end of file diff --git a/local/modules/Cheque/Config/config.xml b/local/modules/Cheque/Config/config.xml index 2430f5027..cac3f6b7b 100755 --- a/local/modules/Cheque/Config/config.xml +++ b/local/modules/Cheque/Config/config.xml @@ -1,4 +1,4 @@ - +string