/** * Prepares the Schema objects for database operations. * * @return void */ protected function _loadSchema() { $name = $plugin = null; if (!empty($this->params['name'])) { $name = $this->params['name']; } if (!empty($this->params['plugin'])) { $plugin = $this->params['plugin']; } if (!empty($this->params['dry'])) { $this->_dry = true; $this->out(__d('cake_console', 'Performing a dry run.')); } $options = array('name' => $name, 'plugin' => $plugin); if (!empty($this->params['snapshot'])) { $fileName = rtrim($this->Schema->file, '.php'); $options['file'] = $fileName . '_' . $this->params['snapshot'] . '.php'; } $Schema = $this->Schema->load($options); if (!$Schema) { $this->err(__d('cake_console', 'The chosen schema could not be loaded. Attempted to load:')); $this->err(__d('cake_console', 'File: %s', $this->Schema->path . DS . $this->Schema->file)); $this->err(__d('cake_console', 'Name: %s', $this->Schema->name)); $this->_stop(); } $table = null; if (isset($this->args[1])) { $table = $this->args[1]; } return array(&$Schema, $table); }
/** * Prepares the Schema objects for database operations. * * @return void */ function _loadSchema() { $name = $plugin = null; if (!empty($this->params['name'])) { $name = $this->params['name']; } if (!empty($this->params['plugin'])) { $plugin = $this->params['plugin']; } if (!empty($this->params['dry'])) { $this->__dry = true; $this->out(__('Performing a dry run.')); } $options = array('name' => $name, 'plugin' => $plugin); if (!empty($this->params['snapshot'])) { $fileName = rtrim($this->Schema->file, '.php'); $options['file'] = $fileName . '_' . $this->params['snapshot'] . '.php'; } $Schema = $this->Schema->load($options); if (!$Schema) { $this->err(__('%s could not be loaded', $this->Schema->path . DS . $this->Schema->file)); $this->_stop(); } $table = null; if (isset($this->args[1])) { $table = $this->args[1]; } return array(&$Schema, $table); }
/** * Prepares the Schema objects for database operations. * * @return void */ protected function _loadSchema() { $name = $plugin = NULL; if (!empty($this->params['name'])) { $name = $this->params['name']; } if (!empty($this->params['plugin'])) { $plugin = $this->params['plugin']; } if (!empty($this->params['dry'])) { $this->_dry = TRUE; $this->out(__d('cake_console', 'Performing a dry run.')); } $options = array('name' => $name, 'plugin' => $plugin, 'connection' => $this->params['connection']); if (!empty($this->params['snapshot'])) { $fileName = basename($this->Schema->file, '.php'); $options['file'] = $fileName . '_' . $this->params['snapshot'] . '.php'; } $Schema = $this->Schema->load($options); if (!$Schema) { $this->err(__d('cake_console', '<error>Error</error>: The chosen schema could not be loaded. Attempted to load:')); $this->err(__d('cake_console', '- file: %s', $this->Schema->path . DS . $this->Schema->file)); $this->err(__d('cake_console', '- name: %s', $this->Schema->name)); return $this->_stop(2); } $table = NULL; if (isset($this->args[1])) { $table = $this->args[1]; } return array(&$Schema, $table); }
/** * Prepares the Schema objects for database operations. * * @return void */ protected function _loadSchema() { $name = $plugin = null; if (!empty($this->params['name'])) { $name = $this->params['name']; } if (!empty($this->params['plugin'])) { $plugin = $this->params['plugin']; } if (!empty($this->params['dry'])) { $this->_dry = true; $this->_out(__d('cake_console', 'Performing a dry run.')); } $options = array('name' => $name, 'plugin' => $plugin); if (!empty($this->params['snapshot'])) { $fileName = rtrim($this->Schema->file, '.php'); $options['file'] = $fileName . '_' . $this->params['snapshot'] . '.php'; } $Schema = $this->Schema->load($options); if (!$Schema) { $this->message[] = __(' ( %s has no database schema ) ', $options['name']); //$this->message[] = __(' ( could not load %s database schema ) ', $options['name']); //$this->_redirect($this->referer()); } $table = null; if (isset($this->args[1])) { $table = $this->args[1]; } return array(&$Schema, $table); }
/** * Creates the schema. * * NOTE: adapted from the schema shell lib/Cake/Console/Command/SchemaShell.php * * @return mixed false on failure, otherwise a string message */ protected function _createSchema() { App::uses('ConnectionManager', 'Model'); App::uses('CakeSchema', 'Model'); $db = ConnectionManager::getDataSource('default'); $CakeSchema = new CakeSchema(array('name' => 'App', 'connection' => $db)); $Schema = $CakeSchema->load(); if (!$Schema) { $this->error(sprintf('Schema could not be loaded: %s', $CakeSchema->path . DS . $CakeSchema->file)); return false; } $out = ''; $drop = $create = array(); foreach ($Schema->tables as $table => $fields) { $drop[$table] = $db->dropSchema($Schema, $table); $create[$table] = $db->createSchema($Schema, $table); } if (empty($drop) || empty($create)) { $out .= 'Schema is up to date.'; return $out; } $out .= "\n" . 'The following table(s) will be dropped.'; $out .= "\n" . implode(", ", array_keys($drop)); $out .= "\n" . 'Dropping table(s).'; $result = $this->_runSchema($db, $drop, 'drop', $Schema); if ($result === false) { return false; } else { $out .= $result; } $out .= "\n" . 'The following table(s) will be created.'; $out .= "\n" . implode(", ", array_keys($create)); $out .= "\n" . 'Creating table(s).'; $result = $this->_runSchema($db, $create, 'create', $Schema); if ($result === false) { return false; } else { $out .= $result; } $out .= "\n" . 'End create.'; $this->log($out); return true; }