mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
fixes #5772.
Sql errors when using reserved words for a field name with the tree behavior. Test Case restructured to allow thorough testing of the various permutations inwhich the tree behavior can be used git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7880 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
ffab7024f0
commit
2f51ccca04
4 changed files with 807 additions and 583 deletions
|
@ -224,7 +224,7 @@ class TreeBehavior extends ModelBehavior {
|
|||
|
||||
if ($id === null) {
|
||||
return $model->find('count', array('conditions' => $scope));
|
||||
} elseif (!empty ($model->data)) {
|
||||
} elseif (isset($model->data[$model->alias][$left]) && isset($model->data[$model->alias][$right])) {
|
||||
$data = $model->data[$model->alias];
|
||||
} else {
|
||||
list($data) = array_values($model->find('first', array('conditions' => array($scope, $model->escapeField() => $id), 'recursive' => $recursive)));
|
||||
|
@ -766,11 +766,10 @@ class TreeBehavior extends ModelBehavior {
|
|||
$errors[] = array('node', $instance[$model->alias][$model->primaryKey],
|
||||
'right greater than parent (node ' . $instance['VerifyParent'][$model->primaryKey] . ').');
|
||||
}
|
||||
} elseif ($model->find('count', array('conditions' => array($scope, $model->escapeField($left) . '< ' . $instance[$model->alias][$left], $right . '> ' . $instance[$model->alias][$right]), 'recursive' => 0))) {
|
||||
} elseif ($model->find('count', array('conditions' => array($scope, $model->escapeField($left) . ' <' => $instance[$model->alias][$left], $model->escapeField($right) . ' >' => $instance[$model->alias][$right]), 'recursive' => 0))) {
|
||||
$errors[] = array('node', $instance[$model->alias][$model->primaryKey], 'The parent field is blank, but has a parent');
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
return $errors;
|
||||
}
|
||||
|
@ -919,7 +918,7 @@ class TreeBehavior extends ModelBehavior {
|
|||
if ($created) {
|
||||
$conditions['NOT'][$model->alias . '.' . $model->primaryKey] = $model->id;
|
||||
}
|
||||
$model->updateAll(array($model->alias . '.' . $field => $model->alias . '.' . $field . ' ' . $dir . ' ' . $shift), $conditions);
|
||||
$model->updateAll(array($model->alias . '.' . $field => $model->escapeField($field) . ' ' . $dir . ' ' . $shift), $conditions);
|
||||
$model->recursive = $modelRecursive;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2246,7 +2246,8 @@ class NumberTree extends CakeTestModel {
|
|||
*/
|
||||
function initialize($levelLimit = 3, $childLimit = 3, $currentLevel = null, $parent_id = null, $prefix = '1', $hierachial = true) {
|
||||
if (!$parent_id) {
|
||||
$this->deleteAll(true);
|
||||
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||
$db->truncate($this->table);
|
||||
$this->save(array($this->name => array('name' => '1. Root')));
|
||||
$this->initialize($levelLimit, $childLimit, 1, $this->id, '1', $hierachial);
|
||||
$this->create(array());
|
||||
|
@ -2262,7 +2263,11 @@ class NumberTree extends CakeTestModel {
|
|||
$this->create($data);
|
||||
|
||||
if ($hierachial) {
|
||||
$data[$this->name]['parent_id'] = $parent_id;
|
||||
if ($this->name == 'UnconventionalTree') {
|
||||
$data[$this->name]['join'] = $parent_id;
|
||||
} else {
|
||||
$data[$this->name]['parent_id'] = $parent_id;
|
||||
}
|
||||
}
|
||||
$this->save($data);
|
||||
$this->initialize($levelLimit, $childLimit, $currentLevel + 1, $this->id, $name, $hierachial);
|
||||
|
@ -2284,6 +2289,28 @@ class FlagTree extends NumberTree {
|
|||
*/
|
||||
var $name = 'FlagTree';
|
||||
}
|
||||
/**
|
||||
* UnconventionalTree class
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class UnconventionalTree extends NumberTree {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'FlagTree'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'UnconventionalTree';
|
||||
var $actsAs = array(
|
||||
'Tree' => array(
|
||||
'parent' => 'join',
|
||||
'left' => 'left',
|
||||
'right' => 'right'
|
||||
)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Campaign class
|
||||
*
|
||||
|
@ -2341,7 +2368,7 @@ class Ad extends CakeTestModel {
|
|||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class AfterTree extends CakeTestModel {
|
||||
class AfterTree extends NumberTree {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
|
|
56
cake/tests/fixtures/unconventional_tree_fixture.php
vendored
Normal file
56
cake/tests/fixtures/unconventional_tree_fixture.php
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Unconventional Tree behavior class test fixture.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.fixtures
|
||||
* @since CakePHP(tm) v 1.2.0.7879
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
/**
|
||||
* UnconventionalTreeFixture class
|
||||
*
|
||||
* Like Number tree, but doesn't use the default values for lft and rght or parent_id
|
||||
*
|
||||
* @uses CakeTestFixture
|
||||
* @package cake
|
||||
* @subpackage cake.tests.fixtures
|
||||
*/
|
||||
class UnconventionalTreeFixture extends CakeTestFixture {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'FlagTree'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'UnconventionalTree';
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'integer','key' => 'primary'),
|
||||
'name' => array('type' => 'string','null' => false),
|
||||
'join' => 'integer',
|
||||
'left' => array('type' => 'integer','null' => false),
|
||||
'right' => array('type' => 'integer','null' => false),
|
||||
);
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue