getCurrentConnection(); if ($dm->getConnectionName($oldConn) === 'master') { return $oldConn; } $dm->setCurrentConnection('master'); $conn = $dm->getCurrentConnection(); foreach ($oldConn->getIterator() as $table) { $conn->addTable($table); $table->setConnection($conn); } $oldConn->close(); return $conn; } /** * Creates a Doctrine_Query class * * @return Doctrine_Query */ public static function create($conn = null, $class = null) { if (self::$defaultClass) { $className = self::$defaultClass; } elseif (function_exists('get_called_class')) { $className = get_called_class(); } else { $className = __CLASS__; } return new $className($conn, $class); } public function getDQInstance($conn = null, $class = null) { return self::create($conn, $class); } public function getHydratorName() { return $this->hydratorName; } public function setHydratorName($hydratorName) { $this->hydratorName = $hydratorName; } /** * execute * executes the query and populates the data set * * @param array $params * @return Doctrine_Collection the root collection */ public function execute($params = array(), $hydrationMode = null) { if ((is_null($hydrationMode) || $hydrationMode == Doctrine_Core::HYDRATE_RECORD) && $this->hydratorName) { $hydrationMode = $this->hydratorName; } return parent::execute($params, $hydrationMode); } public function preQuery() { if ($this->preQueried === true) { return; } $this->preQueried = true; // force to master if this is not a select if ($this->getType() !== self::SELECT) { $this->_conn = self::switchToMaster(); } } /** * This function will wrap the current dql where statement * in parenthesis. This allows more complex dql statements * It can be called multiple times during the creation of the dql * where clause. * * @return $this */ public function whereParenWrap() { $where = $this->_dqlParts['where']; if (count($where) > 0) { array_unshift($where, '('); array_push($where, ')'); $this->_dqlParts['where'] = $where; } return $this; } /** * Create and andWhere if the where parameter is not empty * * @param string $where where string * @param parameters $params * * @return DQ this object */ public function andWhereIf($where, $params = array()) { return empty($where) ? $this : $this->andWhere($where, $params); } /** * Create and orWhere if the where parameter is not empty * * @param string $where where string * @param parameters $params * * @return DQ this object */ public function orWhereIf($where, $params = array()) { return empty($where) ? $this : $this->orWhere($where, $params); } /** * orderByValues * sets the ORDER BY using the MySQL proprietary FIELD() function to force * a sorting by a list of values for a single given column * * @param string $column column name * @param array $values integer values in the order in which they shold appear in the result * @return Doctrine_Query */ public function orderByValues($column, $values) { $field = "FIELD($column"; foreach ($values as $value) { $field.= ", ".(int)$value; } $field.= ")"; return $this->orderBy($field); } }