public function executeAction($preview = false)
    {
        $jobId = intval($this->getParam(\MUtil_Model::REQUEST_ID));

        $batch = $this->loader->getTaskRunnerBatch('commjob-execute-' . $jobId);
        $batch->setMessageLogFile($this->project->getCronLogfile());
        $batch->minimalStepDurationMs = 3000; // 3 seconds max before sending feedback

        if (!$batch->isLoaded() && !is_null(($jobId))) {
            $batch->addMessage(sprintf(
                    $this->_('Starting single %s mail job %s'),
                    $this->project->getName(),
                    $jobId
                    ));

            // Check for unprocessed tokens
            $tracker = $this->loader->getTracker();
            $tracker->loadCompletedTokensBatch($batch, null, $this->currentUser->getUserId());

            // We could skip this, but a check before starting the batch is better
            $sql = $this->db->select()->from('gems__comm_jobs', array('gcj_id_job'))
                    ->where('gcj_active > 0')
                    ->where('gcj_id_job = ?', $jobId);

            $job = $this->db->fetchOne($sql);

            if (!empty($job)) {
                $batch->addTask('Mail\\ExecuteMailJobTask', $job, null, null, $preview);
            } else {
                $batch->reset();
                $this->addMessage($this->_("Mailjob is inactive and won't be executed"), 'danger');
            }
            
            if ($preview === true) {
                $batch->autoStart = true;
            }
        }

        if ($batch->isFinished()) {
            // Add the messages to the view and forward
            $messages = $batch->getMessages(true);
            if (count($messages)) {
                $this->addMessage($messages, 'info');
            }

            $this->_reroute(array('action'=>'show'));
        }
        
        if ($preview === true) {
            $title = sprintf($this->_('Preview single mail job %s'), $jobId);
        } else {
            $title = sprintf($this->_('Executing single mail job %s'), $jobId);
        }

        $this->_helper->BatchRunner($batch, $title, $this->accesslog);
    }
public function executeAction($preview = false)
    {
        $jobId = intval($this->getParam(\MUtil_Model::REQUEST_ID));

        $batch = $this->loader->getTaskRunnerBatch('commjob-execute-' . $jobId);
        $batch->setMessageLogFile($this->project->getCronLogfile());
        $batch->minimalStepDurationMs = 3000; // 3 seconds max before sending feedback

        if (!$batch->isLoaded() && !is_null(($jobId))) {
            $batch->addMessage(sprintf(
                    $this->_('Starting single %s mail job %s'),
                    $this->project->getName(),
                    $jobId
                    ));

            // Check for unprocessed tokens
            $tracker = $this->loader->getTracker();
            $tracker->loadCompletedTokensBatch($batch, null, $this->currentUser->getUserId());

            // We could skip this, but a check before starting the batch is better
            $sql = $this->db->select()->from('gems__comm_jobs', array('gcj_id_job'))
                    ->where('gcj_active > 0')
                    ->where('gcj_id_job = ?', $jobId);

            $job = $this->db->fetchOne($sql);

            if (!empty($job)) {
                $batch->addTask('Mail\\ExecuteMailJobTask', $job, null, null, $preview);
            } else {
                $batch->reset();
                $this->addMessage($this->_("Mailjob is inactive and won't be executed"), 'danger');
            }
            
            if ($preview === true) {
                $batch->autoStart = true;
            }
        }

        if ($batch->isFinished()) {
            // Add the messages to the view and forward
            $messages = $batch->getMessages(true);
            if (count($messages)) {
                $this->addMessage($messages, 'info');
            }

            $this->_reroute(array('action'=>'show'));
        }
        
        if ($preview === true) {
            $title = sprintf($this->_('Preview single mail job %s'), $jobId);
        } else {
            $title = sprintf($this->_('Executing single mail job %s'), $jobId);
        }

        $this->_helper->BatchRunner($batch, $title, $this->accesslog);
    }
public function executeAction ( $ preview = false ) { $ jobId = intval ( $ this -> getParam ( \ MUtil_Model :: REQUEST_ID ) ) ; $ batch = $ this -> loader -> getTaskRunnerBatch ( 'commjob-execute-' . $ jobId ) ; $ batch -> setMessageLogFile ( $ this -> project -> getCronLogfile ( ) ) ; $ batch -> minimalStepDurationMs = 3000 ; // 3 seconds max before sending feedback if ( ! $ batch -> isLoaded ( ) && ! is_null ( ( $ jobId ) ) ) { $ batch -> addMessage ( sprintf ( $ this -> _ ( 'Starting single %s mail job %s' ) , $ this -> project -> getName ( ) , $ jobId ) ) ; // Check for unprocessed tokens $ tracker = $ this -> loader -> getTracker ( ) ; $ tracker -> loadCompletedTokensBatch ( $ batch , null , $ this -> currentUser -> getUserId ( ) ) ; // We could skip this, but a check before starting the batch is better $ sql = $ this -> db -> select ( ) -> from ( 'gems__comm_jobs' , array ( 'gcj_id_job' ) ) -> where ( 'gcj_active > 0' ) -> where ( 'gcj_id_job = ?' , $ jobId ) ; $ job = $ this -> db -> fetchOne ( $ sql ) ; if ( ! empty ( $ job ) ) { $ batch -> addTask ( 'Mail\\ExecuteMailJobTask' , $ job , null , null , $ preview ) ; } else { $ batch -> reset ( ) ; $ this -> addMessage ( $ this -> _ ( "Mailjob is inactive and won't be executed" ) , 'danger' ) ; } if ( $ preview === true ) { $ batch -> autoStart = true ; } } if ( $ batch -> isFinished ( ) ) { // Add the messages to the view and forward $ messages = $ batch -> getMessages ( true ) ; if ( count ( $ messages ) ) { $ this -> addMessage ( $ messages , 'info' ) ; } $ this -> _reroute ( array ( 'action' => 'show' ) ) ; } if ( $ preview === true ) { $ title = sprintf ( $ this -> _ ( 'Preview single mail job %s' ) , $ jobId ) ; } else { $ title = sprintf ( $ this -> _ ( 'Executing single mail job %s' ) , $ jobId ) ; } $ this -> _helper -> BatchRunner ( $ batch , $ title , $ this -> accesslog ) ; }
Execute a single mail job
Execute a single mail job