/** * Write out the tags for a specific resource. * * @param int $resource_id The story we are tagging. * @param int $channel_id The channel id for the story we are tagging * @param array $tags An array of tags. * * @TODO: Move this to a tagger class that uses Content_Tagger * @return boolean * @throws Jonah_Exception */ public function writeTags($resource_id, $channel_id, $tags) { global $conf; // First, make sure all tag names exist in the DB. $tagkeys = array(); $insert = $this->_db->prepare('INSERT INTO jonah_tags (tag_id, tag_name) VALUES(?, ?)'); $query = $this->_db->prepare('SELECT tag_id FROM jonah_tags WHERE tag_name = ?'); foreach ($tags as $tag) { $tag = Horde_String::lower(trim($tag)); $results = $this->_db->execute($query, $this->_db->escapeSimple($tag)); if ($results instanceof PEAR_Error) { throw new Jonah_Exception($results); } elseif ($results->numRows() == 0) { $id = $this->_db->nextId('jonah_tags'); $result = $this->_db->execute($insert, array($id, $tag)); $tagkeys[] = $id; } else { $row = $results->fetchRow(DB_FETCHMODE_ASSOC); $tagkeys[] = $row['tag_id']; } } // Free our resources. $this->_db->freePrepared($insert, true); $this->_db->freePrepared($query, true); $sql = 'DELETE FROM jonah_stories_tags WHERE story_id = ' . (int) $resource_id; $query = $this->_db->prepare('INSERT INTO jonah_stories_tags (story_id, channel_id, tag_id) VALUES(?, ?, ?)'); Horde::log('SQL query by Jonah_Driver_sql::writeTags: ' . $sql, 'DEBUG'); $this->_db->query($sql); foreach ($tagkeys as $key) { $this->_db->execute($query, array($resource_id, $channel_id, $key)); } $this->_db->freePrepared($query, true); /* @TODO We should clear at least any of our cached counts */ return true; }
public function savePaste($bin, $paste, $syntax = 'none', $title = '') { $this->_connect(); $id = $this->_db->nextId('mySequence'); if (PEAR::isError($id)) { throw new Horde_Exception_Wrapped($id); } $uuid = new Horde_Support_Uuid(); $bin = 'default'; // FIXME: Allow bins to be Horde_Shares $query = 'INSERT INTO pastie_pastes (paste_id, paste_uuid, ' . 'paste_bin, paste_title, paste_syntax, paste_content, ' . 'paste_owner, paste_timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?)'; $values = array($id, $uuid, $bin, $title, $syntax, $paste, $GLOBALS['registry']->getAuth(), time()); Horde::log(sprintf('Pastie_Driver_Sql#savePaste(): %s', $query), 'DEBUG'); Horde::log(print_r($values, true), 'DEBUG'); $result = $this->_write_db->query($query, $values); if ($result instanceof PEAR_Error) { Horde::log($result, 'ERR'); throw new Horde_Exception_Wrapped($result); } return $uuid; }
/** * Store a files information within the database. * * @param string $path The path to store the file in. * @param string $name The filename to use. * * @throws Horde_Vfs_Exception */ protected function _writeSQLData($path, $name) { $this->_connect(); // File already exists in database if ($this->exists($path, $name)) { $query = 'UPDATE ' . $this->_params['table'] . ' SET vfs_modified = ?' . ' WHERE vfs_path = ? AND vfs_name = ?'; $values = array(time(), $path, $name); } else { $id = $this->_db->nextId($this->_params['table']); $query = 'INSERT INTO ' . $this->_params['table'] . ' (vfs_id, vfs_type, vfs_path, vfs_name, vfs_modified,' . ' vfs_owner) VALUES (?, ?, ?, ?, ?, ?)'; $values = array($id, self::FILE, $path, $name, time(), $this->_params['user']); } return $this->_db->query($query, $values); }
/** * Saves virtual email address to the backend. * * @param array $info The virtual email data. * @param string $domain The name of the domain for this virtual email. * * @throws Vilma_Exception */ public function saveVirtual($info, $domain) { /* Access check (for domainkey) */ $this->getDomainByName($domain); if (empty($info['virtual_id'])) { $info['virtual_id'] = $this->_db->nextId($this->_params['tables']['virtuals']); $sql = 'INSERT INTO ' . $this->_params['tables']['virtuals'] . ' (' . $this->_getTableField('virtuals', 'virtual_email') . ', ' . $this->_getTableField('virtuals', 'virtual_destination') . ', ' . $this->_getTableField('virtuals', 'virtual_id') . ') VALUES (?, ?, ?)'; } else { $sql = 'UPDATE ' . $this->_params['tables']['virtuals'] . ' SET ' . $this->_getTableField('virtuals', 'virtual_email') . ' = ?, ' . $this->_getTableField('virtuals', 'virtual_destination') . ' = ?' . ' WHERE ' . $this->_getTableField('virtuals', 'virtual_id') . ' = ?'; } $values = array($info['stripped_email'] . '@' . $domain, $info['virtual_destination'], $info['virtual_id']); Horde::log($sql, 'DEBUG'); return $this->_db->query($sql, $values); }
/** * Saves an individual send to the backend. This will be one instance of * a message being sent to a recipient. * * @param int $message_id The message id. * @param string $remote_id The text of the message. * @param string $recipient Any send params used for this * @param string $error Any send params used for this * * @return mixed The send id on success or PEAR Error on failure. */ function saveSend($message_id, $remote_id, $recipient, $error) { $send_id = $this->_db->nextId('swoosh_sends'); if (is_a($send_id, 'PEAR_Error')) { Horde::log($send_id, 'ERR'); return $send_id; } $sql = 'INSERT INTO swoosh_sends (send_id, message_id, send_remote_id, send_recipient, send_status) VALUES (?, ?, ?, ?, ?)'; $values = array($send_id, $message_id, is_null($remote_id) ? 'NULL' : $remote_id, $recipient, is_null($error) ? 'NULL' : $error); $result = $this->_db->query($sql, $values); if (is_a($result, 'PEAR_Error')) { Horde::log($result, 'ERR'); return $result; } return $send_id; }
/** * Returns an unique ID for a description of a symbol type. * * @param integer $lang The language's unique ID. * @param string $string The symbol type description. * * return mixed A unique ID for this description or PEAR_Error on error. */ function getDecId($lang, $string) { $this->_connect(); if (!isset($this->_decIdcache[$lang])) { $this->_decIdcache[$lang] = array(); } if (!isset($this->_decIdcache[$lang][$string])) { $query = 'SELECT declid FROM luxor_declarations' . ' WHERE langid = ? AND declaration = ?'; $values = array($lang, $string); $decId = $this->_db->getOne($query, $values); if (is_null($decId) || is_a($decId, 'PEAR_Error')) { /* Create an ID for this declaration. */ $decId = $this->_db->nextId('luxor_declarations'); if (is_a($decId, 'PEAR_Error')) { return $decId; } $this->_db->query('INSERT INTO luxor_declarations (declid, langid, declaration)' . ' VALUES (?, ?, ?)', array((int) $decId, $lang, $string)); } $this->_decIdcache[$lang][$string] = $decId; } return $this->_decIdcache[$lang][$string]; }