Newscoop\Tools\Console\Command\SchedulerManagerCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
    {
        $systemPreferences = $this->getContainer()->getService('system_preferences_service');
        $schedulerService = $this->getContainer()->getService('newscoop.scheduler');
        $cacheService = $this->getContainer()->getService('newscoop.cache');
        $em = $this->getContainer()->getService('em');
        $jobsCount = $em->getRepository('Newscoop\\Entity\\CronJob')->createQueryBuilder('j')->select('count(j)')->where('j.enabled = true')->getQuery()->getSingleScalarResult();
        $jobs = array();
        $cacheKey = $cacheService->getCacheKey(array('jobs_count', $jobsCount), 'cronjobs');
        if ($cacheService->contains($cacheKey)) {
            $jobs = $cacheService->fetch($cacheKey);
        } else {
            $jobs = $em->getRepository('Newscoop\\Entity\\CronJob')->createQueryBuilder('j')->where('j.enabled = true')->getQuery()->getArrayResult();
            $cacheService->save($cacheKey, $jobs);
        }
        if (!$systemPreferences->CronJobsNotificationEmail) {
            $systemPreferences->CronJobsNotificationEmail = $systemPreferences->EmailFromAddress;
        }
        try {
            foreach ($jobs as $job) {
                unset($job['id']);
                unset($job['createdAt']);
                unset($job['detailsUrl']);
                if ($job['sendMail']) {
                    $job['recipients'] = $systemPreferences->CronJobsNotificationEmail;
                    if ($systemPreferences->CronJobsSenderEmail) {
                        $job['smtpSender'] = $systemPreferences->CronJobsSenderEmail;
                    }
                    if ($systemPreferences->CronJobsSenderName) {
                        $job['smtpSenderName'] = $systemPreferences->CronJobsSenderName;
                    }
                    if (is_null($job['output'])) {
                        $job['output'] = realpath(__DIR__ . '/../../../../../log') . '/cron_job_' . $this->cleanString($job['name']) . '.log';
                    }
                }
                unset($job['sendMail']);
                $schedulerService->addSchedulerJob($job['name'], array_filter($job));
            }
            $schedulerService->run();
        } catch (\Exception $e) {
            $output->writeln("<error>" . $e->getMessage() . "</error>");
        }
    }
SchedulerManagerCommand