/**
  * persist rules data in db
  * 
  * @throws Exception
  */
 protected function _saveRules()
 {
     if (empty($this->_rules)) {
         $this->_rulesBackend->deleteByProperty($this->_accountId, 'account_id');
         return;
     }
     try {
         $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
         $this->_rulesBackend->deleteByProperty($this->_accountId, 'account_id');
         foreach ($this->_rules as $rule) {
             $ruleRecord = new Felamimail_Model_Sieve_Rule();
             $ruleRecord->setFromFSR($rule);
             $ruleRecord->account_id = $this->_accountId;
             $ruleRecord->conditions = Zend_Json::encode($ruleRecord->conditions);
             $this->_rulesBackend->create($ruleRecord);
         }
         Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw $e;
     }
 }
Esempio n. 2
0
 /**
  * get rules for account
  * 
  * @param string $_accountId
  * @return Tinebase_Record_RecordSet of Felamimail_Model_Sieve_Rule
  */
 public function getRules($_accountId)
 {
     $result = new Tinebase_Record_RecordSet('Felamimail_Model_Sieve_Rule');
     $script = $this->_getSieveScript($_accountId);
     if ($script !== NULL) {
         foreach ($script->getRules() as $fsr) {
             $rule = new Felamimail_Model_Sieve_Rule();
             $rule->setFromFSR($fsr);
             $result->addRecord($rule);
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($result->toArray(), TRUE));
         }
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Sieve script empty or could not parse it.');
         }
     }
     return $result;
 }