Skip to content

Commit

Permalink
Merge branch '2.0' into 2.1
Browse files Browse the repository at this point in the history
Conflicts:
	lib/Cake/Test/Case/Model/ModelReadTest.php
	lib/Cake/Utility/Debugger.php
  • Loading branch information
ADmad committed Dec 21, 2011
2 parents c8fd7c0 + 7339640 commit 3890727
Show file tree
Hide file tree
Showing 85 changed files with 533 additions and 431 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Cache/Engine/FileEngine.php
Expand Up @@ -129,14 +129,14 @@ public function write($key, $data, $duration) {
$contents = $expires . $lineBreak . $data . $lineBreak;

if ($this->settings['lock']) {
$this->_File->flock(LOCK_EX);
$this->_File->flock(LOCK_EX);
}

$this->_File->rewind();
$success = $this->_File->ftruncate(0) && $this->_File->fwrite($contents) && $this->_File->fflush();

if ($this->settings['lock']) {
$this->_File->flock(LOCK_UN);
$this->_File->flock(LOCK_UN);
}

return $success;
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Cache/Engine/MemcacheEngine.php
Expand Up @@ -104,7 +104,7 @@ protected function _parseServerString($server) {
$position++;
}
} else {
$position = strpos($server, ':');
$position = strpos($server, ':');
}
$port = 11211;
$host = $server;
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Console/Command/ApiShell.php
Expand Up @@ -101,7 +101,7 @@ public function main() {
$this->_stop();
}
$method = $parsed[$this->params['method']];
$this->out($class .'::'.$method['method'] . $method['parameters']);
$this->out($class . '::' . $method['method'] . $method['parameters']);
$this->hr();
$this->out($method['comment'], true);
} else {
Expand All @@ -127,7 +127,7 @@ public function main() {
if (isset($methods[--$number])) {
$method = $parsed[$methods[$number]];
$this->hr();
$this->out($class .'::'.$method['method'] . $method['parameters']);
$this->out($class . '::' . $method['method'] . $method['parameters']);
$this->hr();
$this->out($method['comment'], true);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Console/Command/Task/ProjectTask.php
Expand Up @@ -269,7 +269,7 @@ public function securitySalt($path) {
$contents = $File->read();
if (preg_match('/([\s]*Configure::write\(\'Security.salt\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
$string = Security::generateAuthKey();
$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.salt\', \''.$string.'\');', $contents);
$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.salt\', \'' . $string . '\');', $contents);
if ($File->write($result)) {
return true;
}
Expand All @@ -290,7 +290,7 @@ public function securityCipherSeed($path) {
if (preg_match('/([\s]*Configure::write\(\'Security.cipherSeed\',[\s\'A-z0-9]*\);)/', $contents, $match)) {
App::uses('Security', 'Utility');
$string = substr(bin2hex(Security::generateAuthKey()), 0, 30);
$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.cipherSeed\', \''.$string.'\');', $contents);
$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.cipherSeed\', \'' . $string . '\');', $contents);
if ($File->write($result)) {
return true;
}
Expand Down Expand Up @@ -357,7 +357,7 @@ public function cakeAdmin($name) {
$File = new File($path . 'core.php');
$contents = $File->read();
if (preg_match('%(\s*[/]*Configure::write\(\'Routing.prefixes\',[\s\'a-z,\)\(]*\);)%', $contents, $match)) {
$result = str_replace($match[0], "\n" . 'Configure::write(\'Routing.prefixes\', array(\''.$name.'\'));', $contents);
$result = str_replace($match[0], "\n" . 'Configure::write(\'Routing.prefixes\', array(\'' . $name . '\'));', $contents);
if ($File->write($result)) {
Configure::write('Routing.prefixes', array($name));
return true;
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Console/Command/UpgradeShell.php
Expand Up @@ -222,6 +222,7 @@ public function helpers() {
$plugins = App::objects('plugin');
$pluginHelpers = array();
foreach ($plugins as $plugin) {
CakePlugin::load($plugin);
$pluginHelpers = array_merge(
$pluginHelpers,
App::objects('helper', App::pluginPath($plugin) . DS . 'views' . DS . 'helpers' . DS, false)
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/Controller/Component/AclComponent.php
Expand Up @@ -488,11 +488,11 @@ public function getAclLink($aro, $aco) {
}

return array(
'aro' => Set::extract($obj, 'Aro.0.'.$this->Aro->alias.'.id'),
'aco' => Set::extract($obj, 'Aco.0.'.$this->Aco->alias.'.id'),
'aro' => Set::extract($obj, 'Aro.0.' . $this->Aro->alias . '.id'),
'aco' => Set::extract($obj, 'Aco.0.' . $this->Aco->alias . '.id'),
'link' => $this->Aro->Permission->find('all', array('conditions' => array(
$this->Aro->Permission->alias . '.aro_id' => Set::extract($obj, 'Aro.0.'.$this->Aro->alias.'.id'),
$this->Aro->Permission->alias . '.aco_id' => Set::extract($obj, 'Aco.0.'.$this->Aco->alias.'.id')
$this->Aro->Permission->alias . '.aro_id' => Set::extract($obj, 'Aro.0.' . $this->Aro->alias . '.id'),
$this->Aro->Permission->alias . '.aco_id' => Set::extract($obj, 'Aco.0.' . $this->Aco->alias . '.id')
)))
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/AuthComponent.php
Expand Up @@ -314,7 +314,7 @@ public function startup($controller) {
if (!$this->_getUser()) {
if (!$request->is('ajax')) {
$this->flash($this->authError);
$this->Session->write('Auth.redirect', Router::reverse($request));
$this->Session->write('Auth.redirect', $request->here());
$controller->redirect($loginAction);
return false;
} elseif (!empty($this->ajaxLogin)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Controller/Controller.php
Expand Up @@ -981,7 +981,7 @@ public function postConditions($data = array(), $op = null, $bool = 'AND', $excl
$arrayOp = is_array($op);
foreach ($data as $model => $fields) {
foreach ($fields as $field => $value) {
$key = $model.'.'.$field;
$key = $model . '.' . $field;
$fieldOp = $op;
if ($arrayOp) {
if (array_key_exists($key, $op)) {
Expand All @@ -998,9 +998,9 @@ public function postConditions($data = array(), $op = null, $bool = 'AND', $excl
$fieldOp = strtoupper(trim($fieldOp));
if ($fieldOp === 'LIKE') {
$key = $key.' LIKE';
$value = '%'.$value.'%';
$value = '%' . $value . '%';
} elseif ($fieldOp && $fieldOp != '=') {
$key = $key.' '.$fieldOp;
$key = $key.' ' . $fieldOp;
}
$cond[$key] = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Core/App.php
Expand Up @@ -681,7 +681,7 @@ protected static function _loadClass($name, $plugin, $type, $originalType, $pare
}
App::uses($extends, $extendType);
if ($plugin && in_array($originalType, array('controller', 'model'))) {
App::uses($plugin . $extends, $plugin . '.' .$type);
App::uses($plugin . $extends, $plugin . '.' . $type);
}
}
if ($plugin) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/I18n/I18n.php
Expand Up @@ -164,7 +164,7 @@ public static function translate($singular, $plural = null, $domain = null, $cat
}

if ($_this->category == 'LC_TIME') {
return $_this->_translateTime($singular,$domain);
return $_this->_translateTime($singular, $domain);
}

if (!isset($count)) {
Expand Down Expand Up @@ -466,7 +466,7 @@ protected function _loadPo($file, $domain) {
} while (!feof($file));
fclose($file);
$merge[""] = $header;
return $this->_domains[$domain][$this->_lang][$this->category] = array_merge($merge ,$translations);
return $this->_domains[$domain][$this->_lang][$this->category] = array_merge($merge, $translations);
}

/**
Expand All @@ -486,7 +486,7 @@ protected function _loadLocaleDefinition($file, $domain = null) {
if (empty($line) || $line[0] === $comment) {
continue;
}
$parts = preg_split("/[[:space:]]+/",$line);
$parts = preg_split("/[[:space:]]+/", $line);
if ($parts[0] === 'comment_char') {
$comment = $parts[1];
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/I18n/Multibyte.php
Expand Up @@ -893,7 +893,7 @@ public static function strtoupper($string) {
* @param string $haystack The string being checked.
* @param string $needle The string being found.
* @return integer The number of times the $needle substring occurs in the $haystack string.
*/
*/
public static function substrCount($haystack, $needle) {
$count = 0;
$haystack = Multibyte::utf8($haystack);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/AclNode.php
Expand Up @@ -95,7 +95,7 @@ public function node($ref = null) {
$queryData['joins'][] = array(
'table' => $table,
'alias' => "{$type}{$i}",
'type' => 'LEFT',
'type' => 'LEFT',
'conditions' => array(
$db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"),
$db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"),
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Model/Aco.php
Expand Up @@ -17,6 +17,7 @@
*/

App::uses('AppModel', 'Model');
App::uses('AclNode', 'Model');

/**
* Access Control Object
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Model/Aro.php
Expand Up @@ -17,6 +17,7 @@
*/

App::uses('AppModel', 'Model');
App::uses('AclNode', 'Model');

/**
* Access Request Object
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Model/Behavior/ContainableBehavior.php
Expand Up @@ -308,10 +308,10 @@ public function containments($Model, $contain, $containments = array(), $throwEr
$val = preg_split('/\s*,\s*/', substr(substr($key, 1), 0, -1));
} elseif (preg_match('/ASC|DESC$/', $key)) {
$option = 'order';
$val = $Model->{$name}->alias.'.'.$key;
$val = $Model->{$name}->alias . '.' . $key;
} elseif (preg_match('/[ =!]/', $key)) {
$option = 'conditions';
$val = $Model->{$name}->alias.'.'.$key;
$val = $Model->{$name}->alias . '.' . $key;
}
$children[$option] = is_array($val) ? $val : array($val);
$newChildren = null;
Expand Down
40 changes: 20 additions & 20 deletions lib/Cake/Model/Behavior/TranslateBehavior.php
Expand Up @@ -104,8 +104,8 @@ public function beforeFind($model, $query) {
$joinTable->table = $RuntimeModel->table;
$joinTable->schemaName = $RuntimeModel->getDataSource()->getSchemaName();

if (is_string($query['fields']) && 'COUNT(*) AS '.$db->name('count') == $query['fields']) {
$query['fields'] = 'COUNT(DISTINCT('.$db->name($model->alias . '.' . $model->primaryKey) . ')) ' . $db->alias . 'count';
if (is_string($query['fields']) && 'COUNT(*) AS ' . $db->name('count') == $query['fields']) {
$query['fields'] = 'COUNT(DISTINCT(' . $db->name($model->alias . '.' . $model->primaryKey) . ')) ' . $db->alias . 'count';
$query['joins'][] = array(
'type' => 'INNER',
'alias' => $RuntimeModel->alias,
Expand All @@ -127,7 +127,7 @@ public function beforeFind($model, $query) {
foreach ($fields as $key => $value) {
$field = (is_numeric($key)) ? $value : $key;

if (in_array($model->alias.'.*', $query['fields']) || in_array($model->alias.'.'.$field, $query['fields']) || in_array($field, $query['fields'])) {
if (in_array($model->alias.'.*', $query['fields']) || in_array($model->alias.'.' . $field, $query['fields']) || in_array($field, $query['fields'])) {
$addFields[] = $field;
}
}
Expand All @@ -138,7 +138,7 @@ public function beforeFind($model, $query) {
foreach ($addFields as $_f => $field) {
$aliasField = is_numeric($_f) ? $field : $_f;

foreach (array($aliasField, $model->alias.'.'.$aliasField) as $_field) {
foreach (array($aliasField, $model->alias . '.' . $aliasField) as $_field) {
$key = array_search($_field, (array)$query['fields']);

if ($key !== false) {
Expand All @@ -148,36 +148,36 @@ public function beforeFind($model, $query) {

if (is_array($locale)) {
foreach ($locale as $_locale) {
$model->virtualFields['i18n_'.$field.'_'.$_locale] = 'I18n__'.$field.'__'.$_locale.'.content';
$model->virtualFields['i18n_' . $field . '_' . $_locale] = 'I18n__' . $field . '__' . $_locale . '.content';
if (!empty($query['fields'])) {
$query['fields'][] = 'i18n_'.$field.'_'.$_locale;
$query['fields'][] = 'i18n_' . $field . '_' . $_locale;
}
$query['joins'][] = array(
'type' => 'LEFT',
'alias' => 'I18n__'.$field.'__'.$_locale,
'alias' => 'I18n__' . $field . '__' . $_locale,
'table' => $joinTable,
'conditions' => array(
$model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}__{$_locale}.foreign_key"),
'I18n__'.$field.'__'.$_locale.'.model' => $model->name,
'I18n__'.$field.'__'.$_locale.'.'.$RuntimeModel->displayField => $aliasField,
'I18n__'.$field.'__'.$_locale.'.locale' => $_locale
'I18n__' . $field . '__' . $_locale . '.model' => $model->name,
'I18n__' . $field . '__' . $_locale . '.' . $RuntimeModel->displayField => $aliasField,
'I18n__' . $field . '__' . $_locale . '.locale' => $_locale
)
);
}
} else {
$model->virtualFields['i18n_'.$field] = 'I18n__'.$field.'.content';
$model->virtualFields['i18n_' . $field] = 'I18n__' . $field . '.content';
if (!empty($query['fields'])) {
$query['fields'][] = 'i18n_'.$field;
$query['fields'][] = 'i18n_' . $field;
}
$query['joins'][] = array(
'type' => 'INNER',
'alias' => 'I18n__'.$field,
'alias' => 'I18n__' . $field,
'table' => $joinTable,
'conditions' => array(
$model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}.foreign_key"),
'I18n__'.$field.'.model' => $model->name,
'I18n__'.$field.'.'.$RuntimeModel->displayField => $aliasField,
'I18n__'.$field.'.locale' => $locale
'I18n__' . $field . '.model' => $model->name,
'I18n__' . $field . '.' . $RuntimeModel->displayField => $aliasField,
'I18n__' . $field . '.locale' => $locale
)
);
}
Expand Down Expand Up @@ -212,11 +212,11 @@ public function afterFind($model, $results, $primary) {

if (is_array($locale)) {
foreach ($locale as $_locale) {
if (!isset($row[$model->alias][$aliasField]) && !empty($row[$model->alias]['i18n_'.$field.'_'.$_locale])) {
$row[$model->alias][$aliasField] = $row[$model->alias]['i18n_'.$field.'_'.$_locale];
if (!isset($row[$model->alias][$aliasField]) && !empty($row[$model->alias]['i18n_' . $field . '_' . $_locale])) {
$row[$model->alias][$aliasField] = $row[$model->alias]['i18n_' . $field . '_' . $_locale];
$row[$model->alias]['locale'] = $_locale;
}
unset($row[$model->alias]['i18n_'.$field.'_'.$_locale]);
unset($row[$model->alias]['i18n_' . $field . '_' . $_locale]);
}

if (!isset($row[$model->alias][$aliasField])) {
Expand Down Expand Up @@ -421,7 +421,7 @@ public function bindTranslation($model, $fields, $reset = true) {
foreach (array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany') as $type) {
if (isset($model->{$type}[$association]) || isset($model->__backAssociation[$type][$association])) {
trigger_error(
__d('cake_dev', 'Association %s is already binded to model %s', $association, $model->alias),
__d('cake_dev', 'Association %s is already bound to model %s', $association, $model->alias),
E_USER_ERROR
);
return false;
Expand Down
17 changes: 8 additions & 9 deletions lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -163,8 +163,8 @@ public function beforeSave($Model) {
$this->_addToWhitelist($Model, $parent);
} else {
$values = $Model->find('first', array(
'conditions' => array($scope,$Model->escapeField() => $Model->id),
'fields' => array($Model->primaryKey, $parent, $left, $right ), 'recursive' => $recursive)
'conditions' => array($scope, $Model->escapeField() => $Model->id),
'fields' => array($Model->primaryKey, $parent, $left, $right), 'recursive' => $recursive)
);

if ($values === false) {
Expand Down Expand Up @@ -503,7 +503,7 @@ public function moveUp($Model, $id = null, $number = 1) {
extract($this->settings[$Model->alias]);
list($node) = array_values($Model->find('first', array(
'conditions' => array($scope, $Model->escapeField() => $id),
'fields' => array($Model->primaryKey, $left, $right, $parent ), 'recursive' => $recursive
'fields' => array($Model->primaryKey, $left, $right, $parent), 'recursive' => $recursive
)));
if ($node[$parent]) {
list($parentNode) = array_values($Model->find('first', array(
Expand All @@ -527,7 +527,7 @@ public function moveUp($Model, $id = null, $number = 1) {
}
$edge = $this->_getMax($Model, $scope, $right, $recursive);
$this->_sync($Model, $edge - $previousNode[$left] +1, '+', 'BETWEEN ' . $previousNode[$left] . ' AND ' . $previousNode[$right]);
$this->_sync($Model, $node[$left] - $previousNode[$left], '-', 'BETWEEN ' .$node[$left] . ' AND ' . $node[$right]);
$this->_sync($Model, $node[$left] - $previousNode[$left], '-', 'BETWEEN ' . $node[$left] . ' AND ' . $node[$right]);
$this->_sync($Model, $edge - $previousNode[$left] - ($node[$right] - $node[$left]), '-', '> ' . $edge);
if (is_int($number)) {
$number--;
Expand Down Expand Up @@ -577,7 +577,6 @@ public function recover($Model, $mode = 'parent', $missingParentAction = null) {
if ($missingParentAction == 'return') {
foreach ($missingParents as $id => $display) {
$this->errors[] = 'cannot find the parent for ' . $Model->alias . ' with id ' . $id . '(' . $display . ')';

}
return false;
} elseif ($missingParentAction == 'delete') {
Expand All @@ -588,13 +587,14 @@ public function recover($Model, $mode = 'parent', $missingParentAction = null) {
}
$count = 1;
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey), 'order' => $left)) as $array) {
$Model->id = $array[$Model->alias][$Model->primaryKey];
$lft = $count++;
$rght = $count++;
$Model->create(false);
$Model->id = $array[$Model->alias][$Model->primaryKey];
$Model->save(array($left => $lft, $right => $rght), array('callbacks' => false));
}
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) {
$Model->create();
$Model->create(false);
$Model->id = $array[$Model->alias][$Model->primaryKey];
$this->_setParent($Model, $array[$Model->alias][$parent]);
}
Expand Down Expand Up @@ -846,11 +846,10 @@ protected function _setParent($Model, $parentId = null, $created = false) {

if (($Model->id == $parentId)) {
return false;

} elseif (($node[$left] < $parentNode[$left]) && ($parentNode[$right] < $node[$right])) {
return false;
}
if (empty ($node[$left]) && empty ($node[$right])) {
if (empty($node[$left]) && empty($node[$right])) {
$this->_sync($Model, 2, '+', '>= ' . $parentNode[$right], $created);
$result = $Model->save(
array($left => $parentNode[$right], $right => $parentNode[$right] + 1, $parent => $parentId),
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Model/Datasource/CakeSession.php
Expand Up @@ -158,10 +158,10 @@ protected static function _setPath($base = null) {
return;
}
if (strpos($base, 'index.php') !== false) {
$base = str_replace('index.php', '', $base);
$base = str_replace('index.php', '', $base);
}
if (strpos($base, '?') !== false) {
$base = str_replace('?', '', $base);
$base = str_replace('?', '', $base);
}
self::$path = $base;
}
Expand Down

0 comments on commit 3890727

Please sign in to comment.