Вопрос

I checked all possible answers, but I'm sorry, I couldn't figure this out. I tried making the properties non-static but code pad shows the error on the line:

$task = new sfCacheClearTask($sfContext::getInstance()->getEventDispatcher(), new sfFormatter());

Refer http://codepad.org/zcqrkVoY

Pl help resolve this. Thanks

class doSokiJobTask extends sfBaseTask {

    CONST STATUS_PENDING = 0;
    CONST STATUS_DONE = 1;
    CONST STATUS_IN_PROGRESS = 2;
    CONST STATUS_FAILED = 3;
    CONST STATUS_CANCELLED = 4;

    CONST TIME_TO_DIE = 60;

    public $context = null;
    public $job_name = null;
    public $done = null;
    public $status = null;
    public $start = 0;

    protected function setJobName($name) {
        $this->job_name = strtolower($name);
    }

    protected function configure() {
        $this->addArguments(array(
                //new sfCommandArgument('build', sfCommandArgument::REQUIRED, ''),
        ));

        $this->addOptions(array(
            new sfCommandOption('env', null, sfCommandOption::PARAMETER_OPTIONAL, 'Env to use', 'dev'),
            new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'Env to use', 'frontend'),
            new sfCommandOption('job-type', null, sfCommandOption::PARAMETER_REQUIRED, 'Job to be executed', 'job'),
            new sfCommandOption('daemon', null, sfCommandOption::PARAMETER_REQUIRED, 'Daemon running the job', 0),
        ));

        $this->namespace = 'soki';
        $this->name = 'job';
        $this->briefDescription = 'Lets you run jobs in the background';
        $this->detailedDescription = <<<EOF
The [setup|INFO] task helps run jobs in the background.
Call it with:

  [php symfony setup|INFO]
EOF;
//$this->filesystem = new sfFilesystem(null, $this->formatter);
    }

    protected function execute($arguments = array(), $options = array()) {
        $this->start = $ts_start = microtime(true);
        $options['quiet'] = 'true';
        $configuration = ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env'], true);
        new sfDatabaseManager($configuration);
        $sfContext = sfContext::createInstance($configuration);
        $this->context = $sfContext;
        $this->setJobName($options['job-type']);
        if (true) {
            $file_logger = new sfFileLogger($this->dispatcher, array('file' => $this->configuration->getRootDir() . '/log/jobs.log'));
            $this->dispatcher->connect('command.log', array($file_logger, 'listenToLogEvent'));
        }

        try {
            if (!$this->job_name)
                $this->logSection('INVALID', 'Job Type could not be identified', null, 'ERROR');

            switch ($this->job_name) {
                case 'clear-cache':
                    $task = new sfCacheClearTask($sfContext::getInstance()->getEventDispatcher(), new sfFormatter());
                    $task->run(array(), array('env' => $options['env'], 'app' => $options['application']));
                    $this->done = true;
                    break;
                case 'send-email':
                    $task = new sfProjectSendEmailsTask($sfContext::getInstance()->getEventDispatcher(), new sfFormatter());
                    $task->run(array(), array('env' => $options['env'], 'application' => $options['application'],
                        'message-limit' => sfConfig::get('sf_spool_message_limit', 25)));
                    $this->done = true;
                    break;
                case 'chmod':
                    if (!chmod(sfConfig::get('sf_root_dir') . "/data_society", 0755))
                        throw new Exception('CHMOD failed on ' . sfConfig::get('sf_root_dir') . "/data_society");
                    $this->done = true;
                    break;
                case 'disable-install':
                    $this->done = Application::secureSokiInstaller(true);
                    sokiUtil::clearCacheAsync();
                    break;
                /* case 'enable-install':
                  Application::secureSokiInstaller(false);
                  sokiUtil::clearCacheAsync();
                  break; */
                case 'job':
                    $this->executeJob($arguments, $options);
                    break;
                default:
                    $this->logSection('UNKNOWN', 'Job Type could not be identified', null, 'ERROR');
                    break;
            }
            $ts_end = microtime(true);
            $this->logSection($this->job_name, ($this->done ? 'DONE' : 'FAILED') . ' in ' . round($ts_end - $ts_start) . 's @ ' . $options['env'] . '/' . $options['application'], null, 'INFO');
        } catch (Exception $e) {
            $this->logSection($this->job_name, $e->getMessage(), null, 'ERROR');
            throw $e;
        }
    }
Это было полезно?

Решение

You call static methods via the class, eg ClassName::methodName(), not via an instance $instance::methodName()

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top