128 lines
4.3 KiB
PHP
128 lines
4.3 KiB
PHP
<?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;
|
|
use Cadoles\PortalBundle\Entity\Project;
|
|
|
|
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 / setusersniveau')
|
|
->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;
|
|
case "setusersniveau": $this->setusersniveau(); break;
|
|
case "setfgcancreateproject": $this->setfgcancreateproject(); break;
|
|
case "createproject": $this->createproject(); 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 setusersniveau() {
|
|
$users = $this->em->getRepository('CadolesCoreBundle:User')->findAll();
|
|
foreach($users as $user) {
|
|
$this->writeln($user->getUsername());
|
|
|
|
$user->setLabelniveau01($user->getNiveau01()->getLabel());
|
|
$user->setLabelniveau02(($user->getNiveau02()?$user->getNiveau02()->getLabel():null));
|
|
|
|
$this->em->persist($user);
|
|
$this->em->flush();
|
|
}
|
|
}
|
|
|
|
private function setfgcancreateproject() {
|
|
$group=$this->em->getRepository('CadolesCoreBundle:Group')->findOneBy(array('fgall'=>true));
|
|
if ($group) {
|
|
$group->setFgcancreateproject(true);
|
|
$this->em->persist($group);
|
|
$this->em->flush();
|
|
}
|
|
}
|
|
|
|
private function createproject() {
|
|
$groups=$this->em->getRepository('CadolesCoreBundle:Group')->findBy(array('fgcanshare'=>true));
|
|
foreach($groups as $group) {
|
|
// On regarde s'il a au moins un project
|
|
if($group->getProjects()->isEmpty()) {
|
|
$project=new Project();
|
|
|
|
$project->setName($group->getLabel());
|
|
$project->addGroup($group);
|
|
$project->setUser($group->getOwner());
|
|
|
|
$this->em->persist($project);
|
|
$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");
|
|
}
|
|
|
|
|
|
|
|
}
|