mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Removing cake schema run
. Replacing it with cake schema create
and cake schema update
. Removes extra typing and simplifies schema shell commands.
Updating test cases.
This commit is contained in:
parent
e1d0be610c
commit
c2a53d3c69
2 changed files with 30 additions and 35 deletions
|
@ -238,20 +238,31 @@ class SchemaShell extends Shell {
|
|||
}
|
||||
|
||||
/**
|
||||
* Run database commands: create, update
|
||||
* Run database create commands. Alias for run create.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function run() {
|
||||
if (!isset($this->args[0])) {
|
||||
$this->err(__('Command not found', true));
|
||||
$this->_stop();
|
||||
}
|
||||
* @return void
|
||||
**/
|
||||
function create() {
|
||||
list($Schema, $table) = $this->_loadSchema();
|
||||
$this->__create($Schema, $table);
|
||||
}
|
||||
|
||||
$command = $this->args[0];
|
||||
|
||||
$this->Dispatch->shiftArgs();
|
||||
/**
|
||||
* Run database create commands. Alias for run create.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function update() {
|
||||
list($Schema, $table) = $this->_loadSchema();
|
||||
$this->__update($Schema, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the Schema objects for database operations.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function _loadSchema() {
|
||||
$name = null;
|
||||
if (isset($this->args[0])) {
|
||||
$name = $this->args[0];
|
||||
|
@ -271,29 +282,17 @@ class SchemaShell extends Shell {
|
|||
$options['file'] = $fileName . '_' . $this->params['s'] . '.php';
|
||||
}
|
||||
|
||||
$Schema = $this->Schema->load($options);
|
||||
$Schema =& $this->Schema->load($options);
|
||||
|
||||
if (!$Schema) {
|
||||
$this->err(sprintf(__('%s could not be loaded', true), $this->Schema->file));
|
||||
$this->_stop();
|
||||
}
|
||||
|
||||
$table = null;
|
||||
if (isset($this->args[1])) {
|
||||
$table = $this->args[1];
|
||||
}
|
||||
|
||||
switch ($command) {
|
||||
case 'create':
|
||||
$this->__create($Schema, $table);
|
||||
break;
|
||||
case 'update':
|
||||
$this->__update($Schema, $table);
|
||||
break;
|
||||
default:
|
||||
$this->err(__('Command not found', true));
|
||||
$this->_stop();
|
||||
}
|
||||
return array(&$Schema, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -336,7 +335,6 @@ class SchemaShell extends Shell {
|
|||
$this->out(__('Creating table(s).', true));
|
||||
$this->__run($create, 'create', $Schema);
|
||||
}
|
||||
|
||||
$this->out(__('End create.', true));
|
||||
}
|
||||
|
||||
|
@ -395,7 +393,6 @@ class SchemaShell extends Shell {
|
|||
}
|
||||
Configure::write('debug', 2);
|
||||
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
||||
$db->fullDebug = true;
|
||||
|
||||
foreach ($contents as $table => $sql) {
|
||||
if (empty($sql)) {
|
||||
|
|
|
@ -289,13 +289,12 @@ class SchemaShellTest extends CakeTestCase {
|
|||
function testRunCreateNoArgs() {
|
||||
$this->Shell->params = array(
|
||||
'connection' => 'test_suite',
|
||||
'name' => 'i18n',
|
||||
'path' => APP . 'config' . DS . 'sql'
|
||||
);
|
||||
$this->Shell->args = array('create');
|
||||
$this->Shell->args = array('i18n');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->setReturnValue('in', 'y');
|
||||
$this->Shell->run();
|
||||
$this->Shell->create();
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$sources = $db->listSources();
|
||||
|
@ -316,10 +315,10 @@ class SchemaShellTest extends CakeTestCase {
|
|||
'name' => 'DbAcl',
|
||||
'path' => APP . 'config' . DS . 'schema'
|
||||
);
|
||||
$this->Shell->args = array('create', 'acos');
|
||||
$this->Shell->args = array('DbAcl', 'acos');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->setReturnValue('in', 'y');
|
||||
$this->Shell->run();
|
||||
$this->Shell->create();
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$sources = $db->listSources();
|
||||
|
@ -337,14 +336,13 @@ class SchemaShellTest extends CakeTestCase {
|
|||
**/
|
||||
function testRunUpdateWithTable() {
|
||||
$this->Shell->params = array(
|
||||
'name' => 'SchemaShellTest',
|
||||
'connection' => 'test_suite',
|
||||
'f' => true
|
||||
);
|
||||
$this->Shell->args = array('update', 'articles');
|
||||
$this->Shell->args = array('SchemaShellTest', 'articles');
|
||||
$this->Shell->startup();
|
||||
$this->Shell->setReturnValue('in', 'y');
|
||||
$this->Shell->run();
|
||||
$this->Shell->update();
|
||||
|
||||
$article =& new Model(array('name' => 'Article', 'ds' => 'test_suite'));
|
||||
$fields = $article->schema();
|
||||
|
|
Loading…
Add table
Reference in a new issue