1
votes

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

1
Is this full stack or just using the console component? - qooplmao
i use php application.php updateInfo for run cron but give error - Laurentiu
So you are not using the full Symfony Framework? If you are using the full stack Symfony Framework then you can just create a command and put it in a bundle inside a Command folder and Symfony will find it and insert the container (it will then be available through 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
please can you give a tutorial how to do that ? - Laurentiu
Which? There are 2 options. - qooplmao

1 Answers

5
votes

You don't need to create a file to run your command, you can ignore your application.php and simply run from the command line (within your project path)

php app/console updateInfo