Пример #1
0
 public function execute() {
     $task = new Gpf_Db_Task();
     $task->setClassName('Gpf_Mail_OutboxRunner');
     $task->loadFromData(array(Gpf_Db_Table_Tasks::CLASSNAME));
     
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add(Gpf_Db_Table_MailOutbox::ID);
     $select->from->add(Gpf_Db_Table_MailOutbox::getName());
     $select->orderBy->add(Gpf_Db_Table_MailOutbox::ID);
     $select->limit->set(0,1);
     try {
     	$row = $select->getOneRow();
     	$begining = $row->get(Gpf_Db_Table_MailOutbox::ID);
     } catch (Gpf_Exception $e) {
     	$begining = 1;
     }
     
     try {
         $task->load();
         $task->setParams($begining);
         $task->setWorkingAreaFrom($begining);   
         $task->setWorkingAreaTo(Gpf_Mail_OutboxRunner::MAX_MAIL_WORKERS_COUNT);
         $task->update(array(Gpf_Db_Table_Tasks::WORKING_AREA_FROM, Gpf_Db_Table_Tasks::WORKING_AREA_TO, Gpf_Db_Table_Tasks::PARAMS));
     } catch (Gpf_Exception $e) {
         throw new Gpf_Exception('Cannot update Gpf_Mail_OutboxRunner task to paralel version');
     }
 }
 protected function buildFrom()
 {
     $this->_selectBuilder->from->add(Gpf_Db_Table_MailOutbox::getName(), 'mo');
     $condition = 'mo.' . Gpf_Db_Table_MailOutbox::MAILACCOUNTID . ' = ' . 'ma.' . Gpf_Db_Table_MailAccounts::ID;
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_MailAccounts::getName(), 'ma', $condition);
     $condition = 'mo.' . Gpf_Db_Table_MailOutbox::MAIL_ID . ' = ' . 'm.' . Gpf_Db_Table_Mails::ID;
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Mails::getName(), 'm', $condition);
 }
Пример #3
0
 /**
  *
  * @param $outboxid
  * @return Gpf_Db_Mail
  */
 private function loadMailFromOutbox($outboxid)
 {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->addAll(Gpf_Db_Table_Mails::getInstance(), 'm');
     $select->from->add(Gpf_Db_Table_MailOutbox::getName(), 'mo');
     $select->from->addInnerJoin(Gpf_Db_Table_Mails::getName(), 'm', 'm.' . Gpf_Db_Table_Mails::ID . ' = mo.' . Gpf_Db_Table_MailOutbox::MAIL_ID);
     $select->where->add("mo." . Gpf_Db_Table_MailOutbox::ID, "=", $outboxid);
     $mail = new Gpf_Db_Mail();
     $mail->fillFromSelect($select);
     return $mail;
 }
 /**
  *
  * @service mail_outbox write
  * @param $ids
  * @return Gpf_Rpc_Action
  */
 public function restartSendingMail(Gpf_Rpc_Params $params)
 {
     $action = new Gpf_Rpc_Action($params);
     $action->setErrorMessage($this->_('Failed to restart %s row(s)'));
     $action->setInfoMessage($this->_('%s row(s) successfully restarted'));
     foreach ($action->getIds() as $id) {
         try {
             $update = new Gpf_SqlBuilder_UpdateBuilder();
             $update->from->add(Gpf_Db_Table_MailOutbox::getName());
             $update->set->add(Gpf_Db_Table_MailOutbox::ERROR_MSG, self::RESTART_ERROR_MSG);
             $update->set->add(Gpf_Db_Table_MailOutbox::RETRY_NR, self::RESTART_RETRY_NR);
             $update->set->add(Gpf_Db_Table_MailOutbox::SCHNEDULET_AT, Gpf_Common_DateUtils::now());
             $update->where->add(Gpf_Db_Table_MailOutbox::ID, '=', $id, 'AND');
             $update->where->add(Gpf_Db_Table_MailOutbox::STATUS, '=', self::STATUS_PENDING);
             $update->executeOne();
             $action->addOk();
         } catch (Exception $e) {
             $action->addError();
         }
     }
     return $action;
 }
Пример #5
0
 private function getStatusCount($status)
 {
     $sql = new Gpf_SqlBuilder_SelectBuilder();
     $sql->select->add('count(*)', 'cnt');
     $sql->from->add(Gpf_Db_Table_MailOutbox::getName());
     $sql->where->add(Gpf_Db_Table_MailOutbox::STATUS, '=', $status);
     $record = $sql->getOneRow();
     return $record->get('cnt');
 }
    private function getUnsentEmails() {
        $select = new Gpf_SqlBuilder_SelectBuilder();
        $select->select->add('COUNT(o.'.Gpf_Db_Table_MailOutbox::ID.')', 'unsentEmails');
        $select->from->add(Gpf_Db_Table_MailOutbox::getName(), 'o');
        $select->from->addLeftJoin(Gpf_Db_Table_MailAccounts::getName(), 'ma', 'ma.'.Gpf_Db_Table_MailAccounts::ID.' = o.'.Gpf_Db_Table_MailOutbox::MAILACCOUNTID);
        $select->where->add('o.'.Gpf_Db_Table_MailOutbox::STATUS, '=', Gpf_Db_Table_MailOutbox::STATUS_PENDING);

        Gpf_Plugins_Engine::extensionPoint('AffiliateNetwork.modifyWhere', 
        new Gpf_Common_SelectBuilderCompoundRecord($select, new Gpf_Data_Record(array('columnPrefix'), array('ma'))));

        $result = $select->getOneRow();
        
        return $result->get('unsentEmails');
    }