mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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
This commit is contained in:
parent
a9bafdedb4
commit
2edfe3dd53
4 changed files with 5 additions and 164 deletions
|
@ -272,7 +272,6 @@ class ControllerTask extends Shell {
|
||||||
$compact = array();
|
$compact = array();
|
||||||
$actions .= "\tfunction {$admin}add() {\n";
|
$actions .= "\tfunction {$admin}add() {\n";
|
||||||
$actions .= "\t\tif (!empty(\$this->data)) {\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\t\$this->{$currentModelName}->create();\n";
|
||||||
$actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n";
|
$actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n";
|
||||||
if ($wannaUseSession) {
|
if ($wannaUseSession) {
|
||||||
|
@ -324,7 +323,6 @@ class ControllerTask extends Shell {
|
||||||
}
|
}
|
||||||
$actions .= "\t\t}\n";
|
$actions .= "\t\t}\n";
|
||||||
$actions .= "\t\tif (!empty(\$this->data)) {\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";
|
$actions .= "\t\t\tif (\$this->{$currentModelName}->save(\$this->data)) {\n";
|
||||||
if ($wannaUseSession) {
|
if ($wannaUseSession) {
|
||||||
$actions .= "\t\t\t\t\$this->Session->setFlash('The ".$singularHumanName." has been saved');\n";
|
$actions .= "\t\t\t\t\$this->Session->setFlash('The ".$singularHumanName." has been saved');\n";
|
||||||
|
|
|
@ -509,7 +509,7 @@ class Controller extends Object {
|
||||||
if ($url !== null) {
|
if ($url !== null) {
|
||||||
header('Location: ' . Router::url($url, true));
|
header('Location: ' . Router::url($url, true));
|
||||||
}
|
}
|
||||||
if (!empty($status)) {
|
if (!empty($status) && ($status >= 300 && $status < 400)) {
|
||||||
header($status);
|
header($status);
|
||||||
}
|
}
|
||||||
if ($exit) {
|
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)
|
* Deprecated, see Model::deconstruct();
|
||||||
* and prepares their values to be used for model operations.
|
|
||||||
*
|
*
|
||||||
* @param string $modelClass Model class to use (defaults to controller's model)
|
* @see Model::deconstruct()
|
||||||
* @access public
|
* @deprecated as of 1.2.0.5970
|
||||||
*/
|
*/
|
||||||
function cleanUpFields($modelClass = null) {
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Handles automatic pagination of model records.
|
* Handles automatic pagination of model records.
|
||||||
*
|
*
|
||||||
|
|
|
@ -266,8 +266,6 @@ class Scaffold extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->controller->data)) {
|
if (!empty($this->controller->data)) {
|
||||||
$this->controller->cleanUpFields();
|
|
||||||
|
|
||||||
if ($action == 'create') {
|
if ($action == 'create') {
|
||||||
$this->ScaffoldModel->create();
|
$this->ScaffoldModel->create();
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,92 +46,6 @@ class ControllerTest extends CakeTestCase {
|
||||||
|
|
||||||
var $fixtures = array('core.post', 'core.comment');
|
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() {
|
function testConstructClasses() {
|
||||||
$Controller =& new Controller();
|
$Controller =& new Controller();
|
||||||
$Controller->modelClass = 'ControllerPost';
|
$Controller->modelClass = 'ControllerPost';
|
||||||
|
|
Loading…
Add table
Reference in a new issue