Skip to content

Commit

Permalink
Cake to v2.10.10
Browse files Browse the repository at this point in the history
  • Loading branch information
boshrin committed May 30, 2018
1 parent 434f156 commit 2fe02b3
Show file tree
Hide file tree
Showing 29 changed files with 322 additions and 53 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Cache/CacheEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function key($key) {

$prefix = '';
if (!empty($this->_groupPrefix)) {
$prefix = vsprintf($this->_groupPrefix, $this->groups());
$prefix = md5(implode('_', $this->groups()));
}

$key = preg_replace('/[\s]+/', '_', strtolower(trim(str_replace(array(DS, '/', '.'), '_', strval($key)))));
Expand Down
6 changes: 6 additions & 0 deletions lib/Cake/Console/Command/Task/ControllerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ public function bakeActions($controllerName, $admin = null, $wannaUseSession = t
public function bake($controllerName, $actions = '', $helpers = null, $components = null) {
$this->out("\n" . __d('cake_console', 'Baking controller class for %s...', $controllerName), 1, Shell::QUIET);

if ($helpers === null) {
$helpers = array();
}
if ($components === null) {
$components = array();
}
$isScaffold = ($actions === 'scaffold') ? true : false;

$this->Template->set(array(
Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/I18n/L10n.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class L10n {
/* Latvian */ 'lav' => 'lv',
/* Limburgish */ 'lim' => 'li',
/* Lithuanian */ 'lit' => 'lt',
/* Luxembourgish */ 'ltz' => 'lb',
/* Macedonian */ 'mkd' => 'mk',
/* Macedonian - bibliographic */ 'mac' => 'mk',
/* Malaysian */ 'msa' => 'ms',
Expand Down Expand Up @@ -284,6 +285,7 @@ class L10n {
'ko-kp' => array('language' => 'Korea (North)', 'locale' => 'ko_kp', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
'ko-kr' => array('language' => 'Korea (South)', 'locale' => 'ko_kr', 'localeFallback' => 'kor', 'charset' => 'kr', 'direction' => 'ltr'),
'koi8-r' => array('language' => 'Russian', 'locale' => 'koi8_r', 'localeFallback' => 'rus', 'charset' => 'koi8-r', 'direction' => 'ltr'),
'lb' => array('language' => 'Luxembourgish', 'locale' => 'ltz', 'localeFallback' => 'ltz', 'charset' => 'utf-8', 'direction' => 'ltr'),
'li' => array('language' => 'Limburgish', 'locale' => 'lim', 'localeFallback' => 'nld', 'charset' => 'utf-8', 'direction' => 'ltr'),
'lt' => array('language' => 'Lithuanian', 'locale' => 'lit', 'localeFallback' => 'lit', 'charset' => 'utf-8', 'direction' => 'ltr'),
'lv' => array('language' => 'Latvian', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8', 'direction' => 'ltr'),
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/I18n/Multibyte.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public static function strtolower($string) {

if (!empty($keys)) {
foreach ($keys as $key => $value) {
if ($keys[$key]['upper'] == $char && count($keys[$key]['lower'][0]) === 1) {
if ($keys[$key]['upper'] == $char && count($keys[$key]['lower']) > 0) {
$lowerCase[] = $keys[$key]['lower'][0];
$matched = true;
break 1;
Expand Down
6 changes: 6 additions & 0 deletions lib/Cake/Model/Datasource/CakeSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ protected static function _configureSession() {

if (!empty($sessionConfig['handler'])) {
$sessionConfig['ini']['session.save_handler'] = 'user';

// In PHP7.2.0+ session.save_handler can't be set to 'user' by the user.
// https://github.com/php/php-src/commit/a93a51c3bf4ea1638ce0adc4a899cb93531b9f0d
if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
unset($sessionConfig['ini']['session.save_handler']);
}
} elseif (!empty($sessionConfig['session.save_path']) && Configure::read('debug')) {
if (!is_dir($sessionConfig['session.save_path'])) {
mkdir($sessionConfig['session.save_path'], 0775, true);
Expand Down
4 changes: 4 additions & 0 deletions lib/Cake/Model/Datasource/Database/Sqlserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ public function fields(Model $model, $alias = null, $fields = array(), $quote =
$prepend = 'DISTINCT ';
$fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i]));
}
if (strpos($fields[$i], 'COUNT(DISTINCT') !== false) {
$prepend = 'COUNT(DISTINCT ';
$fields[$i] = trim(str_replace('COUNT(DISTINCT', '', $this->_quoteFields($fields[$i])));
}

if (!preg_match('/\s+AS\s+/i', $fields[$i])) {
if (substr($fields[$i], -1) === '*') {
Expand Down
48 changes: 30 additions & 18 deletions lib/Cake/Model/Datasource/DboSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ protected function _execute($sql, $params = array(), $prepareOptions = array())
$query = $this->_connection->prepare($sql, $prepareOptions);
$query->setFetchMode(PDO::FETCH_LAZY);
if (!$query->execute($params)) {
$this->_results = $query;
$this->_result = $query;
$query->closeCursor();
return false;
}
Expand Down Expand Up @@ -1566,23 +1566,25 @@ protected function _mergeHasMany(&$resultSet, $assocResultSet, $association, Mod
// Make one pass through children and collect by parent key
// Make second pass through parents and associate children
$mergedByFK = array();
foreach ($assocResultSet as $data) {
$fk = $data[$association][$foreignKey];
if (! array_key_exists($fk, $mergedByFK)) {
$mergedByFK[$fk] = array();
}
if (count($data) > 1) {
$data = array_merge($data[$association], $data);
unset($data[$association]);
foreach ($data as $key => $name) {
if (is_numeric($key)) {
$data[$association][] = $name;
unset($data[$key]);
if (is_array($assocResultSet)) {
foreach ($assocResultSet as $data) {
$fk = $data[$association][$foreignKey];
if (! array_key_exists($fk, $mergedByFK)) {
$mergedByFK[$fk] = array();
}
if (count($data) > 1) {
$data = array_merge($data[$association], $data);
unset($data[$association]);
foreach ($data as $key => $name) {
if (is_numeric($key)) {
$data[$association][] = $name;
unset($data[$key]);
}
}
$mergedByFK[$fk][] = $data;
} else {
$mergedByFK[$fk][] = $data[$association];
}
$mergedByFK[$fk][] = $data;
} else {
$mergedByFK[$fk][] = $data[$association];
}
}

Expand Down Expand Up @@ -2576,7 +2578,12 @@ protected function _constructVirtualFields(Model $Model, $alias, $fields) {
$virtual = array();
foreach ($fields as $field) {
$virtualField = $this->name($alias . $this->virtualFieldSeparator . $field);
$expression = $this->_quoteFields($Model->getVirtualField($field));
$virtualFieldExpression = $Model->getVirtualField($field);
if (is_object($virtualFieldExpression) && $virtualFieldExpression->type == 'expression') {
$expression = $virtualFieldExpression->value;
} else {
$expression = $this->_quoteFields($virtualFieldExpression);
}
$virtual[] = '(' . $expression . ") {$this->alias} {$virtualField}";
}
return $virtual;
Expand Down Expand Up @@ -2885,7 +2892,12 @@ protected function _parseKey($key, $value, Model $Model = null) {

if ($Model !== null) {
if ($Model->isVirtualField($key)) {
$key = $this->_quoteFields($Model->getVirtualField($key));
$virtualField = $Model->getVirtualField($key);
if (is_object($virtualField) && $virtualField->type == 'expression') {
$key = $virtualField->value;
} else {
$key = $this->_quoteFields($virtualField);
}
$virtual = true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/ModelValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public function remove($field, $rule = null) {
$this->_parseRules();
if ($rule === null) {
unset($this->_fields[$field]);
} else {
} elseif (array_key_exists($field, $this->_fields)) {
$this->_fields[$field]->removeRule($rule);
}
return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ public function tearDown() {
TestAuthComponent::clearUser();
$this->Auth->Session->delete('Auth');
$this->Auth->Session->delete('Message.auth');
$this->Auth->Session->destroy();
unset($this->Controller, $this->Auth);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ class ControllerPaginateModel extends CakeTestModel {
/**
* paginate method
*
* @return bool
* @return array
*/
public function paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra) {
$this->extra = $extra;
return true;
return array(true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public function setUp() {
public function tearDown() {
parent::tearDown();
$this->Controller->Session->delete('_Token');
$this->Controller->Session->destroy();
unset($this->Controller->Security);
unset($this->Controller->Component);
unset($this->Controller);
Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/Test/Case/Controller/ScaffoldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

App::uses('Router', 'Routing');
App::uses('CakeSession', 'Model/Datasource');
App::uses('Controller', 'Controller');
App::uses('Scaffold', 'Controller');
App::uses('ScaffoldView', 'View');
Expand Down Expand Up @@ -175,6 +176,7 @@ public function setUp() {
*/
public function tearDown() {
parent::tearDown();
CakeSession::destroy();
unset($this->Controller);
}

Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Test/Case/I18n/I18nTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function tearDown() {
parent::tearDown();

Cache::delete('object_map', '_cake_core_');
CakeSession::destroy();
App::build();
CakePlugin::unload();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Model/ConnectionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testGetDataSource() {

ConnectionManager::create($name, $config);
$connections = ConnectionManager::enumConnectionObjects();
$this->assertTrue((bool)(count(array_keys($connections) >= 1)));
$this->assertTrue(count(array_keys($connections)) >= 1);

$source = ConnectionManager::getDataSource('test_get_datasource');
$this->assertTrue(is_object($source));
Expand Down Expand Up @@ -239,7 +239,7 @@ public function testCreateDataSourceWithIntegrationTests() {
$name = 'test_created_connection';

$connections = ConnectionManager::enumConnectionObjects();
$this->assertTrue((bool)(count(array_keys($connections) >= 1)));
$this->assertTrue(count(array_keys($connections)) >= 1);

$source = ConnectionManager::getDataSource('test');
$this->assertTrue(is_object($source));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ public function testDistinctFields() {
$result = $this->db->fields($this->model, null, 'DISTINCT Car.country_code');
$expected = array('DISTINCT [Car].[country_code] AS [Car__country_code]');
$this->assertEquals($expected, $result);

$result = $this->db->fields($this->model, null, 'COUNT(DISTINCT Car.country_code)');
$expected = array('COUNT(DISTINCT [Car].[country_code]) AS [Car__country_code]');
$this->assertEquals($expected, $result);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,42 @@ public function testConditionKeysToString() {
$this->assertEquals($expected, $result[0]);
}

/**
* Test conditionKeysToString() with virtual field
*
* @return void
*/
public function testConditionKeysToStringVirtualFieldExpression() {
$Article = ClassRegistry::init('Article');
$Article->virtualFields = array(
'extra' => $Article->getDataSource()->expression('something virtual')
);
$conn = $this->getMock('MockPDO', array('quote'));
$db = new DboTestSource();
$db->setConnection($conn);

$conn->expects($this->at(0))
->method('quote')
->will($this->returnValue('just text'));

$conditions = array('Article.extra' => 'just text');
$result = $db->conditionKeysToString($conditions, true, $Article);
$expected = "(" . $Article->virtualFields['extra']->value . ") = just text";
$this->assertEquals($expected, $result[0]);

$conn->expects($this->at(0))
->method('quote')
->will($this->returnValue('just text'));
$conn->expects($this->at(1))
->method('quote')
->will($this->returnValue('other text'));

$conditions = array('Article.extra' => array('just text', 'other text'));
$result = $db->conditionKeysToString($conditions, true, $Article);
$expected = "(" . $Article->virtualFields['extra']->value . ") IN (just text, other text)";
$this->assertEquals($expected, $result[0]);
}

/**
* Test conditionKeysToString() with virtual field
*
Expand Down
3 changes: 3 additions & 0 deletions lib/Cake/Test/Case/Model/ModelValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,9 @@ public function testRemoveRule() {
$this->assertTrue(isset($Validator['other']));
$this->assertFalse(isset($Validator['other']['numeric']));
$this->assertTrue(isset($Validator['other']['between']));

$Validator->remove('other');
$Validator->remove('other', 'between');
}

/**
Expand Down
12 changes: 8 additions & 4 deletions lib/Cake/Test/Case/Model/ModelWriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3367,7 +3367,9 @@ public function testSaveAllHabtm() {
array(
'comment' => 'Article comment',
'user_id' => 1
)));
)
)
);
$Article = new Article();
$result = $Article->saveAll($data);
$this->assertFalse(empty($result));
Expand All @@ -3376,7 +3378,7 @@ public function testSaveAllHabtm() {
$this->assertEquals(2, count($result['Tag']));
$this->assertEquals('tag1', $result['Tag'][0]['tag']);
$this->assertEquals(1, count($result['Comment']));
$this->assertEquals(1, count($result['Comment'][0]['comment']));
$this->assertEquals('Article comment', $result['Comment'][0]['comment']);
}

/**
Expand Down Expand Up @@ -5647,7 +5649,9 @@ public function testSaveAssociatedHabtm() {
array(
'comment' => 'Article comment',
'user_id' => 1
)));
)
)
);
$Article = new Article();
$result = $Article->saveAssociated($data);
$this->assertFalse(empty($result));
Expand All @@ -5656,7 +5660,7 @@ public function testSaveAssociatedHabtm() {
$this->assertEquals(2, count($result['Tag']));
$this->assertEquals('tag1', $result['Tag'][0]['tag']);
$this->assertEquals(1, count($result['Comment']));
$this->assertEquals(1, count($result['Comment'][0]['comment']));
$this->assertEquals('Article comment', $result['Comment'][0]['comment']);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ public function testGetMockForModelSecondaryDatasource() {
), App::RESET);
CakePlugin::load('TestPlugin');
ConnectionManager::create('test_secondary', array(
'datasource' => 'Database/TestLocalDriver'
'datasource' => 'Database/TestLocalDriver',
'prefix' => ''
));
$post = $this->getMockForModel('SecondaryPost', array('save'));
$this->assertEquals('test_secondary', $post->useDbConfig);
Expand Down
Loading

0 comments on commit 2fe02b3

Please sign in to comment.