container = $container; $this->em = $em; } protected function configure() { $this ->setName('app:SetPassword') ->setDescription("Modifier le password d'un utilisateur") ->setHelp("Modifier le password d'un utilisateur") ->addArgument('username', InputArgument::OPTIONAL, 'username') ->addArgument('password', InputArgument::OPTIONAL, 'password') ; } protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $this->filesystem = new Filesystem(); $this->rootlog = $this->container->get('kernel')->getLogDir().'/'; $this->writelnred(''); $this->writelnred('== app:SetPasword'); $this->writelnred('=========================================================================================================='); $username = $input->getArgument('username'); $this->writeln($username); $password = $input->getArgument('password'); $this->writeln($password); $user = $this->em->getRepository('App\Entity\User')->findOneBy(['username' => $username]); if ($user) { // Set Password $user->setPassword($password); $this->em->persist($user); $this->em->flush(); } $this->writeln(''); return Command::SUCCESS; } private function writelnred($string) { $this->output->writeln(''.$string.''); $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n"); } private function writeln($string) { if (!$string) { $string = ' '; } $this->output->writeln($string); $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n"); } }