From 2edfe3dd53ef7f5f86643c83fe9fa8f6f4f9b468 Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 9 Nov 2007 02:34:00 +0000 Subject: [PATCH] updating Controller::redirect(), closes #3522, deprecated Controller::cleanUpFields, see Model::deconstruct() git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5973 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/libs/tasks/controller.php | 2 - cake/libs/controller/controller.php | 79 ++--------------- cake/libs/controller/scaffold.php | 2 - .../cases/libs/controller/controller.test.php | 86 ------------------- 4 files changed, 5 insertions(+), 164 deletions(-) diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index c3d0b8366..0f7677d70 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -272,7 +272,6 @@ class ControllerTask extends Shell { $compact = array(); $actions .= "\tfunction {$admin}add() {\n"; $actions .= "\t\tif (!empty(\$this->data)) {\n"; - $actions .= "\t\t\t\$this->cleanUpFields();\n"; $actions .= "\t\t\t\$this->{$currentModelName}->create();\n"; $actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n"; if ($wannaUseSession) { @@ -324,7 +323,6 @@ class ControllerTask extends Shell { } $actions .= "\t\t}\n"; $actions .= "\t\tif (!empty(\$this->data)) {\n"; - $actions .= "\t\t\t\$this->cleanUpFields();\n"; $actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n"; if ($wannaUseSession) { $actions .= "\t\t\t\t\$this->Session->setFlash('The ".$singularHumanName." has been saved');\n"; diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 1b25ec43e..c8402713b 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -509,7 +509,7 @@ class Controller extends Object { if ($url !== null) { header('Location: ' . Router::url($url, true)); } - if (!empty($status)) { + if (!empty($status) && ($status >= 300 && $status < 400)) { header($status); } if ($exit) { @@ -813,81 +813,12 @@ class Controller extends Object { } } /** - * Cleans up the date fields of current Model. Goes through posted fields (in Controller::$data) - * and prepares their values to be used for model operations. + * Deprecated, see Model::deconstruct(); * - * @param string $modelClass Model class to use (defaults to controller's model) - * @access public + * @see Model::deconstruct() + * @deprecated as of 1.2.0.5970 */ - function cleanUpFields($modelClass = null) { - if ($modelClass == null) { - $modelClass = $this->modelClass; - } - $fields = $this->{$modelClass}->schema(); - foreach ($fields as $field => $value) { - if (in_array($value['type'], array('datetime', 'timestamp', 'date', 'time'))) { - $useNewDate = false; - $date = array(); - $dates = array('Y'=>'_year', 'm'=>'_month', 'd'=>'_day'); - foreach ($dates as $default => $var) { - if (isset($this->data[$modelClass][$field . $var])) { - if (!empty($this->data[$modelClass][$field . $var])) { - $date[$var] = $this->data[$modelClass][$field . $var]; - } - $useNewDate = true; - unset($this->data[$modelClass][$field . $var]); - } - } - if (count($date) == 3 && in_array($value['type'], array('datetime', 'timestamp', 'date'))) { - $date = join('-', array_values($date)); - } else { - $date = null; - } - - if ($value['type'] != 'date') { - $time = array(); - $times = array('H'=>'_hour', 'i'=>'_min', 's'=>'_sec'); - foreach($times as $default => $var) { - if (isset($this->data[$modelClass][$field . $var])) { - if (!empty($this->data[$modelClass][$field . $var])) { - $time[$var] = $this->data[$modelClass][$field . $var]; - } elseif ($this->data[$modelClass][$field . $var] === '0') { - $time[$var] = '00'; - } - $useNewDate = true; - unset($this->data[$modelClass][$field . $var]); - } - } - - $meridian = false; - if (isset($this->data[$modelClass][$field . '_meridian'])) { - $meridian = $this->data[$modelClass][$field . '_meridian']; - unset($this->data[$modelClass][$field . '_meridian']); - } - - if (isset($time['_hour']) && $time['_hour'] != 12 && 'pm' == $meridian) { - $time['_hour'] = $time['_hour'] + 12; - } - if (isset($time['_hour']) && $time['_hour'] == 12 && 'am' == $meridian) { - $time['_hour'] = '00'; - } - if (count($time) > 1) { - $time = join(':', array_values($time)); - } - - if ($date && $time) { - $date = $date . ' ' . $time; - } elseif (is_string($time)) { - $date = $time; - } - } - - if ($useNewDate && (isset($date) || isset($value['null']))) { - $this->data[$modelClass][$field] = $date; - } - } - } - } + function cleanUpFields($modelClass = null) {} /** * Handles automatic pagination of model records. * diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index c1f050d53..ef2bd3a2c 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -266,8 +266,6 @@ class Scaffold extends Object { } if (!empty($this->controller->data)) { - $this->controller->cleanUpFields(); - if ($action == 'create') { $this->ScaffoldModel->create(); } diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 6474cb504..94e98b4f6 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -46,92 +46,6 @@ class ControllerTest extends CakeTestCase { var $fixtures = array('core.post', 'core.comment'); - function testCleanUpFields() { - $Controller =& new Controller(); - $Controller->modelClass = 'ControllerPost'; - $Controller->ControllerPost =& new ControllerPost(); - - $Controller->data['ControllerPost']['created_year'] = ''; - $Controller->data['ControllerPost']['created_month'] = ''; - $Controller->data['ControllerPost']['created_day'] = ''; - $Controller->data['ControllerPost']['created_hour'] = ''; - $Controller->data['ControllerPost']['created_min'] = ''; - $Controller->data['ControllerPost']['created_sec'] = ''; - - $Controller->cleanUpFields(); - $expected = array('ControllerPost'=> array('created'=> '')); - $this->assertEqual($Controller->data, $expected); - - $Controller->data['ControllerPost']['created_year'] = '2007'; - $Controller->data['ControllerPost']['created_month'] = '08'; - $Controller->data['ControllerPost']['created_day'] = '20'; - $Controller->data['ControllerPost']['created_hour'] = ''; - $Controller->data['ControllerPost']['created_min'] = ''; - $Controller->data['ControllerPost']['created_sec'] = ''; - - $Controller->cleanUpFields(); - $expected = array('ControllerPost'=> array('created'=> '2007-08-20')); - $this->assertEqual($Controller->data, $expected); - - $Controller->data['ControllerPost']['created_year'] = '2007'; - $Controller->data['ControllerPost']['created_month'] = '08'; - $Controller->data['ControllerPost']['created_day'] = '20'; - $Controller->data['ControllerPost']['created_hour'] = '10'; - $Controller->data['ControllerPost']['created_min'] = '12'; - $Controller->data['ControllerPost']['created_sec'] = ''; - - $Controller->cleanUpFields(); - $expected = array('ControllerPost'=> array('created'=> '2007-08-20 10:12')); - $this->assertEqual($Controller->data, $expected); - - $Controller->data['ControllerPost']['created_year'] = '2007'; - $Controller->data['ControllerPost']['created_month'] = ''; - $Controller->data['ControllerPost']['created_day'] = '12'; - $Controller->data['ControllerPost']['created_hour'] = '20'; - $Controller->data['ControllerPost']['created_min'] = ''; - $Controller->data['ControllerPost']['created_sec'] = ''; - - $Controller->cleanUpFields(); - $expected = array('ControllerPost'=> array('created'=> '')); - $this->assertEqual($Controller->data, $expected); - - $Controller->data['ControllerPost']['created_hour'] = '20'; - $Controller->data['ControllerPost']['created_min'] = '33'; - - $Controller->cleanUpFields(); - $expected = array('ControllerPost'=> array('created'=> '20:33')); - $this->assertEqual($Controller->data, $expected); - - $Controller->data['ControllerPost']['created_hour'] = '20'; - $Controller->data['ControllerPost']['created_min'] = '33'; - $Controller->data['ControllerPost']['created_sec'] = '33'; - - $Controller->cleanUpFields(); - $expected = array('ControllerPost'=> array('created'=> '20:33:33')); - $this->assertEqual($Controller->data, $expected); - - $Controller->data['ControllerPost']['created_hour'] = '13'; - $Controller->data['ControllerPost']['created_min'] = '00'; - $Controller->data['ControllerPost']['updated_hour'] = '14'; - $Controller->data['ControllerPost']['updated_min'] = '40'; - - $Controller->cleanUpFields(); - $expected = array('ControllerPost'=> array('created'=> '13:00', 'updated'=> '14:40')); - $this->assertEqual($Controller->data, $expected); - - $Controller->data['ControllerPost']['created_hour'] = '13'; - $Controller->data['ControllerPost']['created_min'] = '0'; - $Controller->data['ControllerPost']['updated_hour'] = '14'; - $Controller->data['ControllerPost']['updated_min'] = '40'; - - $Controller->cleanUpFields(); - $expected = array('ControllerPost'=> array('created'=> '13:00', 'updated'=> '14:40')); - $this->assertEqual($Controller->data, $expected); - - - unset($Controller); - } - function testConstructClasses() { $Controller =& new Controller(); $Controller->modelClass = 'ControllerPost';