ajout script forcer flag visible à true (ref #100)

This commit is contained in:
afornerot 2020-02-24 09:41:53 +01:00
parent 7440f462ec
commit 124f6fb738
4 changed files with 85 additions and 1 deletions

View File

@ -0,0 +1,84 @@
<?php
namespace Cadoles\CoreBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\KernelInterface;
use Doctrine\DBAL\Connection as DBALConnection;
use Doctrine\ORM\EntityManager;
use Cadoles\CoreBundle\Entity\User;
global $bdd01;
global $config;
class ScriptCommand extends Command
{
private $container;
private $em;
private $output;
private $filesystem;
private $rootlog;
protected function configure()
{
$this
->setName('Core:Script')
->setDescription('Lauch Script')
->setHelp('Execeute some script : visibletrue / ')
->addArgument('scriptname', InputArgument::OPTIONAL, 'scriptname')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->container = $this->getApplication()->getKernel()->getContainer();
$this->em = $this->container->get('doctrine')->getEntityManager();
$this->output = $output;
$this->filesystem = new Filesystem();
$this->rootlog = $this->container->get('kernel')->getRootDir()."/../var/logs/";
$this->writelnred('');
$this->writelnred('== Core:Script');
$this->writelnred('==========================================================================================================');
$scriptname = $input->getArgument('scriptname');
$this->writeln($scriptname);
switch($scriptname) {
case "visibletrue": $this->visibletrue(); break;
}
$this->writeln('');
return 1;
}
private function visibletrue() {
$users = $this->em->getRepository('CadolesCoreBundle:User')->findAll();
foreach($users as $user) {
if(!$user->getVisible()) {
$this->writeln($user->getUsername());
$user->setVisible(true);
$this->em->persist($user);
$this->em->flush();
}
}
}
private function writelnred($string) {
$this->output->writeln('<fg=red>'.$string.'</>');
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
private function writeln($string) {
$this->output->writeln($string);
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
}

View File

@ -8,7 +8,7 @@ INSERT IGNORE INTO `niveau01` (`id`, `label`, `siren`) VALUES
(-100, 'DRAAF', '130007107');
INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES
(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}BkFFVAICIt3FUlHQLN1FsNWUtsPnLFRs
(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}S0E51VgU0ZRXsD5jEdnUDeBkwBRO+29r
', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple');

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB