开发者

Symfony task on the hosting

I have task:

<?php
require_once(dirname(__FILE__).'/../../config/ProjectConfiguration.class.php');

class GroupCheckTask extends sfBaseTask
{
  protected function configure()
  {
    // // add your own arguments here
    // $this->addArguments(array(
    //   new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'),
    // ));

      $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUI开发者_StackOverflow中文版RED, 'The connection name', 'doctrine'),
      // add your own options here
    ));

    $this->namespace        = '';
    $this->name             = 'GroupCheck';
    $this->briefDescription = '';
    $this->detailedDescription = <<<EOF
The [GroupCheck|INFO] task does things.
Call it with:

  [php symfony GroupCheck|INFO]
EOF;
  }

  protected function execute($arguments = array(), $options = array())
  {

    $databaseManager = new sfDatabaseManager($this->configuration);
    $connection = $databaseManager->getDatabase($options['connection'])->getConnection();

    // add your code here



    $users=  Doctrine::getTable('sfGuardUserProfile')->getUserDelay() ;


       foreach($users as $sfGuardUserProfile)
       {
          $users_id =$sfGuardUserProfile-> getUserId();

          $userForChange =  Doctrine::getTable('sfGuardUserGroup')->getUserForChange($users_id) ;

          foreach($userForChange as $sfGuardUserGroup)
       {

            $sfGuardUserGroup->setSfGuardGroup(Doctrine::getTable('sfGuardGroup')-        >findOneByName('basic'))->save();

       }

       }
  }
}

And in my localhost all works fine, but it is not work in hosting. What is the correct way to run task on hosting from cron tab?


first, you dont need put the line require_once(dirname(__FILE__).'/../../config/ProjectConfiguration.class.php');

second, write a namespace for your task is a good practice

third, you need the the a php file like:

<?php
  /* /path/to/file.php */
  chdir("/the/path/in/your/host/to/symfony/project");
  exec("symfony your_namespace:GroupCheck");
?>

last, you can put this file in your crontab

00 59 23 * * php /path/to/file.php
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜