mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch '2.0' of github.com:cakephp/cakephp into 2.0
This commit is contained in:
commit
ca0dccb1e7
4 changed files with 102 additions and 18 deletions
|
@ -229,6 +229,10 @@ class CakeSchema extends Object {
|
|||
foreach ($models as $model) {
|
||||
$importModel = $model;
|
||||
$plugin = null;
|
||||
if ($model == 'AppModel') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($this->plugin)) {
|
||||
if ($model == $this->plugin . 'AppModel') {
|
||||
continue;
|
||||
|
|
|
@ -2110,10 +2110,42 @@ class Model extends Object {
|
|||
$this->findQueryType = $type;
|
||||
$this->id = $this->getID();
|
||||
|
||||
$query = $this->buildQuery($type, $query);
|
||||
if (is_null($query)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$results = $this->getDataSource()->read($this, $query);
|
||||
$this->resetAssociations();
|
||||
|
||||
if ($query['callbacks'] === true || $query['callbacks'] === 'after') {
|
||||
$results = $this->_filterResults($results);
|
||||
}
|
||||
|
||||
$this->findQueryType = null;
|
||||
|
||||
if ($type === 'all') {
|
||||
return $results;
|
||||
} else {
|
||||
if ($this->findMethods[$type] === true) {
|
||||
return $this->{'_find' . ucfirst($type)}('after', $query, $results);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the query array that is used by the data source to generate the query to fetch the data.
|
||||
*
|
||||
* @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
|
||||
* @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
|
||||
* @return array Query array or null if it could not be build for some reasons
|
||||
* @see Model::find()
|
||||
*/
|
||||
public function buildQuery($type = 'first', $query = array()) {
|
||||
$query = array_merge(
|
||||
array(
|
||||
'conditions' => null, 'fields' => null, 'joins' => array(), 'limit' => null,
|
||||
'offset' => null, 'order' => null, 'page' => 1, 'group' => null, 'callbacks' => true
|
||||
'offset' => null, 'order' => null, 'page' => 1, 'group' => null, 'callbacks' => true,
|
||||
),
|
||||
(array)$query
|
||||
);
|
||||
|
@ -2156,22 +2188,7 @@ class Model extends Object {
|
|||
}
|
||||
}
|
||||
|
||||
$results = $this->getDataSource()->read($this, $query);
|
||||
$this->resetAssociations();
|
||||
|
||||
if ($query['callbacks'] === true || $query['callbacks'] === 'after') {
|
||||
$results = $this->_filterResults($results);
|
||||
}
|
||||
|
||||
$this->findQueryType = null;
|
||||
|
||||
if ($type === 'all') {
|
||||
return $results;
|
||||
} else {
|
||||
if ($this->findMethods[$type] === true) {
|
||||
return $this->{'_find' . ucfirst($type)}('after', $query, $results);
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -603,6 +603,41 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
$this->assertFalse(isset($read['tables']['missing']['posts_tags']), 'Join table marked as missing');
|
||||
}
|
||||
|
||||
/**
|
||||
* testSchemaReadWithAppModel method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function testSchemaReadWithAppModel() {
|
||||
$connections = ConnectionManager::enumConnectionObjects();
|
||||
if (!empty($connections['default'])) {
|
||||
$backup = $connections['default'];
|
||||
ConnectionManager::drop('default');
|
||||
}
|
||||
ConnectionManager::create('default', $connections['test']);
|
||||
try {
|
||||
$read = $this->Schema->read(array(
|
||||
'connection' => 'default',
|
||||
'name' => 'TestApp',
|
||||
'models' => array('AppModel')
|
||||
));
|
||||
unset($read['tables']['missing']);
|
||||
$this->assertTrue(empty($read['tables']));
|
||||
if (!empty($backup)) {
|
||||
ConnectionManager::drop('default');
|
||||
ConnectionManager::create('default', $backup);
|
||||
}
|
||||
} catch(MissingTableException $mte) {
|
||||
if (!empty($backup)) {
|
||||
ConnectionManager::drop('default');
|
||||
ConnectionManager::create('default', $backup);
|
||||
}
|
||||
$this->fail($mte->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* testSchemaReadWithOddTablePrefix method
|
||||
*
|
||||
|
|
|
@ -6010,6 +6010,34 @@ class ModelReadTest extends BaseModelTest {
|
|||
$this->assertTrue(empty($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* test buildQuery()
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildQuery() {
|
||||
$this->loadFixtures('User');
|
||||
$TestModel = new User();
|
||||
$TestModel->cacheQueries = false;
|
||||
|
||||
$expected = array(
|
||||
'conditions' => array(
|
||||
'user' => 'larry'),
|
||||
'fields' => NULL,
|
||||
'joins' => array (),
|
||||
'limit' => NULL,
|
||||
'offset' => NULL,
|
||||
'order' => array(
|
||||
0 => NULL),
|
||||
'page' => 1,
|
||||
'group' => NULL,
|
||||
'callbacks' => true,
|
||||
'returnQuery' => true);
|
||||
$result = $TestModel->buildQuery('all', array('returnQuery' => true, 'conditions' => array('user' => 'larry')));
|
||||
$this->assertEqual($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test find('all') method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue