Permalink
Browse files

Merge branch '2.0' into 2.1

Conflicts:
	lib/Cake/Model/Model.php
	lib/Cake/Test/Case/Routing/RouterTest.php
  • Loading branch information...
2 parents d61b6dc + e6f5ebc commit df5d9ac3d1529c0dd1ff29d1c38af85ed53f80a8 @markstory markstory committed Jan 21, 2012
@@ -576,12 +576,9 @@ protected function _getParams() {
if (is_string($aco)) {
$aco = $this->parseIdentifier($aco);
}
- $action = null;
- if (isset($this->args[2])) {
+ $action = '*';
+ if (isset($this->args[2]) && !in_array($this->args[2], array('', 'all'))) {
$action = $this->args[2];
- if ($action == '' || $action == 'all') {
- $action = '*';
- }
}
return compact('aro', 'aco', 'action', 'aroName', 'acoName');
}
@@ -87,7 +87,7 @@ public function execute() {
*/
protected function _interactive() {
$this->hr();
- $this->out('Database Configuration:');
+ $this->out(__d('cake_console', 'Database Configuration:'));
$this->hr();
$done = false;
$dbConfigs = array();
@@ -169,7 +169,10 @@ public function locations() {
}
}
}
+
$this->_moveViewFiles();
+ $this->_moveAppClasses();
+
$sourceDirs = array(
'.' => array('recursive' => false),
'Console',
@@ -593,6 +596,35 @@ protected function _moveViewFiles() {
}
}
+/**
+ * Move the AppController, and AppModel classes.
+ *
+ * @return void
+ */
+ protected function _moveAppClasses() {
+ $files = array(
+ APP . 'app_controller.php' => APP . 'Controller' . DS . 'AppController.php',
+ APP . 'controllers' . DS .'app_controller.php' => APP . 'Controller' . DS . 'AppController.php',
+ APP . 'app_model.php' => APP . 'Model' . DS . 'AppModel.php',
+ APP . 'models' . DS . 'app_model.php' => APP . 'Model' . DS . 'AppModel.php',
+ );
+ foreach ($files as $old => $new) {
+ if (file_exists($old)) {
+ $this->out(__d('cake_console', 'Moving %s to %s', $old, $new));
+
+ if ($this->params['dry-run']) {
+ continue;
+ }
+ if ($this->params['git']) {
+ exec('git mv -f ' . escapeshellarg($old) . ' ' . escapeshellarg($old . '__'));
+ exec('git mv -f ' . escapeshellarg($old . '__') . ' ' . escapeshellarg($new));
+ } else {
+ rename($old, $new);
+ }
+ }
+ }
+ }
+
/**
* Move application php files to where they now should be
*
@@ -467,7 +467,7 @@ public function parse($argv, $command = null) {
}
$params = $args = array();
$this->_tokens = $argv;
- while ($token = array_shift($this->_tokens)) {
+ while (($token = array_shift($this->_tokens)) !== null) {
if (substr($token, 0, 2) == '--') {
$params = $this->_parseLongOption($token, $params);
} elseif (substr($token, 0, 1) == '-') {
@@ -465,7 +465,12 @@ public function in($prompt, $options = null, $default = null) {
}
}
if (is_array($options)) {
- while ($in === '' || ($in !== '' && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) {
+ $options = array_merge(
+ array_map('strtolower', $options),
+ array_map('strtoupper', $options),
+ $options
+ );
+ while ($in === '' || !in_array($in, $options)) {
$in = $this->_getInput($prompt, $options, $default);
}
}
@@ -29,13 +29,6 @@
*/
class PagesController extends AppController {
-/**
- * Controller name
- *
- * @var string
- */
- public $name = 'Pages';
-
/**
* Default helper
*
@@ -393,7 +393,12 @@ protected function _authRequired($controller) {
if ($this->Session->check('_Token')) {
$tData = $this->Session->read('_Token');
- if (!empty($tData['allowedControllers']) && !in_array($this->request->params['controller'], $tData['allowedControllers']) || !empty($tData['allowedActions']) && !in_array($this->request->params['action'], $tData['allowedActions'])) {
+ if (
+ !empty($tData['allowedControllers']) &&
+ !in_array($this->request->params['controller'], $tData['allowedControllers']) ||
+ !empty($tData['allowedActions']) &&
+ !in_array($this->request->params['action'], $tData['allowedActions'])
+ ) {
if (!$this->blackHole($controller, 'auth')) {
return null;
}
@@ -443,8 +448,8 @@ protected function _validatePost($controller) {
$multi = array();
foreach ($fieldList as $i => $key) {
- if (preg_match('/\.\d+$/', $key)) {
- $multi[$i] = preg_replace('/\.\d+$/', '', $key);
+ if (preg_match('/(\.\d+)+$/', $key)) {
+ $multi[$i] = preg_replace('/(\.\d+)+$/', '', $key);
unset($fieldList[$i]);
}
}
@@ -838,7 +838,7 @@ public function set($one, $two = null) {
* @return mixed Returns the return value of the called action
*/
public function setAction($action) {
- $this->request->action = $action;
+ $this->request->params['action'] = $action;
$this->view = $action;
$args = func_get_args();
unset($args[0]);
View
@@ -2105,11 +2105,11 @@ public function validateMany($data, $options = array()) {
*
* #### Options
*
- * - validate: Set to false to disable validation, true to validate each record before saving,
- * 'first' to validate *all* records before any are saved (default),
- * - atomic: If true (default), will attempt to save all records in a single transaction.
+ * - `validate` Set to `false` to disable validation, `true` to validate each record before saving,
+ * 'first' to validate *all* records before any are saved(default),
+ * - `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.
- * - fieldList: Equivalent to the $fieldList parameter in Model::save()
+ * - `fieldList` Equivalent to the $fieldList parameter in Model::save()
*
* @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.
@@ -2123,7 +2123,7 @@ public function saveAssociated($data = null, $options = array()) {
$data = $this->data;
}
- $options = array_merge(array('validate' => true, 'atomic' => true), $options);
+ $options = array_merge(array('validate' => 'first', 'atomic' => true), $options);
$this->validationErrors = $validationErrors = array();
if (empty($data) && $options['validate'] !== false) {
@@ -2970,7 +2970,7 @@ public function invalidFields($options = array()) {
$data = array();
}
- $exists = $this->exists();
+ $exists = null;
$_validate = $this->validate;
$whitelist = $this->whitelist;
@@ -3016,81 +3016,85 @@ public function invalidFields($options = array()) {
}
$validator = array_merge($default, $validator);
- if (
- empty($validator['on']) || ($validator['on'] == 'create' &&
- !$exists) || ($validator['on'] == 'update' && $exists
- )) {
- $valid = true;
- $requiredFail = (
- (!isset($data[$fieldName]) && $validator['required'] === true) ||
- (
- isset($data[$fieldName]) && (empty($data[$fieldName]) &&
- !is_numeric($data[$fieldName])) && $validator['allowEmpty'] === false
- )
- );
+ if (!empty($validator['on'])) {
+ if ($exists === null) {
+ $exists = $this->exists();
+ }
+ if (($validator['on'] == 'create' && $exists) || ($validator['on'] == 'update' && !$exists)) {
+ continue;
+ }
+ }
- if (!$requiredFail && array_key_exists($fieldName, $data)) {
- if (empty($data[$fieldName]) && $data[$fieldName] != '0' && $validator['allowEmpty'] === true) {
- break;
- }
- if (is_array($validator['rule'])) {
- $rule = $validator['rule'][0];
- unset($validator['rule'][0]);
- $ruleParams = array_merge(array($data[$fieldName]), array_values($validator['rule']));
- } else {
- $rule = $validator['rule'];
- $ruleParams = array($data[$fieldName]);
- }
+ $valid = true;
+ $requiredFail = (
+ (!isset($data[$fieldName]) && $validator['required'] === true) ||
+ (
+ isset($data[$fieldName]) && (empty($data[$fieldName]) &&
+ !is_numeric($data[$fieldName])) && $validator['allowEmpty'] === false
+ )
+ );
- if (in_array(strtolower($rule), $methods)) {
- $ruleParams[] = $validator;
- $ruleParams[0] = array($fieldName => $ruleParams[0]);
- $valid = $this->dispatchMethod($rule, $ruleParams);
- } elseif (in_array($rule, $behaviorMethods) || in_array(strtolower($rule), $behaviorMethods)) {
- $ruleParams[] = $validator;
- $ruleParams[0] = array($fieldName => $ruleParams[0]);
- $valid = $this->Behaviors->dispatchMethod($this, $rule, $ruleParams);
- } elseif (class_exists('Validation') && method_exists('Validation', $rule)) {
- $valid = call_user_func_array(array('Validation', $rule), $ruleParams);
- } elseif (!is_array($validator['rule'])) {
- $valid = preg_match($rule, $data[$fieldName]);
- } elseif (Configure::read('debug') > 0) {
- trigger_error(__d('cake_dev', 'Could not find validation handler %s for %s', $rule, $fieldName), E_USER_WARNING);
- }
+ if (!$requiredFail && array_key_exists($fieldName, $data)) {
+ if (empty($data[$fieldName]) && $data[$fieldName] != '0' && $validator['allowEmpty'] === true) {
+ break;
+ }
+ if (is_array($validator['rule'])) {
+ $rule = $validator['rule'][0];
+ unset($validator['rule'][0]);
+ $ruleParams = array_merge(array($data[$fieldName]), array_values($validator['rule']));
+ } else {
+ $rule = $validator['rule'];
+ $ruleParams = array($data[$fieldName]);
}
- if ($requiredFail || !$valid || (is_string($valid) && strlen($valid) > 0)) {
- if (is_string($valid)) {
- $message = $valid;
- } elseif (isset($validator['message'])) {
- $args = null;
- if (is_array($validator['message'])) {
- $message = $validator['message'][0];
- $args = array_slice($validator['message'], 1);
- } else {
- $message = $validator['message'];
- }
- if (is_array($validator['rule']) && $args === null) {
- $args = array_slice($ruleSet[$index]['rule'], 1);
- }
- $message = __d($validationDomain, $message, $args);
- } elseif (is_string($index)) {
- if (is_array($validator['rule'])) {
- $args = array_slice($ruleSet[$index]['rule'], 1);
- $message = __d($validationDomain, $index, $args);
- } else {
- $message = __d($validationDomain, $index);
- }
- } elseif (!$requiredFail && is_numeric($index) && count($ruleSet) > 1) {
- $message = $index + 1;
+ if (in_array(strtolower($rule), $methods)) {
+ $ruleParams[] = $validator;
+ $ruleParams[0] = array($fieldName => $ruleParams[0]);
+ $valid = $this->dispatchMethod($rule, $ruleParams);
+ } elseif (in_array($rule, $behaviorMethods) || in_array(strtolower($rule), $behaviorMethods)) {
+ $ruleParams[] = $validator;
+ $ruleParams[0] = array($fieldName => $ruleParams[0]);
+ $valid = $this->Behaviors->dispatchMethod($this, $rule, $ruleParams);
+ } elseif (method_exists('Validation', $rule)) {
+ $valid = call_user_func_array(array('Validation', $rule), $ruleParams);
+ } elseif (!is_array($validator['rule'])) {
+ $valid = preg_match($rule, $data[$fieldName]);
+ } elseif (Configure::read('debug') > 0) {
+ trigger_error(__d('cake_dev', 'Could not find validation handler %s for %s', $rule, $fieldName), E_USER_WARNING);
+ }
+ }
+
+ if ($requiredFail || !$valid || (is_string($valid) && strlen($valid) > 0)) {
+ if (is_string($valid)) {
+ $message = $valid;
+ } elseif (isset($validator['message'])) {
+ $args = null;
+ if (is_array($validator['message'])) {
+ $message = $validator['message'][0];
+ $args = array_slice($validator['message'], 1);
} else {
- $message = __d('cake_dev', 'This field cannot be left blank');
+ $message = $validator['message'];
}
-
- $this->invalidate($fieldName, $message);
- if ($validator['last']) {
- break;
+ if (is_array($validator['rule']) && $args === null) {
+ $args = array_slice($ruleSet[$index]['rule'], 1);
+ }
+ $message = __d($validationDomain, $message, $args);
+ } elseif (is_string($index)) {
+ if (is_array($validator['rule'])) {
+ $args = array_slice($ruleSet[$index]['rule'], 1);
+ $message = __d($validationDomain, $index, $args);
+ } else {
+ $message = __d($validationDomain, $index);
}
+ } elseif (!$requiredFail && is_numeric($index) && count($ruleSet) > 1) {
+ $message = $index + 1;
+ } else {
+ $message = __d('cake_dev', 'This field cannot be left blank');
+ }
+
+ $this->invalidate($fieldName, $message);
+ if ($validator['last']) {
+ break;
}
}
}
@@ -1240,17 +1240,22 @@ protected function _createBoundary() {
/**
* Attach non-embedded files by adding file contents inside boundaries.
*
+ * @param string $boundary Boundary to use. If null, will default to $this->_boundary
* @return array An array of lines to add to the message
*/
- protected function _attachFiles() {
+ protected function _attachFiles($boundary = null) {
+ if ($boundary === null) {
+ $boundary = $this->_boundary;
+ }
+
$msg = array();
foreach ($this->_attachments as $filename => $fileInfo) {
if (!empty($fileInfo['contentId'])) {
continue;
}
$data = $this->_readFile($fileInfo['file']);
- $msg[] = '--' . $this->_boundary;
+ $msg[] = '--' . $boundary;
$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
$msg[] = 'Content-Transfer-Encoding: base64';
$msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
@@ -1278,17 +1283,22 @@ protected function _readFile($file) {
/**
* Attach inline/embedded files to the message.
*
+ * @param string $boundary Boundary to use. If null, will default to $this->_boundary
* @return array An array of lines to add to the message
*/
- protected function _attachInlineFiles() {
+ protected function _attachInlineFiles($boundary = null) {
+ if ($boundary === null) {
+ $boundary = $this->_boundary;
+ }
+
$msg = array();
foreach ($this->_attachments as $filename => $fileInfo) {
if (empty($fileInfo['contentId'])) {
continue;
}
$data = $this->_readFile($fileInfo['file']);
- $msg[] = '--rel-' . $this->_boundary;
+ $msg[] = '--' . $boundary;
$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
$msg[] = 'Content-Transfer-Encoding: base64';
$msg[] = 'Content-ID: <' . $fileInfo['contentId'] . '>';
@@ -1365,15 +1375,15 @@ protected function _render($content) {
}
if ($hasInlineAttachments) {
- $attachments = $this->_attachInlineFiles();
+ $attachments = $this->_attachInlineFiles($relBoundary);
$msg = array_merge($msg, $attachments);
$msg[] = '';
$msg[] = '--' . $relBoundary . '--';
$msg[] = '';
}
if ($hasAttachments) {
- $attachments = $this->_attachFiles();
+ $attachments = $this->_attachFiles($boundary);
$msg = array_merge($msg, $attachments);
}
if ($hasAttachments || $hasMultipleTypes) {
Oops, something went wrong.

0 comments on commit df5d9ac

Please sign in to comment.