container = $container; $this->em = $em; } protected function configure() { $this ->setName('app:Script') ->setDescription('Script to call') ->setHelp('Script to call') ; } protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $this->filesystem = new Filesystem(); $this->rootlog = $this->container->get('kernel')->getLogDir()."/"; $output->writeln('APP = Scripts'); $this->callscript("addapikey"); $output->writeln(''); return 1; } private function callscript($name) { $script=$this->em->getRepository("App:Script")->findOneBy(["name"=>$name]); if(!$script) { //$this->writelnred("== SCRIPT = ".$name); $this->$name(); $script=new Script(); $script->setName($name); $this->em->persist($script); $this->em->flush(); $this->writeln(""); } } private function addapikey() { $users=$this->em->getRepository("App:User")->findBy(["apikey"=>null]); foreach($users as $user) { $key = Uuid::uuid4(); $user->setApikey($key); $this->em->persist($user); $this->em->flush(); } } private function writelnred($string) { $this->output->writeln(''.$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"); } }