Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions UPGRADE_TO_1_2
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ fetching relationships.
Now if we were to do the following PHP we'll get the SQL with an order by.

[php]
$q = Doctrine::getTable('User')
$q = Doctrine_Core::getTable('User')
->createQuery('u')
->leftJoin('u.Articles a');

Expand All @@ -826,7 +826,7 @@ Now you should see this SQL query.
Or if you lazily fetch the `Articles` they will be lazily loaded with the order by.

[php]
$user = Doctrine::getTable('User')->find(1);
$user = Doctrine_Core::getTable('User')->find(1);
$articles = $user->Articles;

This would execute the following SQL query.
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "friendsofsymfony1/doctrine1",
"name": "james-and-james-fulfilment/doctrine1",
"type": "library",
"description": "PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2",
"keywords": ["orm", "database", "symfony1", "doctrine1"],
Expand All @@ -16,7 +16,7 @@
},
{
"name": "Doctrine1 Contributors",
"homepage": "https://github.com/FriendsOfSymfony1/doctrine1/graphs/contributors"
"homepage": "https://github.com/JamesAndJamesFulfilment/doctrine1/graphs/contributors"
}
],
"require": {
Expand All @@ -25,8 +25,8 @@
"ext-pdo": "*"
},
"support": {
"issues": "https://github.com/FriendsOfSymfony1/doctrine1/issues",
"source": "https://github.com/FriendsOfSymfony1/doctrine1"
"issues": "https://github.com/JamesAndJamesFulfilment/doctrine1/issues",
"source": "https://github.com/JamesAndJamesFulfilment/doctrine1"
},
"autoload": {
"psr-0": {
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public static function setPath($path)
public static function getPath()
{
if ( ! self::$_path) {
self::$_path = realpath(dirname(__FILE__) . '/..');
self::$_path = realpath(__DIR__ . '/..');
}

return self::$_path;
Expand Down Expand Up @@ -1132,7 +1132,7 @@ public static function compile($target = null, $includedDrivers = array())
public static function autoload($className)
{
if (strpos($className, 'sfYaml') === 0) {
require dirname(__FILE__) . '/Parser/sfYaml/' . $className . '.php';
require __DIR__ . '/Parser/sfYaml/' . $className . '.php';

return true;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/Doctrine/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public function quoteIdentifier($str, $checkOption = true)
return $str;
}
$tmp = $this->conn->identifier_quoting;

// Avoid double parsing
// http://www.doctrine-project.org/jira/browse/DC-972
if ((substr($str, 0, 1) === $tmp['start']) && (substr($str, -1) === $tmp['end'])) {
return $str;
}

$str = str_replace($tmp['end'],
$tmp['escape'] .
$tmp['end'], $str);
Expand Down
11 changes: 10 additions & 1 deletion lib/Doctrine/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ public static function unaccent($string)
'Å'=>'Aa','Æ'=>'Ae','Ø'=>'O','æ'=>'a','ø'=>'o','å'=>'aa'
);

// JS added basic cyrillic translit
$cyr = array(
'ж', 'ч', 'щ', 'ш', 'ю', 'а', 'б', 'в', 'г', 'д', 'e', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ъ', 'ь', 'я',
'Ж', 'Ч', 'Щ', 'Ш', 'Ю', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ъ', 'Ь', 'Я');
$lat = array(
'zh', 'ch', 'sht', 'sh', 'yu', 'a', 'b', 'v', 'g', 'd', 'e', 'z', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', 'y', 'x', 'q',
'Zh', 'Ch', 'Sht', 'Sh', 'Yu', 'A', 'B', 'V', 'G', 'D', 'E', 'Z', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'H', 'c', 'Y', 'X', 'Q');
$string = str_replace($cyr, $lat, $string);

$string = strtr($string, $chars);
} else {
// Assume ISO-8859-1 if not UTF-8
Expand Down Expand Up @@ -275,4 +284,4 @@ public static function urlize($text)

return trim($text, '-');
}
}
}
30 changes: 30 additions & 0 deletions lib/Doctrine/Lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,36 @@ public static function arrayDeepMerge()
}
}

/**
* arrayDeepCombine
*
* Recursively walks down the destination array and attempts to merge
* the compare array at the same key.
*
* @param array $destination
* @param array $compare
*
* @return void
*/
public static function arrayDeepCombine(array $destination, array $compare)
{
// If we encounter a scenario where we have two array properties then we
// should recursively call this method and set the keys.
foreach ($destination as $key => $value) {
if (empty($compare[$key])) {
continue;
}

if (is_array($value) && is_array($compare[$key])) {
$destination[$key] = array_merge($destination[$key], $compare[$key]);
} else if (!empty($compare[$key])) {
self::arrayDeepCombine($destination[$key], $compare[$key]);
}
}

return $source;
}

/**
* arrayDiffSimple
*
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/Parser/sfYaml/sfYaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function load($input)
return $input;
}

require_once dirname(__FILE__).'/sfYamlParser.php';
require_once __DIR__.'/sfYamlParser.php';

$yaml = new sfYamlParser();

Expand Down Expand Up @@ -116,7 +116,7 @@ public static function load($input)
*/
public static function dump($array, $inline = 2)
{
require_once dirname(__FILE__).'/sfYamlDumper.php';
require_once __DIR__.'/sfYamlDumper.php';

$yaml = new sfYamlDumper();

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Parser/sfYaml/sfYamlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

require_once(dirname(__FILE__).'/sfYamlInline.php');
require_once(__DIR__.'/sfYamlInline.php');

/**
* sfYamlDumper dumps PHP variables to YAML strings.
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Parser/sfYaml/sfYamlInline.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

require_once dirname(__FILE__).'/sfYaml.php';
require_once __DIR__.'/sfYaml.php';

/**
* sfYamlInline implements a YAML parser/dumper for the YAML inline syntax.
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Parser/sfYaml/sfYamlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

require_once(dirname(__FILE__).'/sfYamlInline.php');
require_once(__DIR__.'/sfYamlInline.php');

if (!defined('PREG_BAD_UTF8_OFFSET_ERROR'))
{
Expand Down
57 changes: 47 additions & 10 deletions lib/Doctrine/Query.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,11 @@ protected function _buildSqlFromPart($ignorePending = false)
if ($k === 0) {
if ( ! $ignorePending && $this->_type == self::SELECT) {
// We may still have pending conditions
$alias_lookup = empty($this->_derivedTable) ? $e[1] : end($e);
$alias = count($e) > 1
? $this->getComponentAlias($e[1])
: null;
$where = $this->_processPendingJoinConditions($alias);
$where = $this->_processPendingJoinConditions($alias_lookup);

// apply inheritance to WHERE part
if ( ! empty($where)) {
Expand Down Expand Up @@ -1098,6 +1099,32 @@ protected function _buildSqlFromPart($ignorePending = false)
return $q;
}

/**
* fromSubquery
* Given a string or a Query object, we will parse this to be a subquery
* which we will later swap the 'from' table for.
*
* There is a current limitation where duplicate aliases will cause an
* error, but we are only really using this method for slow queries.
*
* @param mixed $query
*
* @return void
*/
public function fromSubquery($query)
{
// If we passed a Query (and not a string) ensure we bind the params to this
// query instance, otherwise we will get an error.
if ($query instanceof Doctrine_Query) {
$this->_derivedTableParams = $query->getParams();
}

$this->_derivedTable = $this->parseSubquery($query);
$this->_derivedTable = preg_replace('/d[0-9]*__/i', '', $this->_derivedTable);

return $this;
}

/**
* Processes the pending join conditions, used for dynamically add conditions
* to root component/joined components without interfering in the main dql
Expand Down Expand Up @@ -1126,7 +1153,7 @@ protected function _processPendingJoinConditions($alias)

/**
* builds the sql query from the given parameters and applies things such as
* column aggregation inheritance and limit subqueries if needed
* column aggregation, indexes, inheritance and limit subqueries if needed
*
* @param array $params an array of prepared statement params (needed only in mysql driver
* when limit subquery algorithm is used)
Expand All @@ -1143,11 +1170,12 @@ public function getSqlQuery($params = array(), $limitSubquery = true)

if ($this->_state !== self::STATE_DIRTY) {
$this->fixArrayParameterValues($this->getInternalParams());

// Return compiled SQL
return $this->_sql;
$sql = $this->_sql;
} else {
$sql = $this->buildSqlQuery($limitSubquery);
}
return $this->buildSqlQuery($limitSubquery);
// Apply any indexes which have been specified (if none specified, return the query)
return $this->_applyIndexesToQuery($sql);
}

/**
Expand Down Expand Up @@ -1193,6 +1221,12 @@ public function buildSqlQuery($limitSubquery = true)
$diffQueryComponents = array_diff_key($queryComponentsAfter, $queryComponentsBefore);
$this->_rootAlias = key($diffQueryComponents);
}

if ($this->_derivedTable) {
$alias_parts = explode(' ', $this->_sqlParts['from'][0]);
$alias = end($alias_parts);
$this->_sqlParts['from'][0] = "{$this->_derivedTable} AS {$alias}";
}
}
$this->_state = self::STATE_CLEAN;

Expand Down Expand Up @@ -1369,7 +1403,7 @@ public function buildSqlQuery($limitSubquery = true)
}

$q .= ( ! empty($this->_sqlParts['groupby'])) ? ' GROUP BY ' . implode(', ', $this->_sqlParts['groupby']) : '';
$q .= ( ! empty($this->_sqlParts['having'])) ? ' HAVING ' . implode(' AND ', $this->_sqlParts['having']): '';
$q .= ( ! empty($this->_sqlParts['having'])) ? ' HAVING ' . implode(self::HAVING_JOINER, $this->_sqlParts['having']): '';
$q .= ( ! empty($this->_sqlParts['orderby'])) ? ' ORDER BY ' . implode(', ', $this->_sqlParts['orderby']) : '';

if ($modifyLimit) {
Expand Down Expand Up @@ -1498,7 +1532,7 @@ public function getLimitSubquery()
// all conditions must be preserved in subquery
$subquery .= ( ! empty($this->_sqlParts['where']))? ' WHERE ' . implode(' ', $this->_sqlParts['where']) : '';
$subquery .= ( ! empty($this->_sqlParts['groupby']))? ' GROUP BY ' . implode(', ', $this->_sqlParts['groupby']) : '';
$subquery .= ( ! empty($having))? ' HAVING ' . implode(' AND ', $having) : '';
$subquery .= ( ! empty($having))? ' HAVING ' . implode(self::HAVING_JOINER, $having) : '';
$subquery .= ( ! empty($orderby))? ' ORDER BY ' . implode(', ', $orderby) : '';

if (($driverName == 'oracle' || $driverName == 'oci' || $driverName == 'oci8') && $this->_isOrderedByJoinedColumn()) {
Expand All @@ -1516,6 +1550,8 @@ public function getLimitSubquery()

// add driver specific limit clause
$subquery = $this->_conn->modifyLimitSubquery($table, $subquery, $this->_sqlParts['limit'], $this->_sqlParts['offset']);
// apply any outstanding indexes to the subquery before we rebuild the query parts using new Aliases
$subquery = $this->_applyIndexesToQuery($subquery);

$parts = $this->_tokenizer->quoteExplode($subquery, ' ', "'", "'");

Expand Down Expand Up @@ -1585,6 +1621,7 @@ public function getLimitSubquery()
}

$subquery = implode(' ', $parts);

return $subquery;
}

Expand Down Expand Up @@ -2069,7 +2106,7 @@ public function getCountSqlQuery()
$groupby = ( ! empty($groupby)) ? ' GROUP BY ' . implode(', ', $groupby) : '';

// Build the having clause
$having = ( ! empty($having)) ? ' HAVING ' . implode(' AND ', $having) : '';
$having = ( ! empty($having)) ? ' HAVING ' . implode(self::HAVING_JOINER, $having) : '';

// Building the from clause and finishing query
if (count($this->_queryComponents) == 1 && empty($having)) {
Expand Down Expand Up @@ -2111,7 +2148,7 @@ public function getCountSqlQuery()
. $this->_conn->quoteIdentifier('dctrn_count_query');
}

return $q;
return $this->_applyIndexesToQuery($q);
}

/**
Expand Down
Loading