- * require_once('dbo_mysql.php'); // or 'dbo_postgres.php'
+ * require('dbo_mysql.php'); // or 'dbo_postgres.php'
*
* // create and connect the object
* $db = new DBO_MySQL(array( // or 'DBO_Postgres'
diff --git a/cake/libs/model/dbo/dbo_mysql.php b/cake/libs/model/dbo/dbo_mysql.php
index 402709180..496de8d80 100644
--- a/cake/libs/model/dbo/dbo_mysql.php
+++ b/cake/libs/model/dbo/dbo_mysql.php
@@ -283,14 +283,8 @@ class DboMysql extends DboSource
{
$data = stripslashes($data);
}
- if (version_compare(phpversion(),"4.3.0") == "-1")
- {
- $data = mysql_escape_string($data, $this->connection);
- }
- else
- {
- $data = mysql_real_escape_string($data, $this->connection);
- }
+ $data = mysql_real_escape_string($data, $this->connection);
+
if(!is_numeric($data))
{
$return = "'" . $data . "'";
diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php
index f4b0bf4e1..b43464e5e 100644
--- a/cake/libs/model/model.php
+++ b/cake/libs/model/model.php
@@ -35,7 +35,7 @@
*/
if (phpversion() < 5)
{
- require_once(LIBS.'model'.DS.'model_php4.php');
+ require(LIBS.'model'.DS.'model_php4.php');
if (function_exists("overload"))
{
overload("Model");
@@ -43,6 +43,6 @@ if (phpversion() < 5)
}
else
{
- require_once(LIBS.'model'.DS.'model_php5.php');
+ require(LIBS.'model'.DS.'model_php5.php');
}
?>
\ No newline at end of file
diff --git a/cake/libs/model/model_php4.php b/cake/libs/model/model_php4.php
index a7052294f..0ce5fef0a 100644
--- a/cake/libs/model/model_php4.php
+++ b/cake/libs/model/model_php4.php
@@ -6,7 +6,7 @@
*
* DBO-backed object data model, for mapping database tables to Cake objects.
*
- * PHP versions 4 and 5
+ * PHP versions 4
*
* CakePHP : Rapid Development Framework
* Copyright (c) 2006, Cake Software Foundation, Inc.
@@ -77,7 +77,7 @@ class Model extends Object
var $parent = false;
/**
- * Custom database table name
+ * Custom database table name.
*
* @var string
* @access public
@@ -85,7 +85,7 @@ class Model extends Object
var $useTable = null;
/**
- * Custom display field name
+ * Custom display field name. Display fields are used by Scaffold, in SELECT boxes' OPTION elements.
*
* @var string
* @access public
@@ -147,7 +147,7 @@ class Model extends Object
var $validationErrors = null;
/**
- * Prefix for tables in model.
+ * Database table prefix for tables in model.
*
* @var string
*/
@@ -161,7 +161,7 @@ class Model extends Object
var $name = null;
/**
- * Name of the model.
+ * Name of the current model.
*
* @var string
*/
@@ -182,7 +182,7 @@ class Model extends Object
var $modelToTable = array();
/**
- * List of Foreign Key names to table used tables. Used for associations.
+ * List of Foreign Key names to used tables. Used for associations.
*
* @var array
*/
@@ -203,7 +203,7 @@ class Model extends Object
var $logTransactions = false;
/**
- * Whether or not to enable transactions for this model (i.e. begin/commit/rollback)
+ * Whether or not to enable transactions for this model (i.e. BEGIN/COMMIT/ROLLBACK)
*
* @var boolean
*/
@@ -238,7 +238,7 @@ class Model extends Object
var $hasAndBelongsToMany = array();
/**
- * recursive assoication depth
+ * Depth of recursive association
*
* @var int
*/
@@ -290,8 +290,8 @@ class Model extends Object
* Constructor. Binds the Model's database table to the object.
*
* @param integer $id
- * @param string $table Database table to use.
- * @param unknown_type $ds DataSource connection object.
+ * @param string $table Name of database table to use.
+ * @param DataSource $ds DataSource connection object.
*/
function __construct ($id=false, $table=null, $ds=null)
{
@@ -428,6 +428,7 @@ class Model extends Object
* @param string $assoc
* @param string $className Class name
* @param string $type Type of assocation
+ * @todo Is the third parameter in use at the moment? It is not referred to in the method OJ, 30. jan 2006
* @access private
*/
function __constructLinkedModel($assoc, $className, $type)
@@ -435,7 +436,7 @@ class Model extends Object
$colKey = Inflector::underscore($className);
if(ClassRegistry::isKeySet($colKey))
{
- $this->{$className} =& ClassRegistry::getObject($colKey);
+ $this->{$className} =& ClassRegistry::getObject($colKey);
}
else
{
@@ -448,11 +449,11 @@ class Model extends Object
}
/**
- * Build array-based association from string
+ * Build array-based association from string.
*
* @param string $type "Belongs", "One", "Many", "ManyTo"
* @param string $assoc
- * @param string $model
+ * @todo Is the second parameter in use at the moment? It is not referred to in the method OJ, 30. jan 2006
* @access private
*/
function __generateAssociation ($type, $assoc)
@@ -604,10 +605,9 @@ class Model extends Object
}
/**
- * Returns true if given field name exists in this Model's database table.
- * Starts by loading the metadata into the private property table_info if that is not already set.
+ * Returns true if this Model has given field in its database table.
*
- * @param string $name Name of table to look in
+ * @param string $name Name of field to look for
* @return boolean
*/
function hasField ($name)
@@ -624,9 +624,9 @@ class Model extends Object
}
/**
- * Initializes the model for writing a new record
+ * Initializes the model for writing a new record.
*
- * @return boolean True on success
+ * @return boolean True
*/
function create ()
{
@@ -646,7 +646,7 @@ class Model extends Object
}
/**
- * Deprecated
+ * Deprecated. Use query() instead.
*
*/
function findBySql ($sql)
@@ -691,8 +691,8 @@ class Model extends Object
* Returns contents of a field in a query matching given conditions.
*
* @param string $name Name of field to get
- * @param string $conditions SQL conditions (defaults to NULL)
- * @param string $order (defaults to NULL)
+ * @param array $conditions SQL conditions (defaults to NULL)
+ * @param string $order SQL ORDER BY fragment
* @return field contents
*/
function field ($name, $conditions = null, $order = null)
@@ -739,14 +739,14 @@ class Model extends Object
/**
* Saves model data to the database.
+ * By default, validation occurs before save.
*
* @param array $data Data to save.
- * @param boolean $validate
- * @param array $fields
+ * @param boolean $validate If set, validation will be done before the save
+ * @param array $fieldList List of fields to allow to be written
* @return boolean success
- * @todo Implement $fields param as a whitelist of allowable fields
*/
- function save ($data = null, $validate = true, $fields = null)
+ function save ($data = null, $validate = true, $fieldList = array())
{
if ($data)
{
@@ -760,122 +760,123 @@ class Model extends Object
}
}
- if($this->beforeSave())
+ $whitelist = !(empty($fieldList) || count($fieldList) == 0);
+
+ if ($validate && !$this->validates())
{
- if ($validate && !$this->validates())
+ return false;
+ }
+
+ if(!$this->beforeSave())
+ {
+ return false;
+ }
+
+ $fields = $values = array();
+ $count = 0;
+
+ if(count($this->data) > 1)
+ {
+ $weHaveMulti = true;
+ $joined = false;
+ }
+ else
+ {
+ $weHaveMulti = false;
+ }
+
+ foreach ($this->data as $n => $v)
+ {
+ if(isset($weHaveMulti) && $count > 0 && count($this->hasAndBelongsToMany) > 0)
{
- return false;
+ $joined[] = $v;
}
- $fields = $values = array();
- $count = 0;
+ else
+ {
+ foreach ($v as $x => $y)
+ {
+ if ($this->hasField($x) && ($whitelist && in_array($x, $fieldList) || !$whitelist))
+ {
+ $fields[] = $x;
+ $values[] = $y;
- if(count($this->data) > 1)
- {
- $weHaveMulti = true;
- $joined = false;
- }
- else
- {
- $weHaveMulti = false;
- }
+ if($x == $this->primaryKey && !is_numeric($y))
+ {
+ $newID = $y;
+ }
+ }
+ }
+ $count++;
+ }
+ }
- foreach ($this->data as $n => $v)
- {
- if(isset($weHaveMulti) && $count > 0 && count($this->hasAndBelongsToMany) > 0)
- {
- $joined[] = $v;
- }
- else
- {
- foreach ($v as $x => $y)
- {
- if ($this->hasField($x))
- {
- $fields[] = $x;
- $values[] = $y;
+ if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields) && ($whitelist && in_array('created', $fieldList) || !$whitelist))
+ {
+ $fields[] = 'created';
+ $values[] = date('Y-m-d H:i:s');
+ }
+ if ($this->hasField('modified') && !in_array('modified', $fields) && ($whitelist && in_array('modified', $fieldList) || !$whitelist))
+ {
+ $fields[] = 'modified';
+ $values[] = date('Y-m-d H:i:s');
+ }
+ if ($this->hasField('updated') && !in_array('updated', $fields) && ($whitelist && in_array('updated', $fieldList) || !$whitelist))
+ {
+ $fields[] = 'updated';
+ $values[] = date('Y-m-d H:i:s');
+ }
- if($x == $this->primaryKey && !is_numeric($y))
- {
- $newID = $y;
- }
- }
- }
- $count++;
- }
- }
+ if(!$this->exists())
+ {
+ $this->id = false;
+ }
- if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields))
- {
- $fields[] = 'created';
- $values[] = date('Y-m-d H:i:s');
- }
- if ($this->hasField('modified') && !in_array('modified', $fields))
- {
- $fields[] = 'modified';
- $values[] = date('Y-m-d H:i:s');
- }
- if ($this->hasField('updated') && !in_array('updated', $fields))
- {
- $fields[] = 'updated';
- $values[] = date('Y-m-d H:i:s');
- }
+ if(count($fields))
+ {
+ if(!empty($this->id))
+ {
+ if ($this->db->update($this, $fields, $values))
+ {
+ if(!empty($joined))
+ {
+ $this->__saveMulti($joined, $this->id);
+ }
+ $this->afterSave();
+ $this->data = false;
+ return true;
+ }
+ else
+ {
+ return $this->hasAny($this->escapeField($this->primaryKey).' = '.$this->db->value($this->id));
+ }
+ }
+ else
+ {
+ if($this->db->create($this, $fields, $values))
+ {
+ $this->__insertID = $this->db->lastInsertId($this->table, $this->primaryKey);
+ $this->id = $this->__insertID;
- if(!$this->exists())
- {
- $this->id = false;
- }
+ if(!$this->id > 0 && isset($newID))
+ {
+ $this->__insertID = $newID;
+ $this->id = $newID;
+ }
- if(count($fields))
- {
- if(!empty($this->id))
- {
- if ($this->db->update($this, $fields, $values))
- {
- if(!empty($joined))
- {
- $this->__saveMulti($joined, $this->id);
- }
- $this->afterSave();
- $this->data = false;
- return true;
- }
- else
- {
- return $this->hasAny($this->escapeField($this->primaryKey).' = '.$this->db->value($this->id));
- }
- }
- else
- {
- if($this->db->create($this, $fields, $values))
- {
- $this->__insertID = $this->db->lastInsertId($this->table, $this->primaryKey);
- $this->id = $this->__insertID;
+ if(!empty($joined))
+ {
+ $this->__saveMulti($joined, $this->id);
+ }
- if(!$this->id > 0 && isset($newID))
- {
- $this->__insertID = $newID;
- $this->id = $newID;
- }
-
- if(!empty($joined))
- {
- $this->__saveMulti($joined, $this->id);
- }
-
- $this->afterSave();
- $this->data = false;
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- else
- {
- return false;
- }
+ $this->afterSave();
+ $this->data = false;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
}
else
{
@@ -949,10 +950,10 @@ class Model extends Object
/**
* Removes record for given id. If no id is given, the current id is used. Returns true on success.
*
- * @param mixed $id Id of database record to delete
+ * @param mixed $id Id of record to delete
* @return boolean True on success
*/
- function del ($id = null)
+ function del ($id = null, $cascade = false)
{
if ($id)
{
@@ -963,6 +964,11 @@ class Model extends Object
{
if ($this->id && $this->db->delete($this))
{
+ //$this->__deleteJoins($id);
+ if ($cascade)
+ {
+ //$this->__deleteMulti($id);
+ }
$this->afterDelete();
$this->id = false;
return true;
@@ -972,6 +978,42 @@ class Model extends Object
return false;
}
+/**
+ * Cascades model deletes to hasMany relationships.
+ *
+ * @param string $id
+ * @return null
+ * @access private
+ */
+ function __deleteMulti ($id)
+ {
+ foreach ($this->hasMany as $assoc => $data)
+ {
+ $model =& $this->{$data['className']};
+ $field = $model->escapeField($data['foreignKey']);
+ $records = $model->findAll($field.'='.$id);
+
+ foreach($records as $record)
+ {
+
+ }
+ }
+ }
+
+/**
+ * Cascades model deletes to HABTM join keys.
+ *
+ * @param string $id
+ * @return null
+ * @access private
+ */
+ function __deleteJoins ($id)
+ {
+ foreach ($this->hasAndBelongsToMany as $assoc => $data)
+ {
+ }
+ }
+
/**
* Returns true if a record with set id exists.
*
@@ -994,6 +1036,7 @@ class Model extends Object
/**
* Returns true if a record that meets given conditions exists
*
+ * @param array $conditions SQL conditions array
* @return boolean True if such a record exists
*/
function hasAny ($conditions = null)
@@ -1003,11 +1046,13 @@ class Model extends Object
/**
* Return a single row as a resultset array.
+ * By using the $recursive parameter, the call can access further "levels of association" than
+ * the ones this model is directly associated to.
*
- * @param string $conditions SQL conditions
+ * @param array $conditions SQL conditions array
* @param mixed $fields Either a single string of a field name, or an array of field names
* @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC")
- * @param int $recursize The number of levels deep to fetch associated records
+ * @param int $recursive The number of levels deep to fetch associated records
* @return array Array of records
*/
function find ($conditions = null, $fields = null, $order = null, $recursive = null)
@@ -1022,13 +1067,15 @@ class Model extends Object
/**
* Returns a resultset array with specified fields from database matching given conditions.
+ * By using the $recursive parameter, the call can access further "levels of association" than
+ * the ones this model is directly associated to.
*
* @param mixed $conditions SQL conditions as a string or as an array('field'=>'value',...)
* @param mixed $fields Either a single string of a field name, or an array of field names
* @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC")
- * @param int $limit SQL LIMIT clause, for calculating items per page
- * @param int $page Page number
- * @param int $recursize The number of levels deep to fetch associated records
+ * @param int $limit SQL LIMIT clause, for calculating items per page.
+ * @param int $page Page number, for accessing paged data
+ * @param int $recursive The number of levels deep to fetch associated records
* @return array Array of records
*/
function findAll ($conditions = null, $fields = null, $order = null, $limit = 50, $page = 1, $recursive = null)
@@ -1061,7 +1108,7 @@ class Model extends Object
}
/**
- * Runs a direct query against the bound DataSource, and returns the result
+ * Runs a direct query against the bound DataSource, and returns the result.
*
* @param string $data Query data
* @return array
@@ -1089,9 +1136,10 @@ class Model extends Object
/**
* Returns number of rows matching given SQL condition.
*
- * @param string $conditions SQL conditions (WHERE clause conditions)
+ * @param array $conditions SQL conditions array for findAll
* @param int $recursize The number of levels deep to fetch associated records
* @return int Number of matching rows
+ * @see Model::findAll
*/
function findCount ($conditions = null, $recursive = 0)
{
@@ -1105,12 +1153,12 @@ class Model extends Object
/**
* Special findAll variation for tables joined to themselves.
- * The table needs fields id and parent_id to work.
+ * The table needs the fields id and parent_id to work.
*
* @param array $conditions Conditions for the findAll() call
* @param array $fields Fields for the findAll() call
* @param string $sort SQL ORDER BY statement
- * @return unknown
+ * @return array
* @todo Perhaps create a Component with this logic
*/
function findAllThreaded ($conditions=null, $fields=null, $sort=null)
@@ -1125,6 +1173,7 @@ class Model extends Object
* @param string $root NULL or id for root node of operation
* @return array
* @access private
+ * @see findAllThreaded
*/
function __doThread ($data, $root)
{
@@ -1154,7 +1203,7 @@ class Model extends Object
* which is useful when creating paged lists.
*
* @param string $conditions SQL conditions for matching rows
- * @param unknown_type $field
+ * @param string $field Field name (parameter for findAll)
* @param unknown_type $value
* @return array Array with keys "prev" and "next" that holds the id's
*/
@@ -1179,7 +1228,7 @@ class Model extends Object
}
/**
- * Returns a resultset for given SQL statement.
+ * Returns a resultset for given SQL statement. Generic SQL queries should be made with this method.
*
* @param string $sql SQL statement
* @return array Resultset
@@ -1191,7 +1240,7 @@ class Model extends Object
}
/**
- * Returns true if all fields pass validation.
+ * Returns true if all fields pass validation, otherwise false.
*
* @param array $data POST data
* @return boolean True if there are no errors
@@ -1254,7 +1303,7 @@ class Model extends Object
}
/**
- * This function determines whether or not a string is a foreign key
+ * Returns true if given field name is a foreign key in this Model.
*
* @param string $field Returns true if the input string ends in "_id"
* @return True if the field is a foreign key listed in the belongsTo array.
@@ -1284,7 +1333,7 @@ class Model extends Object
}
/**
- * Returns a resultset array with specified fields from database matching given conditions.
+ * Returns a resultset array with specified fields from database matching given conditions. Method can be used to generate option lists for SELECT elements.
*
* @param mixed $conditions SQL conditions as a string or as an array('field'=>'value',...)
* @param mixed $fields Either a single string of a field name, or an array of field names
@@ -1313,7 +1362,7 @@ class Model extends Object
}
/**
- * Escapes the field name and prepends the model name
+ * Escapes the field name and prepends the model name. Escaping will be done according to the current database driver's rules.
*
* @param unknown_type $field
* @return string The name of the escaped field for this Model (i.e. id becomes `Post`.`id`).
@@ -1350,7 +1399,7 @@ class Model extends Object
}
/**
- * Gets the ID of the last record this Model inserted
+ * Returns the ID of the last record this Model inserted
*
* @return mixed
*/
@@ -1360,7 +1409,7 @@ class Model extends Object
}
/**
- * Gets the ID of the last record this Model inserted
+ * Returns the ID of the last record this Model inserted
*
* @return mixed
*/
@@ -1370,7 +1419,7 @@ class Model extends Object
}
/**
- * Gets the number of rows returned from the last query
+ * Returns the number of rows returned from the last query
*
* @return int
*/
@@ -1381,7 +1430,7 @@ class Model extends Object
}
/**
- * Gets the number of rows affected by the last query
+ * Returns the number of rows affected by the last query
*
* @return int
*/
@@ -1409,7 +1458,6 @@ class Model extends Object
{
$this->tablePrefix = $this->db->config['prefix'];
}
-
if(empty($this->db) || $this->db == null || !is_object($this->db))
{
return $this->cakeError('missingConnection',array(array('className' => $this->name)));
@@ -1428,7 +1476,7 @@ class Model extends Object
}
/**
- * After find callback
+ * After find callback. Can be used to modify any results returned by find and findAll.
*
* @param mixed $results The results of the find operation
* @return mixed Result of the find operation
diff --git a/cake/libs/model/model_php5.php b/cake/libs/model/model_php5.php
index 2ab5703d4..767bb79c9 100644
--- a/cake/libs/model/model_php5.php
+++ b/cake/libs/model/model_php5.php
@@ -6,7 +6,7 @@
*
* DBO-backed object data model, for mapping database tables to Cake objects.
*
- * PHP versions 4 and 5
+ * PHP versions 5
*
* CakePHP : Rapid Development Framework
* Copyright (c) 2006, Cake Software Foundation, Inc.
@@ -739,11 +739,10 @@ class Model extends Object
*
* @param array $data Data to save.
* @param boolean $validate If set, validation will be done before the save
- * @param array $fields
+ * @param array $fieldList List of fields to allow to be written
* @return boolean success
- * @todo Implement $fields param as a whitelist of allowable fields
*/
- function save ($data = null, $validate = true, $fields = null)
+ function save ($data = null, $validate = true, $fieldList = array())
{
if ($data)
{
@@ -756,122 +755,124 @@ class Model extends Object
$this->set($data);
}
}
- if($this->beforeSave())
+
+ $whitelist = !(empty($fieldList) || count($fieldList) == 0);
+
+ if ($validate && !$this->validates())
{
- if ($validate && !$this->validates())
+ return false;
+ }
+
+ if(!$this->beforeSave())
+ {
+ return false;
+ }
+
+ $fields = $values = array();
+ $count = 0;
+
+ if(count($this->data) > 1)
+ {
+ $weHaveMulti = true;
+ $joined = false;
+ }
+ else
+ {
+ $weHaveMulti = false;
+ }
+
+ foreach ($this->data as $n => $v)
+ {
+ if(isset($weHaveMulti) && $count > 0 && count($this->hasAndBelongsToMany) > 0)
{
- return false;
+ $joined[] = $v;
}
- $fields = $values = array();
- $count = 0;
+ else
+ {
+ foreach ($v as $x => $y)
+ {
+ if ($this->hasField($x) && ($whitelist && in_array($x, $fieldList) || !$whitelist))
+ {
+ $fields[] = $x;
+ $values[] = $y;
- if(count($this->data) > 1)
- {
- $weHaveMulti = true;
- $joined = false;
- }
- else
- {
- $weHaveMulti = false;
- }
+ if($x == $this->primaryKey && !is_numeric($y))
+ {
+ $newID = $y;
+ }
+ }
+ }
+ $count++;
+ }
+ }
- foreach ($this->data as $n => $v)
- {
- if(isset($weHaveMulti) && $count > 0 && count($this->hasAndBelongsToMany) > 0)
- {
- $joined[] = $v;
- }
- else
- {
- foreach ($v as $x => $y)
- {
- if ($this->hasField($x))
- {
- $fields[] = $x;
- $values[] = $y;
+ if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields) && ($whitelist && in_array('created', $fieldList) || !$whitelist))
+ {
+ $fields[] = 'created';
+ $values[] = date('Y-m-d H:i:s');
+ }
+ if ($this->hasField('modified') && !in_array('modified', $fields) && ($whitelist && in_array('modified', $fieldList) || !$whitelist))
+ {
+ $fields[] = 'modified';
+ $values[] = date('Y-m-d H:i:s');
+ }
+ if ($this->hasField('updated') && !in_array('updated', $fields) && ($whitelist && in_array('updated', $fieldList) || !$whitelist))
+ {
+ $fields[] = 'updated';
+ $values[] = date('Y-m-d H:i:s');
+ }
- if($x == $this->primaryKey && !is_numeric($y))
- {
- $newID = $y;
- }
- }
- }
- $count++;
- }
- }
+ if(!$this->exists())
+ {
+ $this->id = false;
+ }
- if (empty($this->id) && $this->hasField('created') && !in_array('created', $fields))
- {
- $fields[] = 'created';
- $values[] = date('Y-m-d H:i:s');
- }
- if ($this->hasField('modified') && !in_array('modified', $fields))
- {
- $fields[] = 'modified';
- $values[] = date('Y-m-d H:i:s');
- }
- if ($this->hasField('updated') && !in_array('updated', $fields))
- {
- $fields[] = 'updated';
- $values[] = date('Y-m-d H:i:s');
- }
+ if(count($fields))
+ {
+ if(!empty($this->id))
+ {
+ if ($this->db->update($this, $fields, $values))
+ {
+ if(!empty($joined))
+ {
+ $this->__saveMulti($joined, $this->id);
+ }
+ $this->afterSave();
+ $this->data = false;
+ return true;
+ }
+ else
+ {
+ return $this->hasAny($this->escapeField($this->primaryKey).' = '.$this->db->value($this->id));
+ }
+ }
+ else
+ {
+ if($this->db->create($this, $fields, $values))
+ {
+ $this->__insertID = $this->db->lastInsertId($this->table, $this->primaryKey);
+ $this->id = $this->__insertID;
- if(!$this->exists())
- {
- $this->id = false;
- }
+ if(!$this->id > 0 && isset($newID))
+ {
+ $this->__insertID = $newID;
+ $this->id = $newID;
+ }
- if(count($fields))
- {
- if(!empty($this->id))
- {
- if ($this->db->update($this, $fields, $values))
- {
- if(!empty($joined))
- {
- $this->__saveMulti($joined, $this->id);
- }
- $this->afterSave();
- $this->data = false;
- return true;
- }
- else
- {
- return $this->hasAny($this->escapeField($this->primaryKey).' = '.$this->db->value($this->id));
- }
- }
- else
- {
- if($this->db->create($this, $fields, $values))
- {
- $this->__insertID = $this->db->lastInsertId($this->table, $this->primaryKey);
- $this->id = $this->__insertID;
+ if(!empty($joined))
+ {
+ $this->__saveMulti($joined, $this->id);
+ }
- if(!$this->id > 0 && isset($newID))
- {
- $this->__insertID = $newID;
- $this->id = $newID;
- }
-
- if(!empty($joined))
- {
- $this->__saveMulti($joined, $this->id);
- }
-
- $this->afterSave();
- $this->data = false;
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- else
- {
- return false;
- }
+ $this->afterSave();
+ $this->data = false;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
}
else
{
@@ -948,7 +949,7 @@ class Model extends Object
* @param mixed $id Id of record to delete
* @return boolean True on success
*/
- function del ($id = null)
+ function del ($id = null, $cascade = false)
{
if ($id)
{
@@ -959,6 +960,11 @@ class Model extends Object
{
if ($this->id && $this->db->delete($this))
{
+ //$this->__deleteJoins($id);
+ if ($cascade)
+ {
+ //$this->__deleteMulti($id);
+ }
$this->afterDelete();
$this->id = false;
return true;
@@ -968,6 +974,42 @@ class Model extends Object
return false;
}
+/**
+ * Cascades model deletes to hasMany relationships.
+ *
+ * @param string $id
+ * @return null
+ * @access private
+ */
+ function __deleteMulti ($id)
+ {
+ foreach ($this->hasMany as $assoc => $data)
+ {
+ $model =& $this->{$data['className']};
+ $field = $model->escapeField($data['foreignKey']);
+ $records = $model->findAll($field.'='.$id);
+
+ foreach($records as $record)
+ {
+
+ }
+ }
+ }
+
+/**
+ * Cascades model deletes to HABTM join keys.
+ *
+ * @param string $id
+ * @return null
+ * @access private
+ */
+ function __deleteJoins ($id)
+ {
+ foreach ($this->hasAndBelongsToMany as $assoc => $data)
+ {
+ }
+ }
+
/**
* Returns true if a record with set id exists.
*
diff --git a/cake/libs/session.php b/cake/libs/session.php
index 7c61621ca..20c6d0516 100644
--- a/cake/libs/session.php
+++ b/cake/libs/session.php
@@ -129,13 +129,21 @@ class CakeSession extends Object
$this->time = time();
$this->sessionTime = $this->time + (Security::inactiveMins() * CAKE_SESSION_TIMEOUT);
$this->security = CAKE_SECURITY;
-
+ session_write_close();
+
if (!isset($_SESSION))
{
$this->_initSession();
- $this->_begin();
-
}
+
+ session_cache_limiter("must-revalidate");
+ session_start();
+
+ if (!isset($_SESSION))
+ {
+ $this->_begin();
+ }
+
$this->_checkValid();
parent::__construct();
}
@@ -274,8 +282,6 @@ class CakeSession extends Object
*/
function _begin()
{
- session_cache_limiter("must-revalidate");
- session_start();
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
}
@@ -286,10 +292,7 @@ class CakeSession extends Object
*/
function _close()
{
- echo "";
- echo "CakeSession::_close() Not Implemented Yet";
- echo "
";
- die();
+ return true;
}
/**
@@ -297,13 +300,13 @@ class CakeSession extends Object
*
* @access private
*/
- function _destroy()
+ function _destroy($key)
{
- echo "";
- echo "CakeSession::_destroy() Not Implemented Yet";
- echo "
";
- die();
+ $db =& ConnectionManager::getDataSource('default');
+ $db->execute("DELETE FROM ".$db->name('cake_sessions')." WHERE ".$db->name('id')." = ".$db->value($key));
+ return true;
}
+
/**
* Private helper method to destroy invalid sessions.
*
@@ -331,12 +334,11 @@ class CakeSession extends Object
*
* @access private
*/
- function _gc()
+ function _gc($expires)
{
- echo "";
- echo "CakeSession::_gc() Not Implemented Yet";
- echo "
";
- die();
+ $db =& ConnectionManager::getDataSource('default');
+ $db->execute("DELETE FROM ".$db->name('cake_sessions')." WHERE ".$db->name('expires')." < " . $db->value(time()));
+ return true;
}
/**
@@ -346,11 +348,6 @@ class CakeSession extends Object
*/
function _initSession()
{
- if (function_exists('session_write_close'))
- {
- session_write_close();
- }
-
switch ($this->security)
{
case 'high':
@@ -409,7 +406,7 @@ class CakeSession extends Object
$config = CONFIGS.CAKE_SESSION_SAVE.'.php';
if(is_file($config))
{
- require_once($config);
+ require($config);
}
else
{
@@ -465,10 +462,7 @@ class CakeSession extends Object
*/
function _open()
{
- echo "";
- echo "CakeSession::_open() Not Implemented Yet";
- echo "
";
- die();
+ return true;
}
/**
@@ -477,12 +471,20 @@ class CakeSession extends Object
* @access private
*
*/
- function _read()
+ function _read($key)
{
- echo "";
- echo "CakeSession::_read() Not Implemented Yet";
- echo "
";
- die();
+ $db =& ConnectionManager::getDataSource('default');
+
+ $row = $db->query("SELECT ".$db->name('data')." FROM ".$db->name('cake_sessions')." WHERE ".$db->name('id')." = ".$db->value($key));
+
+ if ($row && $row[0]['cake_sessions']['data'])
+ {
+ return $row[0]['cake_sessions']['data'];
+ }
+ else
+ {
+ return false;
+ }
}
/**
@@ -543,7 +545,7 @@ class CakeSession extends Object
{
$names = array($name);
}
- $expression = $expression = "\$_SESSION";
+ $expression = "\$_SESSION";
foreach($names as $item)
{
@@ -578,12 +580,40 @@ class CakeSession extends Object
*
* @access private
*/
- function _write()
+ function _write($key, $value)
{
- echo "";
- echo "CakeSession::_write() Not Implemented Yet";
- echo "
";
- die();
+ $db =& ConnectionManager::getDataSource('default');
+
+ switch (CAKE_SECURITY) {
+ case 'high':
+ $factor = 10;
+ break;
+ case 'medium':
+ $factor = 100;
+ break;
+ case 'low':
+ $factor = 300;
+ break;
+
+ default:
+ $factor = 10;
+ break;
+ }
+
+ $expires = time() + CAKE_SESSION_TIMEOUT * $factor;
+
+ $row = $db->query("SELECT COUNT(*) AS count FROM ".$db->name('cake_sessions')." WHERE ".$db->name('id')." = ".$db->value($key));
+
+ if($row[0][0]['count'] > 0)
+ {
+ $db->execute("UPDATE ".$db->name('cake_sessions')." SET ".$db->name('data')." = ".$db->value($value).", ".$db->name('expires')." = ".$db->name($expires)." WHERE ".$db->name('id')." = ".$db->value($key));
+ }
+ else
+ {
+ $db->execute("INSERT INTO ".$db->name('cake_sessions')." (".$db->name('data').",".$db->name('expires').",".$db->name('id').") VALUES (".$db->value($value).", ".$db->value($expires).", ".$db->value($key).")");
+ }
+
+ return true;
}
}
?>
\ No newline at end of file
diff --git a/cake/libs/view/helpers/ajax.php b/cake/libs/view/helpers/ajax.php
index 6df22b58c..caa5bdb75 100644
--- a/cake/libs/view/helpers/ajax.php
+++ b/cake/libs/view/helpers/ajax.php
@@ -189,7 +189,7 @@ class AjaxHelper extends Helper
if (isset($options['id']))
{
$htmlOptions['onclick'] = ' return false;';
- return $this->Html->link($title, $href, $htmlOptions) . $this->Javascript->event("$('{$options['id']}')", "click", "function() {" . $this->remoteFunction($options) . "; return true; }");
+ return $this->Html->link($title, $href, $htmlOptions) . $this->Javascript->event("$('{$options['id']}')", "click", $this->remoteFunction($options));
}
else
{
@@ -208,7 +208,7 @@ class AjaxHelper extends Helper
}
if (isset($html_options['id']))
{
- return $this->Html->link($title, $href, $html_options) . $this->Javascript->event("$('{$html_options['id']}')", "click", "function() {" . $this->remoteFunction($options) . "; return true; }");
+ return $this->Html->link($title, $href, $html_options) . $this->Javascript->event("$('{$html_options['id']}')", "click", $this->remoteFunction($options));
}
else
{
@@ -322,7 +322,7 @@ class AjaxHelper extends Helper
}
$options['url'] = $action;
- return $this->Html->formTag($htmlOptions['action'], $type, $htmlOptions) . $this->Javascript->event("$('".$htmlOptions['id']."')", "submit", "function(){" . $this->remoteFunction($options) . ";}");
+ return $this->Html->formTag($htmlOptions['action'], $type, $htmlOptions) . $this->Javascript->event("$('".$htmlOptions['id']."')", "submit", $this->remoteFunction($options));
}
/**
@@ -331,25 +331,32 @@ class AjaxHelper extends Helper
* Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular
* reloading POST arrangement. options argument is the same as in form_remote_tag
*
- * @param string $name Input button name
- * @param string $value Input button value
+ * @param string $title Input button title
* @param array $options Callback options
* @return string Ajaxed input button
*/
- function submit ($name, $value, $options = array())
+ function submit ($title = 'Submit', $options = array())
{
$htmlOptions = $this->__getHtmlOptions($options);
- $htmlOptions['type'] = 'button';
- $htmlOptions['name'] = $name;
- $htmlOptions['value'] = $value;
+ if (!isset($htmlOptions['type']))
+ {
+ $htmlOptions['type'] = 'submit';
+ }
+ $htmlOptions['value'] = $title;
if (!isset($options['with']))
{
- $options['with'] = 'Form.serialize(this.form)';
+ $options['with'] = 'Form.serialize(Event.element(event).form)';
}
- $htmlOptions['onclick'] = $this->remoteFunction($options) . "; return false;";
- return $this->Html->tag('input', $htmlOptions);
+ if(!isset($htmlOptions['id']))
+ {
+ $htmlOptions['id'] = 'submit'.intval(rand());
+ }
+
+ $htmlOptions['onclick'] = "return false;";
+ return $this->Html->submit($title, $htmlOptions) .
+ $this->Javascript->event('$("'.$htmlOptions['id'].'")', 'click', $this->remoteFunction($options));
}
/**
@@ -558,7 +565,7 @@ class AjaxHelper extends Helper
}
if (isset($options['callback']))
{
- $options['callback'] = 'function(form) {'.$options['callback'].'}';
+ $options['callback'] = 'function(form, value) {'.$options['callback'].'}';
}
$options = $this->_optionsToString($options, array('okText', 'cancelText', 'savingText', 'formId', 'externalControl', 'highlightcolor', 'highlightendcolor', 'savingClassName', 'formClassName', 'loadTextURL', 'loadingText'));
@@ -597,7 +604,7 @@ class AjaxHelper extends Helper
}
/**
- * Private helper function for Javascript.
+ * Private helper function for Javascript.
*
*/
function __optionsForAjax ($options = array())
diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php
index 028713465..53beddb48 100644
--- a/cake/libs/view/helpers/html.php
+++ b/cake/libs/view/helpers/html.php
@@ -255,7 +255,7 @@ class HtmlHelper extends Helper
{
$this->setFormTag($fieldName);
- if (empty($htmlAttributes['value']))
+ if (!isset($htmlAttributes['value']))
{
$htmlAttributes['value'] = $this->tagValue($fieldName);
}
@@ -502,7 +502,7 @@ class HtmlHelper extends Helper
$opt_value==$value? $options_here['checked'] = 'checked': null;
$parsed_options = $this->parseHtmlOptions(array_merge($htmlAttributes, $options_here), null, '', ' ');
$individual_tag_name = "{$this->field}_{$opt_value}";
- $out[] = sprintf($this->tags['radio'], $individual_tag_name, $this->model, $this->field, $individual_tag_name, $parsed_options, $opt_title);
+ $out[] = sprintf($this->tags['radio'], $this->model, $this->field, $individual_tag_name, $parsed_options, $opt_title);
}
$out = join($inbetween, $out);
@@ -1403,7 +1403,7 @@ class HtmlHelper extends Helper
$mins[$minCount] = sprintf('%02d', $minCount);
}
- $option = $this->selectTag($tagName.'_min', $mins, $minValue, $select_attr,
+ $option = $this->selectTag($tagName.'_min', $mins, $minValue, $select_attr,
$optionAttr);
return $option;
}
diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php
index c4527f287..822115d99 100644
--- a/cake/libs/view/helpers/javascript.php
+++ b/cake/libs/view/helpers/javascript.php
@@ -136,7 +136,7 @@ class JavascriptHelper extends Helper
$useCapture = "false";
}
- $b = "Event.observe($object, '$event', $observer, $useCapture);";
+ $b = "Event.observe($object, '$event', function(event){ $observer }, $useCapture);";
if($this->_cacheEvents === true)
{
$this->_cachedEvents[] = $b;
diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php
index 7fc7df9a2..33eda1e3f 100644
--- a/cake/libs/view/helpers/text.php
+++ b/cake/libs/view/helpers/text.php
@@ -32,11 +32,14 @@
* Included libraries.
*
*/
-if(!class_exists('Flay') || !class_exists('Html'))
+if(!class_exists('Flay'))
{
- uses('flay', DS.'view'.DS.'helpers'.DS.'html');
+ uses('flay');
+}
+if(!class_exists('Html'))
+{
+ uses(DS.'view'.DS.'helpers'.DS.'html');
}
-
/**
* Text helper library.
diff --git a/cake/libs/view/templates/pages/home.thtml b/cake/libs/view/templates/pages/home.thtml
index 7a0443500..29d2ea565 100644
--- a/cake/libs/view/templates/pages/home.thtml
+++ b/cake/libs/view/templates/pages/home.thtml
@@ -35,10 +35,8 @@
Cakeconnected ? ' is able to' : ' is not able to';?> connect to the database.
-Take a bite out of CakePHP Beta
-
-More content will be added...
-
+CakePHP
+
If you plan to upgrade from an older version, you may also want to read the changelog
Editing this Page
diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php
index 45a4b9ea2..2d3a4ca11 100644
--- a/cake/libs/view/view.php
+++ b/cake/libs/view/view.php
@@ -687,7 +687,7 @@ class View extends Object
}
if (is_file($helperFn))
{
- require_once $helperFn;
+ require $helperFn;
}
else
{
diff --git a/cake/scripts/acl.php b/cake/scripts/acl.php
index 214ff86ed..37656d760 100644
--- a/cake/scripts/acl.php
+++ b/cake/scripts/acl.php
@@ -51,10 +51,10 @@ define ('APP_DIR', 'app');
*
*/
define ('DEBUG', 1);
-require_once (ROOT.'cake'.DS.'basics.php');
-require_once (ROOT.'cake'.DS.'config'.DS.'paths.php');
-require_once (CONFIGS.'core.php');
-require_once (CONFIGS.'database.php');
+require (ROOT.'cake'.DS.'basics.php');
+require (ROOT.'cake'.DS.'config'.DS.'paths.php');
+require (CONFIGS.'core.php');
+require (CONFIGS.'database.php');
uses ('neat_array');
uses ('object');
uses ('session');
@@ -62,7 +62,7 @@ uses ('security');
uses ('model'.DS.'connection_manager');
uses ('model'.DS.'datasources'.DS.'dbo_source');
uses ('model'.DS.'model');
-require_once(CAKE.'app_model.php');
+require(CAKE.'app_model.php');
uses ('controller'.DS.'components'.DS.'acl');
uses ('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aclnode');
uses ('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aco');
diff --git a/index.php b/index.php
index 4f6410df3..27c4613db 100644
--- a/index.php
+++ b/index.php
@@ -48,10 +48,10 @@ if (!defined('CAKE_CORE_INCLUDE_PATH'))
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS);
-require_once 'cake'.DS.'basics.php';
-require_once 'config'.DS.'core.php';
-require_once 'cake'.DS.'config'.DS.'paths.php';
-
+require 'cake'.DS.'basics.php';
+require 'config'.DS.'core.php';
+require 'cake'.DS.'config'.DS.'paths.php';
+$bootstrap = true;
$uri = setUri();
@@ -62,7 +62,7 @@ $uri = setUri();
if ($uri === '/' || $uri === '/index.php')
{
$_GET['url'] = '/';
- require_once ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php';
+ require ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php';
}
else
{
@@ -79,6 +79,6 @@ else
$_GET['url'] = $path;
- require_once ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php';
+ require ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php';
}
?>
\ No newline at end of file