I try use doctrine in cron job , i try follow some suggestion from stack and find to use
ContainerAwareCommand
but seem have a problem with kernel , every time don't found him , here is my simple cron namespace Site\Bundle\AdminBundle\Services\Cron;
class EuropatourCron extends \Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
{
protected function configure() {
parent::configure();
$this->setName("updateInfo")
->setDescription("Update db with offert from Europatours.at")
->addArgument('install');
}
protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) {
$toDo = $this->getContainer()->get('doctrine')->getRepository('SiteAdminBundle:Europatoursofertacron')->findBy(array(
'status' => 0
));
$output->writeln(\Doctrine\Common\Util\Debug::dump($toDo));
}
}
and here is my file from test:
// application.php
require_once 'vendor/autoload.php';
require_once 'src/Site/Bundle/AdminBundle/Services/Crons/EuropatourCron.php';
use Site\Bundle\AdminBundle\Services\Cron\EuropatourCron;
use Symfony\Component\Console\Application;
$application = new Application();
$application->add(new EuropatourCron);
$application->run();
i was try found a reson for this error but no found:
PHP Fatal error: Call to undefined method Symfony\Component\Console\Application::getKernel() in /var/www/europatur/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php on line 42
app/console command:name
). If you are just using the components you will need to build the container yourself and inject it into the command. – qooplmao