Example #1
0
 function beginTransaction()
 {
     if ($this->hasTransactions) {
         $result = $this->oDbh->beginTransaction();
         return !PEAR::isError($result);
     }
     return true;
 }
Example #2
0
 /**
  * Start a transaction
  * @return bool
  */
 public static function beginTransaction()
 {
     self::connect();
     if (self::$backend == self::BACKEND_MDB2 && !self::$connection->supports('transactions')) {
         return false;
     }
     self::$connection->beginTransaction();
     self::$inTransaction = true;
     return true;
 }
    /**
     * Commits keywords indexed by this indexer to the database index table
     *
     * If this indexer was created with the <code>$new</code> parameter then
     * the index is cleared for this indexer's document type before new
     * keywords are inserted. Otherwise, the new keywords are simply appended
     * to the existing index.
     */
    public function commit()
    {
        try {
            $this->db->beginTransaction();
            if ($this->new) {
                $this->clear();
                $this->new = false;
            }
            $indexed_ids = $this->db->implodeArray($this->clear_document_ids, 'integer');
            $delete_sql = sprintf('delete from NateGoSearchIndex
				where document_id in (%s) and document_type = %s', $indexed_ids, $this->db->quote($this->document_type, 'integer'));
            $result = $this->db->exec($delete_sql);
            if (MDB2::isError($result)) {
                throw new NateGoSearchDBException($result);
            }
            $keyword = array_pop($this->keywords);
            while ($keyword !== null) {
                $sql = sprintf('insert into NateGoSearchIndex (
						document_id,
						document_type,
						field_id,
						word,
						weight,
						location
					) values (%s, %s, %s, %s, %s, %s)', $this->db->quote($keyword->getDocumentId(), 'integer'), $this->db->quote($keyword->getDocumentType(), 'integer'), $this->db->quote($keyword->getTermId(), 'integer'), $this->db->quote($keyword->getWord(), 'text'), $this->db->quote($keyword->getWeight(), 'integer'), $this->db->quote($keyword->getLocation(), 'integer'));
                $result = $this->db->exec($sql);
                if (MDB2::isError($result)) {
                    throw new NateGoSearchDBException($result);
                }
                unset($keyword);
                $keyword = array_pop($this->keywords);
            }
            $popular_keyword = array_pop($this->popular_keywords);
            while ($popular_keyword !== null) {
                // TODO: there must be a better way to handle dupe words...
                $sql = sprintf('select count(keyword) from NateGoSearchPopularKeywords
					where keyword = %s', $this->db->quote($popular_keyword, 'text'));
                $exists = $this->db->queryOne($sql);
                if (MDB2::isError($result)) {
                    throw new NateGoSearchDBException($result);
                }
                if (!$exists) {
                    $sql = sprintf('insert into NateGoSearchPopularKeywords
						(keyword) values (%s)', $this->db->quote($popular_keyword, 'text'));
                    $result = $this->db->exec($sql);
                    if (MDB2::isError($result)) {
                        throw new NateGoSearchDBException($result);
                    }
                }
                unset($popular_keyword);
                $popular_keyword = array_pop($this->popular_keywords);
            }
            $this->clear_document_ids = array();
            $this->db->commit();
        } catch (NateGoSearchDBException $e) {
            $this->db->rollback();
            throw $e;
        }
    }