mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing TreeBehavior so tests will work on php 4.
Removing _ _METHOD_ _ from files since it is not valid on php 4 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5337 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
15c8d5012e
commit
b7ba57c8b1
3 changed files with 15 additions and 57 deletions
|
@ -128,7 +128,7 @@ class TreeBehavior extends ModelBehavior {
|
|||
$parentNode = $model->find(array($scope, $model->escapeField() => $model->data[$model->name][$parent]),
|
||||
array($model->primaryKey), null, -1);
|
||||
if (!$parentNode) {
|
||||
trigger_error(__('Trying to save a node under a none-existant node in ' . __METHOD__, E_USER_WARNING));
|
||||
trigger_error(__('Trying to save a node under a none-existant node in TreeBehavior::beforeSave', E_USER_WARNING));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -142,16 +142,16 @@ class TreeBehavior extends ModelBehavior {
|
|||
$parentNode = $model->find(array($scope, $model->escapeField() => $model->data[$model->name][$parent]),
|
||||
array($model->primaryKey, $left, $right), null, -1);
|
||||
if (!$parentNode) {
|
||||
trigger_error(__('Trying to save a node under a none-existant node in ' . __METHOD__, E_USER_WARNING));
|
||||
trigger_error(__('Trying to save a node under a none-existant node in TreeBehavior::beforeSave', E_USER_WARNING));
|
||||
return false;
|
||||
} else {
|
||||
list($parentNode) = array_values($parentNode);
|
||||
if (($node[$left] < $parentNode[$left]) && ($parentNode[$right] < $node[$right])) {
|
||||
trigger_error(__('Trying to save a node under itself in ' . __METHOD__, E_USER_WARNING));
|
||||
trigger_error(__('Trying to save a node under itself in TreeBehavior::beforeSave', E_USER_WARNING));
|
||||
return false;
|
||||
}
|
||||
elseif ($node[$model->primaryKey] == $parentNode[$model->primaryKey]) {
|
||||
trigger_error(__('Trying to set a node to be the parent of itself in ' . __METHOD__, E_USER_WARNING));
|
||||
trigger_error(__('Trying to set a node to be the parent of itself in TreeBehavior::beforeSave', E_USER_WARNING));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -321,7 +321,8 @@ class TreeBehavior extends ModelBehavior {
|
|||
|
||||
if ($parentId) {
|
||||
$parentId = $parentId[$model->name][$parent];
|
||||
$parent = $model->findById($parentId, $fields, null, $recursive);
|
||||
$parent = $model->find(array($model->name . '.' . $model->primaryKey => $parentId), $fields, null, $recursive);
|
||||
|
||||
return $parent;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -342,7 +343,7 @@ class TreeBehavior extends ModelBehavior {
|
|||
$id = $model->id;
|
||||
}
|
||||
extract($this->settings[$model->name]);
|
||||
@list($item) = array_values($model->findById($id, array($left, $right)));
|
||||
@list($item) = array_values($model->find(array($model->name . '.' . $model->primaryKey => $id), array($left, $right)));
|
||||
|
||||
if (empty ($item)) {
|
||||
return null;
|
||||
|
@ -626,15 +627,15 @@ class TreeBehavior extends ModelBehavior {
|
|||
list($parentNode)= array_values($model->find(array($scope, $model->escapeField() => $parentId),
|
||||
array($model->primaryKey, $left, $right), null, -1));
|
||||
if (empty ($parentNode)) {
|
||||
trigger_error(__('Trying to move a node under a none-existant node in ' . __METHOD__, true), E_USER_WARNING);
|
||||
trigger_error(__('Trying to move a node under a none-existant node in TreeBehavior::_setParent', true), E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
elseif (($model->id == $parentId)) {
|
||||
trigger_error(__('Trying to set a node to be the parent of itself in ' . __METHOD__, E_USER_WARNING));
|
||||
trigger_error(__('Trying to set a node to be the parent of itself in TreeBehavior::_setParent', E_USER_WARNING));
|
||||
return false;
|
||||
}
|
||||
elseif (($node[$left] < $parentNode[$left]) && ($parentNode[$right] < $node[$right])) {
|
||||
trigger_error(__('Trying to move a node under itself in ' . __METHOD__, E_USER_WARNING));
|
||||
trigger_error(__('Trying to move a node under itself in TreeBehavior::_setParent', E_USER_WARNING));
|
||||
return false;
|
||||
}
|
||||
if (empty ($node[$left]) && empty ($node[$right])) {
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
* Included libs
|
||||
*/
|
||||
uses('class_registry', 'validation', 'overloadable', 'model' . DS . 'behavior', 'model' . DS . 'connection_manager', 'set');
|
||||
|
||||
/**
|
||||
* Object-relational mapper.
|
||||
*
|
||||
|
@ -46,7 +45,6 @@ uses('class_registry', 'validation', 'overloadable', 'model' . DS . 'behavior',
|
|||
* @subpackage cake.cake.libs.model
|
||||
*/
|
||||
class Model extends Overloadable {
|
||||
|
||||
/**
|
||||
* The name of the DataSource connection that this Model uses
|
||||
*
|
||||
|
@ -54,7 +52,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $useDbConfig = 'default';
|
||||
|
||||
/**
|
||||
* Enter description here... Still used?
|
||||
*
|
||||
|
@ -63,7 +60,6 @@ class Model extends Overloadable {
|
|||
* @todo Is this still used? -OJ 22 nov 2006
|
||||
*/
|
||||
var $parent = false;
|
||||
|
||||
/**
|
||||
* Custom database table name.
|
||||
*
|
||||
|
@ -71,7 +67,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $useTable = null;
|
||||
|
||||
/**
|
||||
* Custom display field name. Display fields are used by Scaffold, in SELECT boxes' OPTION elements.
|
||||
*
|
||||
|
@ -79,7 +74,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $displayField = null;
|
||||
|
||||
/**
|
||||
* Value of the primary key ID of the record that this model is currently pointing to
|
||||
*
|
||||
|
@ -87,7 +81,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $id = false;
|
||||
|
||||
/**
|
||||
* Container for the data that this model gets from persistent storage (the database).
|
||||
*
|
||||
|
@ -95,7 +88,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $data = array();
|
||||
|
||||
/**
|
||||
* Table name for this Model.
|
||||
*
|
||||
|
@ -103,7 +95,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $table = false;
|
||||
|
||||
/**
|
||||
* The name of the ID field for this Model.
|
||||
*
|
||||
|
@ -111,7 +102,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $primaryKey = null;
|
||||
|
||||
/**
|
||||
* Table metadata
|
||||
*
|
||||
|
@ -119,7 +109,6 @@ class Model extends Overloadable {
|
|||
* @access private
|
||||
*/
|
||||
var $_tableInfo = null;
|
||||
|
||||
/**
|
||||
* List of validation rules. Append entries for validation as ('field_name' => '/^perl_compat_regexp$/')
|
||||
* that have to match with preg_match(). Use these rules with Model::validate()
|
||||
|
@ -128,14 +117,12 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $validate = array();
|
||||
|
||||
/**
|
||||
* Errors in validation
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $validationErrors = array();
|
||||
|
||||
/**
|
||||
* Database table prefix for tables in model.
|
||||
*
|
||||
|
@ -143,21 +130,18 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $tablePrefix = null;
|
||||
|
||||
/**
|
||||
* Name of the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $name = null;
|
||||
|
||||
/**
|
||||
* Name of the current model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $currentModel = null;
|
||||
|
||||
/**
|
||||
* List of table names included in the Model description. Used for associations.
|
||||
*
|
||||
|
@ -165,7 +149,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $tableToModel = array();
|
||||
|
||||
/**
|
||||
* List of Model names by used tables. Used for associations.
|
||||
*
|
||||
|
@ -173,7 +156,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $modelToTable = array();
|
||||
|
||||
/**
|
||||
* List of Foreign Key names to used tables. Used for associations.
|
||||
*
|
||||
|
@ -181,7 +163,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $keyToTable = array();
|
||||
|
||||
/**
|
||||
* Alias table names for model, for use in SQL JOIN statements.
|
||||
*
|
||||
|
@ -189,7 +170,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $alias = array();
|
||||
|
||||
/**
|
||||
* Whether or not transactions for this model should be logged
|
||||
*
|
||||
|
@ -197,7 +177,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $logTransactions = false;
|
||||
|
||||
/**
|
||||
* Whether or not to enable transactions for this model (i.e. BEGIN/COMMIT/ROLLBACK)
|
||||
*
|
||||
|
@ -205,7 +184,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $transactional = false;
|
||||
|
||||
/**
|
||||
* Whether or not to cache queries for this model. This enables in-memory
|
||||
* caching only, the results are not stored beyond this execution.
|
||||
|
@ -214,7 +192,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $cacheQueries = false;
|
||||
|
||||
/**
|
||||
* belongsTo association
|
||||
*
|
||||
|
@ -222,7 +199,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $belongsTo = array();
|
||||
|
||||
/**
|
||||
* hasOne association
|
||||
*
|
||||
|
@ -230,7 +206,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $hasOne = array();
|
||||
|
||||
/**
|
||||
* hasMany association
|
||||
*
|
||||
|
@ -238,7 +213,6 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $hasMany = array();
|
||||
|
||||
/**
|
||||
* hasAndBelongsToMany association
|
||||
*
|
||||
|
@ -246,14 +220,12 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $hasAndBelongsToMany = array();
|
||||
|
||||
/**
|
||||
* List of behaviors to use
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $actsAs = null;
|
||||
|
||||
/**
|
||||
* Behavior objects
|
||||
*
|
||||
|
@ -266,7 +238,6 @@ class Model extends Overloadable {
|
|||
* @var boolean
|
||||
*/
|
||||
var $cacheSources = true;
|
||||
|
||||
/**
|
||||
* Mapped behavior methods
|
||||
*
|
||||
|
@ -274,7 +245,6 @@ class Model extends Overloadable {
|
|||
* @access private
|
||||
*/
|
||||
var $__behaviorMethods = array();
|
||||
|
||||
/**
|
||||
* Depth of recursive association
|
||||
*
|
||||
|
@ -282,14 +252,12 @@ class Model extends Overloadable {
|
|||
* @access public
|
||||
*/
|
||||
var $recursive = 1;
|
||||
|
||||
/**
|
||||
* Default ordering of model records
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
var $order = null;
|
||||
|
||||
/**
|
||||
* Default association keys
|
||||
*
|
||||
|
@ -302,7 +270,6 @@ class Model extends Overloadable {
|
|||
'hasMany' => array('className', 'foreignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'dependent', 'exclusive', 'finderQuery', 'counterQuery'),
|
||||
'hasAndBelongsToMany' => array('className', 'joinTable', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery')
|
||||
);
|
||||
|
||||
/**
|
||||
* Holds provided/generated association key names and other data for all associations
|
||||
*
|
||||
|
@ -310,7 +277,6 @@ class Model extends Overloadable {
|
|||
* @access protected
|
||||
*/
|
||||
var $__associations = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
|
||||
/**
|
||||
* Holds model associations temporarily to allow for dynamic (un)binding
|
||||
*
|
||||
|
@ -318,7 +284,6 @@ class Model extends Overloadable {
|
|||
* @access private
|
||||
*/
|
||||
var $__backAssociation = array();
|
||||
|
||||
/**
|
||||
* The last inserted ID of the data that this model created
|
||||
*
|
||||
|
@ -326,7 +291,6 @@ class Model extends Overloadable {
|
|||
* @access protected
|
||||
*/
|
||||
var $__insertID = null;
|
||||
|
||||
/**
|
||||
* The number of records returned by the last query
|
||||
*
|
||||
|
@ -334,7 +298,6 @@ class Model extends Overloadable {
|
|||
* @access protected
|
||||
*/
|
||||
var $__numRows = null;
|
||||
|
||||
/**
|
||||
* The number of records affected by the last query
|
||||
*
|
||||
|
@ -342,7 +305,6 @@ class Model extends Overloadable {
|
|||
* @access protected
|
||||
*/
|
||||
var $__affectedRows = null;
|
||||
|
||||
/**
|
||||
* Constructor. Binds the Model's database table to the object.
|
||||
*
|
||||
|
@ -952,7 +914,6 @@ class Model extends Overloadable {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns contents of a field in a query matching given conditions.
|
||||
*
|
||||
|
@ -990,7 +951,6 @@ class Model extends Overloadable {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a single field to the database.
|
||||
*
|
||||
|
@ -1002,7 +962,6 @@ class Model extends Overloadable {
|
|||
function saveField($name, $value, $validate = false) {
|
||||
return $this->save(array($this->name => array($name => $value)), $validate, array($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves model data to the database.
|
||||
* By default, validation occurs before save.
|
||||
|
@ -2138,9 +2097,7 @@ class Model extends Overloadable {
|
|||
function __wakeup() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
||||
Overloadable::overload('Model');
|
||||
}
|
||||
|
||||
?>
|
|
@ -186,9 +186,9 @@ class NumberTreeCase extends CakeTestCase {
|
|||
$this->NumberTree = & new NumberTree();
|
||||
$this->NumberTree->__initialize(2, 2);
|
||||
|
||||
$this->NumberTree->save(array('NumberTree' => array('name' => __METHOD__,'parent_id' => null)));
|
||||
$this->NumberTree->save(array('NumberTree' => array('name' => 'testAddOrphan', 'parent_id' => null)));
|
||||
$result = $this->NumberTree->find(null, array('name', 'parent_id'), 'NumberTree.lft desc');
|
||||
$expected = array('NumberTree' => array('name' => __METHOD__, 'parent_id' => null));
|
||||
$expected = array('NumberTree' => array('name' => 'testAddOrphan', 'parent_id' => null));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$validTree = $this->NumberTree->verify();
|
||||
|
@ -203,7 +203,7 @@ class NumberTreeCase extends CakeTestCase {
|
|||
$initialCount = $this->NumberTree->findCount();
|
||||
|
||||
$this->NumberTree->create();
|
||||
$saveSuccess = $this->NumberTree->save(array('NumberTree' => array('name' => __METHOD__, 'parent_id' => $data['NumberTree']['id'])));
|
||||
$saveSuccess = $this->NumberTree->save(array('NumberTree' => array('name' => 'testAddMiddle', 'parent_id' => $data['NumberTree']['id'])));
|
||||
$this->assertIdentical($saveSuccess, true);
|
||||
|
||||
$laterCount = $this->NumberTree->findCount();
|
||||
|
@ -214,7 +214,7 @@ class NumberTreeCase extends CakeTestCase {
|
|||
$children = $this->NumberTree->children($data['NumberTree']['id'], true, array('name'));
|
||||
$expects = array(array('NumberTree' => array('name' => '1.1.1')),
|
||||
array('NumberTree' => array('name' => '1.1.2')),
|
||||
array('NumberTree' => array('name' => __METHOD__)));
|
||||
array('NumberTree' => array('name' => 'testAddMiddle')));
|
||||
$this->assertIdentical($children, $expects);
|
||||
|
||||
$validTree = $this->NumberTree->verify();
|
||||
|
@ -229,7 +229,7 @@ class NumberTreeCase extends CakeTestCase {
|
|||
$initialCount = $this->NumberTree->findCount();
|
||||
$this->expectError('Trying to save a node under a none-existant node in TreeBehavior::beforeSave');
|
||||
|
||||
$saveSuccess = $this->NumberTree->save(array('NumberTree' => array('name' => __METHOD__, 'parent_id' => 99999)));
|
||||
$saveSuccess = $this->NumberTree->save(array('NumberTree' => array('name' => 'testAddInvalid', 'parent_id' => 99999)));
|
||||
$this->assertIdentical($saveSuccess, false);
|
||||
|
||||
$laterCount = $this->NumberTree->findCount();
|
||||
|
|
Loading…
Reference in a new issue