mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
updating schema create
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6171 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
1e89fd676b
commit
1d6a63a29a
1 changed files with 35 additions and 6 deletions
|
@ -221,6 +221,7 @@ class SchemaShell extends Shell {
|
||||||
}
|
}
|
||||||
|
|
||||||
$Schema = $this->Schema->load($options);
|
$Schema = $this->Schema->load($options);
|
||||||
|
|
||||||
if (!$Schema) {
|
if (!$Schema) {
|
||||||
$this->err(sprintf(__('%s could not be loaded', true), $this->Schema->file));
|
$this->err(sprintf(__('%s could not be loaded', true), $this->Schema->file));
|
||||||
exit();
|
exit();
|
||||||
|
@ -252,14 +253,38 @@ class SchemaShell extends Shell {
|
||||||
function __create($Schema, $table = null) {
|
function __create($Schema, $table = null) {
|
||||||
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
||||||
|
|
||||||
$drop = $db->dropSchema($Schema, $table);
|
$drop = $create = array();
|
||||||
|
|
||||||
$this->out($drop);
|
if (!$table) {
|
||||||
if ('y' == $this->in(__('Are you sure you want to drop and create the tables?', true), array('y', 'n'), 'n')) {
|
foreach ($Schema->tables as $table => $fields) {
|
||||||
$create = $db->createSchema($Schema, $table);
|
$drop[$table] = $db->dropSchema($Schema, $table);
|
||||||
$this->out('Updating Database...');
|
$create[$table] = $db->createSchema($Schema, $table);
|
||||||
$this->__run($drop . $create, 'create');
|
}
|
||||||
|
} elseif (isset($Schema->tables[$table])) {
|
||||||
|
$drop[$table] = $db->dropSchema($Schema, $table);
|
||||||
|
$create[$table] = $db->createSchema($Schema, $table);
|
||||||
}
|
}
|
||||||
|
if (empty($drop) || empty($create)) {
|
||||||
|
$this->out(__('Schema is up to date.', true));
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->out("\n" . __('The following tables will drop.', true));
|
||||||
|
$this->out(array_keys($drop));
|
||||||
|
|
||||||
|
if ('y' == $this->in(__('Are you sure you want to drop the tables?', true), array('y', 'n'), 'n')) {
|
||||||
|
$this->out('Dropping tables.');
|
||||||
|
$this->__run($drop, 'drop');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->out("\n" . __('The following tables will create.', true));
|
||||||
|
$this->out(array_keys($create));
|
||||||
|
|
||||||
|
if ('y' == $this->in(__('Are you sure you want to create the tables?', true), array('y', 'n'), 'y')) {
|
||||||
|
$this->out('Creating tables.');
|
||||||
|
$this->__run($create, 'create');
|
||||||
|
}
|
||||||
|
|
||||||
$this->out(__('End create.', true));
|
$this->out(__('End create.', true));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -306,6 +331,10 @@ class SchemaShell extends Shell {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __run($contents, $event) {
|
function __run($contents, $event) {
|
||||||
|
if (empty($contents)) {
|
||||||
|
$this->err(__('Sql could not be run', true));
|
||||||
|
return;
|
||||||
|
}
|
||||||
Configure::write('debug', 2);
|
Configure::write('debug', 2);
|
||||||
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
$db =& ConnectionManager::getDataSource($this->Schema->connection);
|
||||||
$db->fullDebug = true;
|
$db->fullDebug = true;
|
||||||
|
|
Loading…
Reference in a new issue