示例#1
0
文件: Horde.php 项目: raz0rsdge/horde
 /**
  * Creates a map entry to map between server and client IDs.
  *
  * If an entry already exists, it is overwritten.
  *
  * @param string $databaseURI  URI of database to sync. Like calendar,
  *                             tasks, contacts or notes. May include
  *                             optional parameters:
  *                             tasks?options=ignorecompleted.
  * @param string $cuid         Client ID of the entry.
  * @param string $suid         Server ID of the entry.
  * @param integer $timestamp   Optional timestamp. This can be used to
  *                             'tag' changes made in the backend during the
  *                             sync process. This allows to identify these,
  *                             and ensure that these changes are not
  *                             replicated back to the client (and thus
  *                             duplicated). See key concept "Changes and
  *                             timestamps".
  */
 public function createUidMap($databaseURI, $cuid, $suid, $timestamp = 0)
 {
     $database = $this->normalize($databaseURI);
     $values = array($suid, (int) $timestamp, $this->_syncDeviceID, $database, $this->_user, $cuid);
     // Check if entry exists. If not insert, otherwise update.
     if (!$this->_getSuid($databaseURI, $cuid)) {
         $query = 'INSERT INTO horde_syncml_map ' . '(syncml_suid, syncml_timestamp, syncml_syncpartner, ' . 'syncml_db, syncml_uid, syncml_cuid) ' . 'VALUES (?, ?, ?, ?, ?, ?)';
         $this->_db->insert($query, $values);
     } else {
         $query = 'UPDATE horde_syncml_map ' . 'SET syncml_suid = ?, syncml_timestamp = ? ' . 'WHERE syncml_syncpartner = ? AND syncml_db = ? AND ' . 'syncml_uid = ? AND syncml_cuid = ?';
         $this->_db->update($query, $values);
     }
 }
示例#2
0
文件: Sql.php 项目: jubinpatel/horde
 /**
  * Create a new transaction ID.
  *
  * @param string $creator        A transaction creator.
  * @param string $creator_email  The transaction creator's email address.
  *
  * @return integer  A transaction ID.
  * @throws Whups_Exception
  */
 public function newTransaction($creator, $creator_email = null)
 {
     $insert = 'INSERT INTO whups_transactions ' . '(transaction_timestamp, transaction_user_id) VALUES(?, ?)';
     $this->_db->beginDbTransaction();
     try {
         if ((empty($creator) || $creator < 0) && !empty($creator_email)) {
             // Need to insert dummy value first so we can get the
             // transaction ID.
             $transactionId = $this->_db->insert($insert, array(time(), 'x'));
             $creator = '-' . $transactionId . '_transaction';
             $this->_db->insert('INSERT INTO whups_guests (guest_id, guest_email) ' . 'VALUES (?, ?)', array((string) $creator, $creator_email));
             $this->_db->update('UPDATE whups_transactions SET transaction_user_id = ? ' . 'WHERE transaction_id = ?', array($creator, $transactionId));
         } else {
             $transactionId = $this->_db->insert($insert, array(time(), $creator));
         }
     } catch (Horde_Db_Exception $e) {
         $this->_db->rollbackDbTransaction();
         throw new Whups_Exception($e);
     }
     $this->_db->commitDbTransaction();
     return $transactionId;
 }
示例#3
0
文件: Sql.php 项目: horde/horde
 /**
  * Save a story to storage.
  *
  * @param array &$info  The story info array.
  * @throws Jonah_Exception
  */
 protected function _saveStory(&$info)
 {
     $values = array((int) $info['channel_id'], Horde_String::convertCharset($info['author'], 'UTF-8', $this->_params['charset']), Horde_String::convertCharset($info['title'], 'UTF-8', $this->_params['charset']), Horde_String::convertCharset($info['description'], 'UTF-8', $this->_params['charset']), $info['body_type'], isset($info['body']) ? Horde_String::convertCharset($info['body'], 'UTF-8', $this->_params['charset']) : null, isset($info['url']) ? $info['url'] : null, isset($info['published']) ? (int) $info['published'] : null, time(), (int) $info['read']);
     if (empty($info['id'])) {
         $channel = $this->getChannel($info['channel_id']);
         $sql = 'INSERT INTO jonah_stories (channel_id, ' . 'story_author, story_title, story_desc, story_body_type, ' . 'story_body, story_url, story_published, story_updated, ' . 'story_read) ' . 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
         Horde::log('SQL Query by Jonah_Driver_sql::_saveStory(): ' . $sql, 'DEBUG');
         try {
             $id = $this->_db->insert($sql, $values);
             $info['id'] = (int) $id;
         } catch (Horde_Db_Exception $e) {
             Horde::log($e->getMessage(), 'ERR');
             throw new Jonah_Exception($e);
         }
         $this->_addPermalink($info);
     } else {
         $values[] = $info['id'];
         $sql = 'UPDATE jonah_stories SET channel_id = ?, ' . 'story_author = ?, story_title = ?, story_desc = ?, ' . 'story_body_type = ?, story_body = ?, story_url = ?, ' . 'story_published = ?, story_updated = ?, story_read = ? ' . 'WHERE story_id = ?';
         Horde::log('SQL Query by Jonah_Driver_sql::_saveStory(): ' . $sql, 'DEBUG');
         try {
             $this->_db->update($sql, $values);
         } catch (Horde_Db_Exception $e) {
             Horde::log($e->getMessage(), 'ERR');
             throw new Jonah_Exception($e);
         }
     }
     if (empty($info['read'])) {
         $info['read'] = 0;
     }
     /* Deal with any tags */
     if (!empty($info['tags'])) {
         $tags = explode(',', $info['tags']);
     } else {
         $tags = array();
     }
     $GLOBALS['injector']->getInstance('Jonah_Tagger')->tag($info['id'], $tags, $GLOBALS['registry']->getAuth(), Jonah_Tagger::TYPE_STORY);
     $this->_timestampChannel($info['id'], time());
     return true;
 }