mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #4230 from beporter/bug/schemashell-name-file-params-fix
SchemaShell --name and --file params priority fix. Fixes #4174
This commit is contained in:
commit
f1d01732a5
3 changed files with 27 additions and 32 deletions
|
@ -66,13 +66,10 @@ class SchemaShell extends AppShell {
|
|||
list($this->params['plugin'], $splitName) = pluginSplit($name);
|
||||
$name = $this->params['name'] = $splitName;
|
||||
}
|
||||
|
||||
$defaultFile = 'schema.php';
|
||||
if (empty($this->params['file'])) {
|
||||
$this->params['file'] = $defaultFile;
|
||||
}
|
||||
if ($name && $this->params['file'] === $defaultFile) {
|
||||
if ($name && empty($this->params['file'])) {
|
||||
$this->params['file'] = Inflector::underscore($name);
|
||||
} elseif (empty($this->params['file'])) {
|
||||
$this->params['file'] = 'schema.php';
|
||||
}
|
||||
if (strpos($this->params['file'], '.php') === false) {
|
||||
$this->params['file'] .= '.php';
|
||||
|
@ -483,7 +480,6 @@ class SchemaShell extends AppShell {
|
|||
);
|
||||
$file = array(
|
||||
'help' => __d('cake_console', 'File name to read and write.'),
|
||||
'default' => 'schema.php'
|
||||
);
|
||||
$name = array(
|
||||
'help' => __d('cake_console',
|
||||
|
|
|
@ -86,7 +86,7 @@ class CakeSchema extends Object {
|
|||
}
|
||||
|
||||
if (strtolower($this->name) === 'cake') {
|
||||
$this->name = Inflector::camelize(Inflector::slug(Configure::read('App.dir')));
|
||||
$this->name = 'App';
|
||||
}
|
||||
|
||||
if (empty($options['path'])) {
|
||||
|
@ -163,11 +163,10 @@ class CakeSchema extends Object {
|
|||
|
||||
$class = $name . 'Schema';
|
||||
|
||||
if (!class_exists($class)) {
|
||||
if (file_exists($path . DS . $file) && is_file($path . DS . $file)) {
|
||||
require_once $path . DS . $file;
|
||||
} elseif (file_exists($path . DS . 'schema.php') && is_file($path . DS . 'schema.php')) {
|
||||
require_once $path . DS . 'schema.php';
|
||||
if (!class_exists($class) && !$this->_requireFile($path, $file)) {
|
||||
$class = Inflector::camelize(Inflector::slug(Configure::read('App.dir'))) . 'Schema';
|
||||
if (!class_exists($class)) {
|
||||
$this->_requireFile($path, $file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -716,4 +715,22 @@ class CakeSchema extends Object {
|
|||
return preg_replace('/^' . preg_quote($prefix) . '/', '', $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to require the schema file specified
|
||||
*
|
||||
* @param string $path Filesystem path to the file
|
||||
* @param string $file Filesystem basename of the file
|
||||
* @return bool True when a file was successfully included, false on failure
|
||||
*/
|
||||
protected function _requireFile($path, $file) {
|
||||
if (file_exists($path . DS . $file) && is_file($path . DS . $file)) {
|
||||
require_once $path . DS . $file;
|
||||
return true;
|
||||
} elseif (file_exists($path . DS . 'schema.php') && is_file($path . DS . 'schema.php')) {
|
||||
require_once $path . DS . 'schema.php';
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -436,25 +436,7 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
*/
|
||||
public function testSchemaName() {
|
||||
$Schema = new CakeSchema();
|
||||
$this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $Schema->name);
|
||||
|
||||
Configure::write('App.dir', 'Some.name.with.dots');
|
||||
$Schema = new CakeSchema();
|
||||
$this->assertEquals('SomeNameWithDots', $Schema->name);
|
||||
|
||||
Configure::write('App.dir', 'Some-name-with-dashes');
|
||||
$Schema = new CakeSchema();
|
||||
$this->assertEquals('SomeNameWithDashes', $Schema->name);
|
||||
|
||||
Configure::write('App.dir', 'Some name with spaces');
|
||||
$Schema = new CakeSchema();
|
||||
$this->assertEquals('SomeNameWithSpaces', $Schema->name);
|
||||
|
||||
Configure::write('App.dir', 'Some,name;with&weird=characters');
|
||||
$Schema = new CakeSchema();
|
||||
$this->assertEquals('SomeNameWithWeirdCharacters', $Schema->name);
|
||||
|
||||
Configure::write('App.dir', 'app');
|
||||
$this->assertEquals('App', $Schema->name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue