Permalink
Browse files

Merge remote-tracking branch 'origin/master' into 2.3

Conflicts:
	lib/Cake/Model/Behavior/TranslateBehavior.php
	lib/Cake/Model/CakeSchema.php
	lib/Cake/Utility/CakeTime.php
	lib/Cake/Utility/ClassRegistry.php
	lib/Cake/View/MediaView.php
  • Loading branch information...
lorenzo committed Sep 25, 2012
2 parents e454282 + 6818d69 commit d5c9d97dc19a2614b1d653a63e4ba7060847d7b6
Showing with 343 additions and 172 deletions.
  1. +5 −2 lib/Cake/Configure/IniReader.php
  2. +4 −1 lib/Cake/Console/Command/Task/DbConfigTask.php
  3. +4 −0 lib/Cake/Console/ConsoleErrorHandler.php
  4. +2 −2 lib/Cake/Console/ShellDispatcher.php
  5. +0 −2 lib/Cake/Controller/Component/Acl/PhpAcl.php
  6. +1 −1 lib/Cake/Controller/Component/AuthComponent.php
  7. +0 −3 lib/Cake/Controller/Component/CookieComponent.php
  8. +0 −1 lib/Cake/Controller/Controller.php
  9. +0 −1 lib/Cake/Core/Configure.php
  10. +14 −4 lib/Cake/Model/Behavior/TranslateBehavior.php
  11. +0 −1 lib/Cake/Model/Datasource/CakeSession.php
  12. +4 −1 lib/Cake/Model/Datasource/Database/Mysql.php
  13. +5 −2 lib/Cake/Model/Datasource/Database/Postgres.php
  14. +5 −2 lib/Cake/Model/Datasource/Database/Sqlite.php
  15. +4 −1 lib/Cake/Model/Datasource/Database/Sqlserver.php
  16. +7 −6 lib/Cake/Model/Datasource/DboSource.php
  17. +3 −3 lib/Cake/Model/Model.php
  18. +1 −2 lib/Cake/Model/Validator/CakeValidationRule.php
  19. +1 −1 lib/Cake/Model/Validator/CakeValidationSet.php
  20. +1 −1 lib/Cake/Network/CakeRequest.php
  21. +23 −6 lib/Cake/Network/Email/MailTransport.php
  22. +1 −1 lib/Cake/Routing/Router.php
  23. +17 −0 lib/Cake/Test/Case/Console/ConsoleErrorHandlerTest.php
  24. +3 −1 lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php
  25. +3 −3 lib/Cake/Test/Case/Error/ExceptionRendererTest.php
  26. +84 −0 lib/Cake/Test/Case/Network/Email/MailTransportTest.php
  27. +24 −0 lib/Cake/Test/Case/Routing/RouterTest.php
  28. +15 −0 lib/Cake/Test/Case/Utility/CakeTimeTest.php
  29. +1 −1 lib/Cake/Test/Case/Utility/DebuggerTest.php
  30. +5 −5 lib/Cake/Test/Case/Utility/FileTest.php
  31. +74 −79 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  32. +3 −10 lib/Cake/Utility/CakeTime.php
  33. +0 −1 lib/Cake/Utility/Debugger.php
  34. +1 −1 lib/Cake/Utility/Folder.php
  35. +0 −1 lib/Cake/Utility/Hash.php
  36. +7 −1 lib/Cake/View/Errors/missing_connection.ctp
  37. +18 −14 lib/Cake/View/Helper/FormHelper.php
  38. +0 −1 lib/Cake/View/Helper/MootoolsEngineHelper.php
  39. +1 −1 lib/Cake/View/Helper/PaginatorHelper.php
  40. +0 −1 lib/Cake/View/Helper/PrototypeEngineHelper.php
  41. +1 −1 lib/Cake/View/Helper/RssHelper.php
  42. +0 −1 lib/Cake/View/Helper/TimeHelper.php
  43. +1 −6 lib/Cake/View/View.php
@@ -72,11 +72,14 @@ class IniReader implements ConfigReaderInterface {
* Build and construct a new ini file parser. The parser can be used to read
* ini files that are on the filesystem.
*
- * @param string $path Path to load ini config files from.
+ * @param string $path Path to load ini config files from. Defaults to APP . 'Config' . DS
* @param string $section Only get one section, leave null to parse and fetch
* all sections in the ini file.
*/
- public function __construct($path, $section = null) {
+ public function __construct($path = null, $section = null) {
+ if (!$path) {
+ $path = APP . 'Config' . DS;
+ }
$this->_path = $path;
$this->_section = $section;
}
@@ -315,8 +315,11 @@ public function bake($configs) {
$config = array_merge($this->_defaultConfig, $config);
extract($config);
+ if (strpos($datasource, 'Database/') === false) {
+ $datasource = "Database/{$datasource}";
+ }
$out .= "\tpublic \${$name} = array(\n";
- $out .= "\t\t'datasource' => 'Database/{$datasource}',\n";
+ $out .= "\t\t'datasource' => '{$datasource}',\n";
$out .= "\t\t'persistent' => {$persistent},\n";
$out .= "\t\t'host' => '{$host}',\n";
@@ -84,6 +84,10 @@ public function handleError($code, $description, $file = null, $line = null, $co
if (Configure::read('debug') == 0) {
CakeLog::write($log, $message);
}
+
+ if ($log === LOG_ERR) {
+ $this->_stop(1);
+ }
}
/**
@@ -160,11 +160,11 @@ public function setErrorHandlers() {
$errorHandler = new ConsoleErrorHandler();
if (empty($error['consoleHandler'])) {
$error['consoleHandler'] = array($errorHandler, 'handleError');
- Configure::write('error', $error);
+ Configure::write('Error', $error);
}
if (empty($exception['consoleHandler'])) {
$exception['consoleHandler'] = array($errorHandler, 'handleException');
- Configure::write('exception', $exception);
+ Configure::write('Exception', $exception);
}
set_exception_handler($exception['consoleHandler']);
set_error_handler($error['consoleHandler'], Configure::read('Error.level'));
@@ -318,10 +318,8 @@ public function resolve($aco) {
* @return void
*/
public function build(array $allow, array $deny = array()) {
- $stack = array();
$this->_tree = array();
$tree = array();
- $root = &$tree;
foreach ($allow as $dotPath => $aros) {
if (is_string($aros)) {
@@ -327,7 +327,7 @@ public function startup(Controller $controller) {
if (!empty($this->loginRedirect)) {
$default = $this->loginRedirect;
}
- $controller->redirect($controller->referer($default), null, true);
+ $controller->redirect($controller->referer($default, true), null, true);
return false;
}
@@ -191,9 +191,6 @@ public function startup(Controller $controller) {
$this->_expire($this->time);
$this->_values[$this->name] = array();
- if (isset($_COOKIE[$this->name])) {
- $this->_values[$this->name] = $this->_decrypt($_COOKIE[$this->name]);
- }
}
/**
@@ -557,7 +557,6 @@ protected function _mergeControllerVars() {
if ($mergeParent || !empty($pluginController)) {
$appVars = get_class_vars($this->_mergeParent);
- $uses = $appVars['uses'];
$merge = array('components', 'helpers');
$this->_mergeVars($merge, $this->_mergeParent, true);
}
@@ -198,7 +198,6 @@ public static function check($var = null) {
*/
public static function delete($var = null) {
$keys = explode('.', $var);
- $last = array_pop($keys);
self::$_values = Hash::remove(self::$_values, $var);
}
@@ -140,15 +140,22 @@ public function beforeFind(Model $Model, $query) {
return $query;
}
- $fields = array_merge($this->settings[$Model->alias], $this->runtime[$Model->alias]['fields']);
+ $fields = array_merge(
+ $this->settings[$Model->alias],
+ $this->runtime[$Model->alias]['fields']
+ );
$addFields = array();
if (empty($query['fields'])) {
$addFields = $fields;
} elseif (is_array($query['fields'])) {
foreach ($fields as $key => $value) {
$field = (is_numeric($key)) ? $value : $key;
- if (in_array($Model->escapeField('*'), $query['fields']) || in_array($Model->alias . '.' . $field, $query['fields']) || in_array($field, $query['fields'])) {
+ if (
+ in_array($Model->escapeField('*'), $query['fields']) ||
+ in_array($Model->alias . '.' . $field, $query['fields']) ||
+ in_array($field, $query['fields'])
+ ) {
$addFields[] = $field;
}
}
@@ -425,7 +432,11 @@ public function afterSave(Model $Model, $created) {
$conditions['locale'] = $_locale;
$conditions['content'] = $_value;
if (array_key_exists($_locale, $translations)) {
- $RuntimeModel->save(array($RuntimeModel->alias => array_merge($conditions, array('id' => $translations[$_locale]))));
+ $RuntimeModel->save(array(
+ $RuntimeModel->alias => array_merge(
+ $conditions, array('id' => $translations[$_locale])
+ )
+ ));
} else {
$RuntimeModel->save(array($RuntimeModel->alias => $conditions));
}
@@ -632,7 +643,6 @@ public function unbindTranslation(Model $Model, $fields = null) {
if (is_string($fields)) {
$fields = array($fields);
}
- $RuntimeModel = $this->translateModel($Model);
$associations = array();
foreach ($fields as $key => $value) {
@@ -447,7 +447,6 @@ public static function clear() {
*/
protected static function _configureSession() {
$sessionConfig = Configure::read('Session');
- $iniSet = function_exists('ini_set');
if (isset($sessionConfig['defaults'])) {
$defaults = self::_defaultConfig($sessionConfig['defaults']);
@@ -150,7 +150,10 @@ public function connect() {
);
$this->connected = true;
} catch (PDOException $e) {
- throw new MissingConnectionException(array('class' => $e->getMessage()));
+ throw new MissingConnectionException(array(
+ 'class' => get_class($this),
+ 'message' => $e->getMessage()
+ ));
}
$this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">=");
@@ -122,7 +122,10 @@ public function connect() {
$this->_execute('SET search_path TO ' . $config['schema']);
}
} catch (PDOException $e) {
- throw new MissingConnectionException(array('class' => $e->getMessage()));
+ throw new MissingConnectionException(array(
+ 'class' => get_class($this),
+ 'message' => $e->getMessage()
+ ));
}
return $this->connected;
@@ -457,7 +460,7 @@ public function index($model) {
)
AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname", false);
- foreach ($indexes as $i => $info) {
+ foreach ($indexes as $info) {
$key = array_pop($info);
if ($key['indisprimary']) {
$key['relname'] = 'PRIMARY';
@@ -114,7 +114,10 @@ public function connect() {
$this->_connection = new PDO('sqlite:' . $config['database'], null, null, $flags);
$this->connected = true;
} catch(PDOException $e) {
- throw new MissingConnectionException(array('class' => $e->getMessage()));
+ throw new MissingConnectionException(array(
+ 'class' => get_class($this),
+ 'message' => $e->getMessage()
+ ));
}
return $this->connected;
}
@@ -488,7 +491,7 @@ public function index($model) {
if (is_bool($indexes)) {
return array();
}
- foreach ($indexes as $i => $info) {
+ foreach ($indexes as $info) {
$key = array_pop($info);
$keyInfo = $this->query('PRAGMA index_info("' . $key['name'] . '")');
foreach ($keyInfo as $keyCol) {
@@ -130,7 +130,10 @@ public function connect() {
);
$this->connected = true;
} catch (PDOException $e) {
- throw new MissingConnectionException(array('class' => $e->getMessage()));
+ throw new MissingConnectionException(array(
+ 'class' => get_class($this),
+ 'message' => $e->getMessage()
+ ));
}
return $this->connected;
@@ -253,6 +253,7 @@ public function __construct($config = null, $autoConnect = true) {
if (!$this->enabled()) {
throw new MissingConnectionException(array(
'class' => get_class($this),
+ 'message' => __d('cake_dev', 'Selected driver is not enabled'),
'enabled' => false
));
}
@@ -1294,9 +1295,9 @@ public function queryAssociation(Model $model, &$linkModel, $type, $association,
}
}
if ($type === 'hasAndBelongsToMany') {
- $uniqueIds = $merge = array();
+ $merge = array();
- foreach ($fetch as $j => $data) {
+ foreach ($fetch as $data) {
if (isset($data[$with]) && $data[$with][$foreignKey] === $row[$modelAlias][$modelPK]) {
if ($habtmFieldsCount <= 2) {
unset($data[$with]);
@@ -1445,7 +1446,7 @@ protected function _mergeAssociation(&$data, &$merge, $association, $type, $self
$data[$association] = array();
}
} else {
- foreach ($merge as $i => $row) {
+ foreach ($merge as $row) {
$insert = array();
if (count($row) === 1) {
$insert = $row[$association];
@@ -2413,7 +2414,7 @@ public function conditions($conditions, $quoteValues = true, $where = true, $mod
}
$clauses = '/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i';
- if (preg_match($clauses, $conditions, $match)) {
+ if (preg_match($clauses, $conditions)) {
$clause = '';
}
$conditions = $this->_quoteFields($conditions);
@@ -2908,7 +2909,7 @@ public function insertMulti($table, $fields, $values) {
$columnMap[$key] = $pdoMap[$type];
}
- foreach ($values as $row => $value) {
+ foreach ($values as $value) {
$i = 1;
foreach ($value as $col => $val) {
$statement->bindValue($i, $val, $columnMap[$col]);
@@ -3220,7 +3221,7 @@ public function introspectType($value) {
$isAllFloat = $isAllInt = true;
$containsFloat = $containsInt = $containsString = false;
- foreach ($value as $key => $valElement) {
+ foreach ($value as $valElement) {
$valElement = trim($valElement);
if (!is_float($valElement) && !preg_match('/^[\d]+\.[\d]+$/', $valElement)) {
$isAllFloat = false;
View
@@ -2374,7 +2374,7 @@ public function delete($id = null, $cascade = true) {
$updateCounterCache = false;
if (!empty($this->belongsTo)) {
- foreach ($this->belongsTo as $parent => $assoc) {
+ foreach ($this->belongsTo as $assoc) {
if (!empty($assoc['counterCache'])) {
$updateCounterCache = true;
break;
@@ -2460,7 +2460,7 @@ protected function _deleteDependent($id, $cascade) {
* @return void
*/
protected function _deleteLinks($id) {
- foreach ($this->hasAndBelongsToMany as $assoc => $data) {
+ foreach ($this->hasAndBelongsToMany as $data) {
list($plugin, $joinModel) = pluginSplit($data['with']);
$records = $this->{$joinModel}->find('all', array(
'conditions' => array($this->{$joinModel}->escapeField($data['foreignKey']) => $id),
@@ -3053,7 +3053,7 @@ public function invalidate($field, $value = true) {
public function isForeignKey($field) {
$foreignKeys = array();
if (!empty($this->belongsTo)) {
- foreach ($this->belongsTo as $assoc => $data) {
+ foreach ($this->belongsTo as $data) {
$foreignKeys[] = $data['foreignKey'];
}
}
@@ -18,8 +18,7 @@
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-App::uses('ModelValidator', 'Model');
-App::uses('CakeValidationSet', 'Model/Validator');
+
App::uses('Validation', 'Utility');
/**
@@ -18,7 +18,7 @@
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-App::uses('ModelValidator', 'Model');
+
App::uses('CakeValidationRule', 'Model/Validator');
/**
@@ -675,7 +675,7 @@ public function subdomains($tldLength = 1) {
public function accepts($type = null) {
$raw = $this->parseAccept();
$accept = array();
- foreach ($raw as $value => $types) {
+ foreach ($raw as $types) {
$accept = array_merge($accept, $types);
}
if ($type === null) {
@@ -41,14 +41,31 @@ public function send(CakeEmail $email) {
unset($headers['To']);
$headers = $this->_headersToString($headers, $eol);
$message = implode($eol, $email->message());
- if (ini_get('safe_mode') || !isset($this->_config['additionalParameters'])) {
- if (!@mail($to, $email->subject(), $message, $headers)) {
- throw new SocketException(__d('cake_dev', 'Could not send email.'));
- }
- } elseif (!@mail($to, $email->subject(), $message, $headers, $this->_config['additionalParameters'])) {
- throw new SocketException(__d('cake_dev', 'Could not send email.'));
+
+ $params = null;
+ if (!ini_get('safe_mode')) {
+ $params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : null;
}
+
+ $this->_mail($to, $email->subject(), $message, $headers, $params);
return array('headers' => $headers, 'message' => $message);
}
+/**
+ * Wraps internal function mail() and throws exception instead of errors if anything goes wrong
+ *
+ * @param string $to email's recipient
+ * @param string $subject email's subject
+ * @param string $message email's body
+ * @param string $headers email's custom headers
+ * @param string $params additional params for sending email
+ * @throws SocketException if mail could not be sent
+ * @return void
+ */
+ protected function _mail($to, $subject, $message, $headers, $params = null) {
+ if (!@mail($to, $subject, $message, $headers, $params)) {
+ throw new SocketException(__d('cake_dev', 'Could not send email.'));
+ }
+ }
+
}
@@ -523,7 +523,7 @@ public static function parse($url) {
$ext = null;
$out = array();
- if ($url && strpos($url, '/') !== 0) {
+ if (strlen($url) && strpos($url, '/') !== 0) {
$url = '/' . $url;
}
if (strpos($url, '?') !== false) {
Oops, something went wrong.

0 comments on commit d5c9d97

Please sign in to comment.