コード例 #1
0
ファイル: Sql.php プロジェクト: jubinpatel/horde
 /**
  * Stores the specified data in the storage backend.
  *
  * @access private
  *
  * @param Ingo_Storage_Rule|Ingo_Storage_Filters $ob  The object to store.
  */
 protected function _store($ob)
 {
     switch ($ob->obType()) {
         case self::ACTION_BLACKLIST:
         case self::ACTION_WHITELIST:
             $is_blacklist = (int) ($ob->obType() == self::ACTION_BLACKLIST);
             if ($is_blacklist) {
                 $filters = $this->retrieve(self::ACTION_FILTERS);
                 $id = $filters->findRuleId(self::ACTION_BLACKLIST);
                 if ($id !== null) {
                     $rule = $filters->getRule($id);
                     if (!isset($rule['action-value']) || $rule['action-value'] != $ob->getBlacklistFolder()) {
                         $rule['action-value'] = $ob->getBlacklistFolder();
                         $filters->updateRule($rule, $id);
                     }
                 }
             }
             $query = sprintf('DELETE FROM %s WHERE list_owner = ? AND list_blacklist = ?', $this->_params['table_lists']);
             $values = array(Ingo::getUser(), $is_blacklist);
             try {
                 $this->_params['db']->delete($query, $values);
             } catch (Horde_Db_Exception $e) {
                 Horde::log($e, 'ERR');
                 throw new Ingo_Exception($e);
             }
             $query = sprintf('INSERT INTO %s (list_owner, list_blacklist, list_address) VALUES (?, ?, ?)', $this->_params['table_lists']);
             $addresses = $is_blacklist ? $ob->getBlacklist() : $ob->getWhitelist();
             foreach ($addresses as $address) {
                 try {
                     $result = $this->_params['db']->insert($query, array(Ingo::getUser(), $is_blacklist, $address));
                 } catch (Horde_Db_Exception $e) {
                     Horde::log($result, 'ERR');
                     throw new Ingo_Exception($e);
                 }
             }
             $ob->setSaved(true);
             break;
         case self::ACTION_FORWARD:
             $values = array(implode("\n", $ob->getForwardAddresses()), (int) (bool) $ob->getForwardKeep(), Ingo::getUser());
             try {
                 if ($ob->isSaved()) {
                     $query = sprintf('UPDATE %s SET forward_addresses = ?, forward_keep = ? WHERE forward_owner = ?', $this->_params['table_forwards']);
                     $this->_params['db']->update($query, $values);
                 } else {
                     $query = sprintf('INSERT INTO %s (forward_addresses, forward_keep, forward_owner) VALUES (?, ?, ?)', $this->_params['table_forwards']);
                     $this->_params['db']->insert($query, $values);
                 }
             } catch (Horde_Db_Exception $e) {
                 throw new Ingo_Exception($e);
             }
             $ob->setSaved(true);
             break;
         case self::ACTION_VACATION:
             $values = array(implode("\n", $ob->getVacationAddresses()), Horde_String::convertCharset($ob->getVacationSubject(), 'UTF-8', $this->_params['charset']), Horde_String::convertCharset($ob->getVacationReason(), 'UTF-8', $this->_params['charset']), (int) $ob->getVacationDays(), (int) $ob->getVacationStart(), (int) $ob->getVacationEnd(), implode("\n", $ob->getVacationExcludes()), (int) (bool) $ob->getVacationIgnorelist(), Ingo::getUser());
             try {
                 if ($ob->isSaved()) {
                     $query = sprintf('UPDATE %s SET vacation_addresses = ?, vacation_subject = ?, vacation_reason = ?, vacation_days = ?, vacation_start = ?, vacation_end = ?, vacation_excludes = ?, vacation_ignorelists = ? WHERE vacation_owner = ?', $this->_params['table_vacations']);
                     $this->_params['db']->update($query, $values);
                 } else {
                     $query = sprintf('INSERT INTO %s (vacation_addresses, vacation_subject, vacation_reason, vacation_days, vacation_start, vacation_end, vacation_excludes, vacation_ignorelists, vacation_owner) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->_params['table_vacations']);
                     $this->_params['db']->insert($query, $values);
                 }
             } catch (Horde_Db_Exception $e) {
                 throw new Ingo_Exception($e);
             }
             $ob->setSaved(true);
             break;
         case self::ACTION_SPAM:
             $values = array((int) $ob->getSpamLevel(), $ob->getSpamFolder(), Ingo::getUser());
             try {
                 if ($ob->isSaved()) {
                     $query = sprintf('UPDATE %s SET spam_level = ?, spam_folder = ? WHERE spam_owner = ?', $this->_params['table_spam']);
                     $this->_params['db']->update($query, $values);
                 } else {
                     $query = sprintf('INSERT INTO %s (spam_level, spam_folder, spam_owner) VALUES (?, ?, ?)', $this->_params['table_spam']);
                     $this->_params['db']->insert($query, $values);
                 }
             } catch (Horde_Db_Exception $e) {
                 throw new Ingo_Exception($e);
             }
             $ob->setSaved(true);
             break;
     }
 }
コード例 #2
0
ファイル: Prefs.php プロジェクト: jubinpatel/horde
 /**
  * Stores the specified data in the storage backend.
  *
  * @param Ingo_Storage_Rule|Ingo_Storage_Filters $ob  The object to store.
  */
 protected function _store($ob)
 {
     $prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('ingo', array('cache' => false, 'user' => Ingo::getUser()));
     switch ($ob->obType()) {
         case self::ACTION_BLACKLIST:
             $data = array('a' => $ob->getBlacklist(), 'f' => $ob->getBlacklistFolder());
             $prefs->setValue('blacklist', serialize($data));
             break;
         case self::ACTION_FILTERS:
             $prefs->setValue('rules', serialize($ob->getFilterList()));
             break;
         case self::ACTION_FORWARD:
             $data = array('a' => $ob->getForwardAddresses(), 'k' => $ob->getForwardKeep());
             $prefs->setValue('forward', serialize($data));
             break;
         case self::ACTION_VACATION:
             $data = array('addresses' => $ob->getVacationAddresses(), 'days' => $ob->getVacationDays(), 'excludes' => $ob->getVacationExcludes(), 'ignorelist' => $ob->getVacationIgnorelist(), 'reason' => $ob->getVacationReason(), 'subject' => $ob->getVacationSubject(), 'start' => $ob->getVacationStart(), 'end' => $ob->getVacationEnd());
             $prefs->setValue('vacation', serialize($data));
             break;
         case self::ACTION_WHITELIST:
             $prefs->setValue('whitelist', serialize($ob->getWhitelist()));
             break;
         case self::ACTION_SPAM:
             $data = array('folder' => $ob->getSpamFolder(), 'level' => $ob->getSpamLevel());
             $prefs->setValue('spam', serialize($data));
             break;
     }
 }