Merge branch 'master' into 2.4

Conflicts:
	lib/Cake/Model/Model.php
	lib/Cake/VERSION.txt
This commit is contained in:
mark_story 2013-04-09 22:09:56 -04:00
commit 5c83bc177d
5 changed files with 59 additions and 45 deletions

View file

@ -24,11 +24,7 @@ before_script:
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE SCHEMA test2;' -U postgres -d cakephp_test; fi" - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE SCHEMA test2;' -U postgres -d cakephp_test; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi" - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi"
- chmod -R 777 ./app/tmp - chmod -R 777 ./app/tmp
- echo "var net = require('net'); - sudo apt-get install lighttpd
var server = net.createServer();
server.listen(80, 'localhost');
console.log('TCP server listening on port 80 at localhost.');" > app/tmp/socket.js
- sudo node ./app/tmp/socket.js &
- pear channel-discover pear.cakephp.org - pear channel-discover pear.cakephp.org
- pear install --alldeps cakephp/CakePHP_CodeSniffer - pear install --alldeps cakephp/CakePHP_CodeSniffer
- phpenv rehash - phpenv rehash

View file

@ -643,11 +643,11 @@ class Model extends Object implements CakeEventListener {
* *
* If `$id` is an array it can be used to pass several options into the model. * If `$id` is an array it can be used to pass several options into the model.
* *
* - id - The id to start the model on. * - `id`: The id to start the model on.
* - table - The table to use for this model. * - `table`: The table to use for this model.
* - ds - The connection name this model is connected to. * - `ds`: The connection name this model is connected to.
* - name - The name of the model eg. Post. * - `name`: The name of the model eg. Post.
* - alias - The alias of the model, this is used for registering the instance in the `ClassRegistry`. * - `alias`: The alias of the model, this is used for registering the instance in the `ClassRegistry`.
* eg. `ParentThread` * eg. `ParentThread`
* *
* ### Overriding Model's __construct method. * ### Overriding Model's __construct method.
@ -1202,7 +1202,7 @@ class Model extends Object implements CakeEventListener {
} }
/** /**
* Normalize Xml::toArray() to use in Model::save() * Normalize `Xml::toArray()` to use in `Model::save()`
* *
* @param array $xml XML as array * @param array $xml XML as array
* @return array * @return array
@ -1602,9 +1602,9 @@ class Model extends Object implements CakeEventListener {
* If a boolean, indicates whether or not to validate before saving. * If a boolean, indicates whether or not to validate before saving.
* If an array, can have following keys: * If an array, can have following keys:
* *
* - `validate`: Set to true/false to enable or disable validation. * - validate: Set to true/false to enable or disable validation.
* - `fieldList`: An array of fields you want to allow for saving. * - fieldList: An array of fields you want to allow for saving.
* - `callbacks`: Set to false to disable callbacks. Using 'before' or 'after' * - callbacks: Set to false to disable callbacks. Using 'before' or 'after'
* will enable only those callbacks. * will enable only those callbacks.
* - `counterCache`: Boolean to control updating of counter caches (if any) * - `counterCache`: Boolean to control updating of counter caches (if any)
* *
@ -1984,7 +1984,7 @@ class Model extends Object implements CakeEventListener {
} }
/** /**
* Helper method for Model::updateCounterCache(). Checks the fields to be updated for * Helper method for `Model::updateCounterCache()`. Checks the fields to be updated for
* *
* @param array $data The fields of the record that will be updated * @param array $data The fields of the record that will be updated
* @return array Returns updated foreign key values, along with an 'old' key containing the old * @return array Returns updated foreign key values, along with an 'old' key containing the old
@ -2019,12 +2019,12 @@ class Model extends Object implements CakeEventListener {
* *
* #### Options * #### Options
* *
* - validate: Set to false to disable validation, true to validate each record before saving, * - `validate`: Set to false to disable validation, true to validate each record before saving,
* 'first' to validate *all* records before any are saved (default), * 'first' to validate *all* records before any are saved (default),
* or 'only' to only validate the records, but not save them. * or 'only' to only validate the records, but not save them.
* - atomic: If true (default), will attempt to save all records in a single transaction. * - `atomic`: If true (default), will attempt to save all records in a single transaction.
* Should be set to false if database/table does not support transactions. * Should be set to false if database/table does not support transactions.
* - fieldList: Equivalent to the $fieldList parameter in Model::save(). * - `fieldList`: Equivalent to the $fieldList parameter in Model::save().
* It should be an associate array with model name as key and array of fields as value. Eg. * It should be an associate array with model name as key and array of fields as value. Eg.
* {{{ * {{{
* array( * array(
@ -2032,9 +2032,9 @@ class Model extends Object implements CakeEventListener {
* 'AssociatedModel' => array('field', 'otherfield') * 'AssociatedModel' => array('field', 'otherfield')
* ) * )
* }}} * }}}
* - deep: See saveMany/saveAssociated * - `deep`: See saveMany/saveAssociated
* - callbacks: See Model::save() * - `callbacks`: See Model::save()
* - counterCache: See Model::save() * - `counterCache`: See Model::save()
* *
* @param array $data Record data to save. This can be either a numerically-indexed array (for saving multiple * @param array $data Record data to save. This can be either a numerically-indexed array (for saving multiple
* records of the same type), or an array indexed by association name. * records of the same type), or an array indexed by association name.
@ -2064,14 +2064,14 @@ class Model extends Object implements CakeEventListener {
* *
* #### Options * #### Options
* *
* - validate: Set to false to disable validation, true to validate each record before saving, * - `validate`: Set to false to disable validation, true to validate each record before saving,
* 'first' to validate *all* records before any are saved (default), * 'first' to validate *all* records before any are saved (default),
* - atomic: If true (default), will attempt to save all records in a single transaction. * - `atomic`: If true (default), will attempt to save all records in a single transaction.
* Should be set to false if database/table does not support transactions. * Should be set to false if database/table does not support transactions.
* - fieldList: Equivalent to the $fieldList parameter in Model::save() * - `fieldList`: Equivalent to the $fieldList parameter in Model::save()
* - deep: If set to true, all associated data will be saved as well. * - `deep`: If set to true, all associated data will be saved as well.
* - callbacks: See Model::save() * - `callbacks`: See Model::save()
* - counterCache: See Model::save() * - `counterCache`: See Model::save()
* *
* @param array $data Record data to save. This should be a numerically-indexed array * @param array $data Record data to save. This should be a numerically-indexed array
* @param array $options Options to use when saving record data, See $options above. * @param array $options Options to use when saving record data, See $options above.
@ -2149,9 +2149,9 @@ class Model extends Object implements CakeEventListener {
* *
* #### Options * #### Options
* *
* - atomic: If true (default), returns boolean. If false returns array. * - `atomic`: If true (default), returns boolean. If false returns array.
* - fieldList: Equivalent to the $fieldList parameter in Model::save() * - `fieldList`: Equivalent to the $fieldList parameter in Model::save()
* - deep: If set to true, all associated data will be validated as well. * - `deep`: If set to true, all associated data will be validated as well.
* *
* Warning: This method could potentially change the passed argument `$data`, * Warning: This method could potentially change the passed argument `$data`,
* If you do not want this to happen, make a copy of `$data` before passing it * If you do not want this to happen, make a copy of `$data` before passing it
@ -2172,11 +2172,11 @@ class Model extends Object implements CakeEventListener {
* *
* #### Options * #### Options
* *
* - validate: Set to `false` to disable validation, `true` to validate each record before saving, * - `validate`: Set to `false` to disable validation, `true` to validate each record before saving,
* 'first' to validate *all* records before any are saved(default), * 'first' to validate *all* records before any are saved(default),
* - atomic: If true (default), will attempt to save all records in a single transaction. * - `atomic`: If true (default), will attempt to save all records in a single transaction.
* Should be set to false if database/table does not support transactions. * Should be set to false if database/table does not support transactions.
* - fieldList: Equivalent to the $fieldList parameter in Model::save(). * - `fieldList`: Equivalent to the $fieldList parameter in Model::save().
* It should be an associate array with model name as key and array of fields as value. Eg. * It should be an associate array with model name as key and array of fields as value. Eg.
* {{{ * {{{
* array( * array(
@ -2184,9 +2184,9 @@ class Model extends Object implements CakeEventListener {
* 'AssociatedModel' => array('field', 'otherfield') * 'AssociatedModel' => array('field', 'otherfield')
* ) * )
* }}} * }}}
* - deep: If set to true, not only directly associated data is saved, but deeper nested associated data as well. * - `deep`: If set to true, not only directly associated data is saved, but deeper nested associated data as well.
* - callbacks: See Model::save() * - `callbacks`: See Model::save()
* - counterCache: See Model::save() * - `counterCache`: See Model::save()
* *
* @param array $data Record data to save. This should be an array indexed by association name. * @param array $data Record data to save. This should be an array indexed by association name.
* @param array $options Options to use when saving record data, See $options above. * @param array $options Options to use when saving record data, See $options above.
@ -2358,9 +2358,9 @@ class Model extends Object implements CakeEventListener {
* *
* #### Options * #### Options
* *
* - atomic: If true (default), returns boolean. If false returns array. * - `atomic`: If true (default), returns boolean. If false returns array.
* - fieldList: Equivalent to the $fieldList parameter in Model::save() * - `fieldList`: Equivalent to the $fieldList parameter in Model::save()
* - deep: If set to true, not only directly associated data , but deeper nested associated data is validated as well. * - `deep`: If set to true, not only directly associated data , but deeper nested associated data is validated as well.
* *
* Warning: This method could potentially change the passed argument `$data`, * Warning: This method could potentially change the passed argument `$data`,
* If you do not want this to happen, make a copy of `$data` before passing it * If you do not want this to happen, make a copy of `$data` before passing it
@ -2592,8 +2592,8 @@ class Model extends Object implements CakeEventListener {
/** /**
* Returns true if a record with particular ID exists. * Returns true if a record with particular ID exists.
* *
* If $id is not passed it calls Model::getID() to obtain the current record ID, * If $id is not passed it calls `Model::getID()` to obtain the current record ID,
* and then performs a Model::find('count') on the currently configured datasource * and then performs a `Model::find('count')` on the currently configured datasource
* to ascertain the existence of the record in persistent storage. * to ascertain the existence of the record in persistent storage.
* *
* @param integer|string $id ID of record to check for existence * @param integer|string $id ID of record to check for existence

View file

@ -880,7 +880,7 @@ class CakeTimeTest extends CakeTestCase {
$date = new DateTime('+1 hour', new DateTimeZone('America/New_York')); $date = new DateTime('+1 hour', new DateTimeZone('America/New_York'));
$result = $this->Time->fromString($date, 'UTC'); $result = $this->Time->fromString($date, 'UTC');
$date->setTimezone(new DateTimeZone('UTC')); $date->setTimezone(new DateTimeZone('UTC'));
$expected = $date->format('U') + $date->getOffset(); $expected = $date->getTimestamp() + $date->getOffset();
$this->assertWithinMargin($expected, $result, 1); $this->assertWithinMargin($expected, $result, 1);
@ -888,6 +888,7 @@ class CakeTimeTest extends CakeTestCase {
$date = new DateTime('+1 hour', new DateTimeZone('America/New_York')); $date = new DateTime('+1 hour', new DateTimeZone('America/New_York'));
$result = $this->Time->fromString($date, 'Asia/Kuwait'); $result = $this->Time->fromString($date, 'Asia/Kuwait');
$date->setTimezone(new DateTimeZone('Asia/Kuwait')); $date->setTimezone(new DateTimeZone('Asia/Kuwait'));
$expected = $date->format('U') + $date->getOffset(); $expected = $date->format('U') + $date->getOffset();
$this->assertWithinMargin($expected, $result, 1); $this->assertWithinMargin($expected, $result, 1);
@ -895,6 +896,18 @@ class CakeTimeTest extends CakeTestCase {
$this->_restoreSystemTimezone(); $this->_restoreSystemTimezone();
} }
/**
* Test that datetimes in the default timezone are not modified.
*
* @return void
*/
public function testFromStringWithDateTimeNoConversion() {
Configure::write('Config.timezone', date_default_timezone_get());
$date = new DateTime('2013-04-09');
$result = $this->Time->fromString($date);
$this->assertEquals($result, $date->getTimestamp());
}
/** /**
* test converting time specifiers using a time definition localfe file * test converting time specifiers using a time definition localfe file
* *

View file

@ -319,10 +319,15 @@ class CakeTime {
if (is_int($dateString) || is_numeric($dateString)) { if (is_int($dateString) || is_numeric($dateString)) {
$date = intval($dateString); $date = intval($dateString);
} elseif (is_object($dateString) && $dateString instanceof DateTime) { } elseif (
$dateString instanceof DateTime &&
$dateString->getTimezone()->getName() != date_default_timezone_get()
) {
$clone = clone $dateString; $clone = clone $dateString;
$clone->setTimezone(new DateTimeZone(date_default_timezone_get())); $clone->setTimezone(new DateTimeZone(date_default_timezone_get()));
$date = (int)$clone->format('U') + $clone->getOffset(); $date = (int)$clone->getTimestamp() + $clone->getOffset();
} elseif ($dateString instanceof DateTime) {
$date = (int)$dateString->getTimeStamp();
} else { } else {
$date = strtotime($dateString); $date = strtotime($dateString);
} }

View file

@ -845,7 +845,7 @@ class FormHelper extends AppHelper {
$modelFields = array(); $modelFields = array();
$model = $this->model(); $model = $this->model();
if ($model) { if ($model) {
$modelFields = array_keys($this->_introspectModel($model, 'fields')); $modelFields = array_keys((array)$this->_introspectModel($model, 'fields'));
} }
if (is_array($fields)) { if (is_array($fields)) {
if (array_key_exists('legend', $fields) && !in_array('legend', $modelFields)) { if (array_key_exists('legend', $fields) && !in_array('legend', $modelFields)) {