public static function getConnection() { if (!isset(self::$connection)) { self::$connection = Propel::getConnection(); // self::$connection->beginTransaction(); } return self::$connection; }
public static function getUnique($connection = null) { if (!isset($connection)) { $connection = QubitTransactionFilter::getConnection(QubitObject::DATABASE_NAME); } // Try a max of 10 times before giving up (avoid infinite loops when // possible slugs exhausted) for ($i = 0; $i < 10; $i++) { $slug = self::random(); $statement = $connection->prepare(' SELECT COUNT(*) FROM ' . QubitSlug::TABLE_NAME . ' WHERE ' . QubitSlug::SLUG . ' = ?;'); $statement->execute(array($slug)); if (0 == $statement->fetchColumn(0)) { return $slug; } } }
protected function update($connection = null) { if (!isset($connection)) { $connection = QubitTransactionFilter::getConnection(QubitStaticPage::DATABASE_NAME); } $statement = $connection->prepare(' UPDATE ' . QubitSlug::TABLE_NAME . ' SET ' . QubitSlug::SLUG . ' = ? WHERE ' . QubitSlug::OBJECT_ID . ' = ?'); if (1 > strlen($this->slug)) { $statement->execute(array(QubitSlug::random(), $this->id)); return; } try { $statement->execute(array($this->slug, $this->id)); } catch (PDOException $e) { $statement->execute(array(QubitSlug::random(), $this->id)); } return parent::update($connection); }
protected function update($connection = null) { if (!isset($connection)) { $connection = QubitTransactionFilter::getConnection(QubitOaiHarvest::DATABASE_NAME); } $offset = 0; foreach ($this->tables as $table) { $criteria = new Criteria(); $selectCriteria = new Criteria(); foreach ($table->getColumns() as $column) { if (!array_key_exists($column->getPhpName(), $this->values)) { if ('updatedAt' == $column->getPhpName()) { $this->values['updatedAt'] = new DateTime(); } } if (array_key_exists($column->getPhpName(), $this->values)) { if ('serialNumber' == $column->getPhpName()) { $selectCriteria->add($column->getFullyQualifiedName(), $this->values[$column->getPhpName()]++); } $criteria->add($column->getFullyQualifiedName(), $this->param($column)); } if ($column->isPrimaryKey()) { $selectCriteria->add($column->getFullyQualifiedName(), $this->keys[$column->getPhpName()]); } $offset++; } if (0 < $criteria->size()) { BasePeer::doUpdate($selectCriteria, $criteria, $connection); } } return $this; }
protected function deleteFromNestedSet($connection = null) { if (!isset($connection)) { $connection = QubitTransactionFilter::getConnection(QubitPhysicalObject::DATABASE_NAME); } $delta = $this->rgt - $this->lft + 1; $statement = $connection->prepare(' UPDATE ' . QubitPhysicalObject::TABLE_NAME . ' SET ' . QubitPhysicalObject::LFT . ' = ' . QubitPhysicalObject::LFT . ' - ? WHERE ' . QubitPhysicalObject::LFT . ' >= ?'); $statement->execute(array($delta, $this->rgt)); $statement = $connection->prepare(' UPDATE ' . QubitPhysicalObject::TABLE_NAME . ' SET ' . QubitPhysicalObject::RGT . ' = ' . QubitPhysicalObject::RGT . ' - ? WHERE ' . QubitPhysicalObject::RGT . ' >= ?'); $statement->execute(array($delta, $this->rgt)); return $this; }
public function delete($connection = null) { if (!isset($connection)) { $connection = QubitTransactionFilter::getConnection(QubitObject::DATABASE_NAME); } $statement = $connection->prepare(' DELETE FROM ' . QubitSlug::TABLE_NAME . ' WHERE ' . QubitSlug::OBJECT_ID . ' = ?'); $statement->execute(array($this->id)); // Delete other names if (0 < count($this->otherNames)) { foreach ($this->otherNames as $otherName) { $otherName->delete(); } } parent::delete($connection); }