mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-17 06:59:51 +00:00
updating acl and model cli
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5217 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
ff40f65fab
commit
537f28878d
2 changed files with 17 additions and 152 deletions
|
@ -50,6 +50,12 @@ class AclShell extends Shell {
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $dataSource = 'default';
|
var $dataSource = 'default';
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
*/
|
||||||
|
var $tasks = array('DbConfig');
|
||||||
/**
|
/**
|
||||||
* override intialize of the Shell
|
* override intialize of the Shell
|
||||||
*
|
*
|
||||||
|
@ -79,10 +85,7 @@ class AclShell extends Shell {
|
||||||
|
|
||||||
if($this->command && !in_array($this->command, array('help'))) {
|
if($this->command && !in_array($this->command, array('help'))) {
|
||||||
if(!file_exists(CONFIGS.'database.php')) {
|
if(!file_exists(CONFIGS.'database.php')) {
|
||||||
$this->out('');
|
$this->DbConfig->execute();
|
||||||
$this->out('Your database configuration was not found.');
|
|
||||||
$this->out('Take a moment to create one:');
|
|
||||||
$this->__doDbConfig();
|
|
||||||
}
|
}
|
||||||
require_once (CONFIGS.'database.php');
|
require_once (CONFIGS.'database.php');
|
||||||
|
|
||||||
|
@ -199,7 +202,7 @@ class AclShell extends Shell {
|
||||||
$this->_checkArgs(2, 'getPath');
|
$this->_checkArgs(2, 'getPath');
|
||||||
$this->checkNodeType();
|
$this->checkNodeType();
|
||||||
extract($this->__dataVars());
|
extract($this->__dataVars());
|
||||||
$id = (is_numeric($this->args[2])) ? intval($this->args[1]) : $this->args[1];
|
$id = (is_numeric($this->args[1])) ? intval($this->args[1]) : $this->args[1];
|
||||||
$nodes = $this->Acl->{$class}->getPath($id);
|
$nodes = $this->Acl->{$class}->getPath($id);
|
||||||
if (empty($nodes)) {
|
if (empty($nodes)) {
|
||||||
$this->error("Supplied Node '".$this->args[1]."' not found", "No tree returned.");
|
$this->error("Supplied Node '".$this->args[1]."' not found", "No tree returned.");
|
||||||
|
@ -450,144 +453,6 @@ class AclShell extends Shell {
|
||||||
$vars['class'] = $class;
|
$vars['class'] = $class;
|
||||||
return $vars;
|
return $vars;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Database configuration setup.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function __doDbConfig() {
|
|
||||||
$this->hr(true);
|
|
||||||
$this->out('Database Configuration:');
|
|
||||||
$this->hr(true);
|
|
||||||
|
|
||||||
$driver = '';
|
|
||||||
|
|
||||||
while ($driver == '') {
|
|
||||||
$driver = $this->in('What database driver would you like to use?', array('mysql','mysqli','mssql','sqlite','postgres', 'odbc', 'oracle'), 'mysql');
|
|
||||||
if ($driver == '') {
|
|
||||||
$this->out('The database driver supplied was empty. Please supply a database driver.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch($driver) {
|
|
||||||
case 'mysql':
|
|
||||||
$connect = 'mysql_connect';
|
|
||||||
break;
|
|
||||||
case 'mysqli':
|
|
||||||
$connect = 'mysqli_connect';
|
|
||||||
break;
|
|
||||||
case 'mssql':
|
|
||||||
$connect = 'mssql_connect';
|
|
||||||
break;
|
|
||||||
case 'sqlite':
|
|
||||||
$connect = 'sqlite_open';
|
|
||||||
break;
|
|
||||||
case 'postgres':
|
|
||||||
$connect = 'pg_connect';
|
|
||||||
break;
|
|
||||||
case 'odbc':
|
|
||||||
$connect = 'odbc_connect';
|
|
||||||
break;
|
|
||||||
case 'oracle':
|
|
||||||
$connect = 'ocilogon';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$this->out('The connection parameter could not be set.');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$host = '';
|
|
||||||
|
|
||||||
while ($host == '') {
|
|
||||||
$host = $this->in('What is the hostname for the database server?', null, 'localhost');
|
|
||||||
if ($host == '') {
|
|
||||||
$this->out('The host name you supplied was empty. Please supply a hostname.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$login = '';
|
|
||||||
|
|
||||||
while ($login == '') {
|
|
||||||
$login = $this->in('What is the database username?', null, 'root');
|
|
||||||
|
|
||||||
if ($login == '') {
|
|
||||||
$this->out('The database username you supplied was empty. Please try again.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$password = '';
|
|
||||||
$blankPassword = false;
|
|
||||||
|
|
||||||
while ($password == '' && $blankPassword == false) {
|
|
||||||
$password = $this->in('What is the database password?');
|
|
||||||
if ($password == '') {
|
|
||||||
$blank = $this->in('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n');
|
|
||||||
if($blank == 'y')
|
|
||||||
{
|
|
||||||
$blankPassword = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$database = '';
|
|
||||||
|
|
||||||
while ($database == '') {
|
|
||||||
$database = $this->in('What is the name of the database you will be using?', null, 'cake');
|
|
||||||
|
|
||||||
if ($database == '') {
|
|
||||||
$this->out('The database name you supplied was empty. Please try again.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$prefix = '';
|
|
||||||
|
|
||||||
while ($prefix == '') {
|
|
||||||
$prefix = $this->in('Enter a table prefix?', null, 'n');
|
|
||||||
}
|
|
||||||
if(low($prefix) == 'n') {
|
|
||||||
$prefix = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->hr(true);
|
|
||||||
$this->out('The following database configuration will be created:');
|
|
||||||
$this->hr(true);
|
|
||||||
$this->out("Driver: $driver");
|
|
||||||
$this->out("Connection: $connect");
|
|
||||||
$this->out("Host: $host");
|
|
||||||
$this->out("User: $login");
|
|
||||||
$this->out("Pass: " . str_repeat('*', strlen($password)));
|
|
||||||
$this->out("Database: $database");
|
|
||||||
$this->out("Table prefix: $prefix");
|
|
||||||
$this->hr(true);
|
|
||||||
$looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
|
|
||||||
|
|
||||||
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
|
|
||||||
$this->bakeDbConfig($driver, $connect, $host, $login, $password, $database, $prefix);
|
|
||||||
} else {
|
|
||||||
$this->out('Bake Aborted.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Creates a database configuration file for Bake.
|
|
||||||
*
|
|
||||||
* @param string $host
|
|
||||||
* @param string $login
|
|
||||||
* @param string $password
|
|
||||||
* @param string $database
|
|
||||||
*/
|
|
||||||
function bakeDbConfig( $driver, $connect, $host, $login, $password, $database, $prefix) {
|
|
||||||
$out = "<?php\n";
|
|
||||||
$out .= "class DATABASE_CONFIG {\n\n";
|
|
||||||
$out .= "\tvar \$default = array(\n";
|
|
||||||
$out .= "\t\t'driver' => '{$driver}',\n";
|
|
||||||
$out .= "\t\t'connect' => '{$connect}',\n";
|
|
||||||
$out .= "\t\t'host' => '{$host}',\n";
|
|
||||||
$out .= "\t\t'login' => '{$login}',\n";
|
|
||||||
$out .= "\t\t'password' => '{$password}',\n";
|
|
||||||
$out .= "\t\t'database' => '{$database}', \n";
|
|
||||||
$out .= "\t\t'prefix' => '{$prefix}' \n";
|
|
||||||
$out .= "\t);\n";
|
|
||||||
$out .= "}\n";
|
|
||||||
$out .= "?>";
|
|
||||||
$filename = CONFIGS.'database.php';
|
|
||||||
$this->createFile($filename, $out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -50,7 +50,7 @@ class ModelTask extends Shell {
|
||||||
$useTable = null;
|
$useTable = null;
|
||||||
$primaryKey = 'id';
|
$primaryKey = 'id';
|
||||||
$validate = array();
|
$validate = array();
|
||||||
$associations = array();
|
$associations = array('belongsTo'=> array(), 'hasOne'=> array(), 'hasMany', 'hasAndBelongsToMany'=> array());
|
||||||
/*$usingDefault = $this->in('Will your model be using a database connection setting other than the default?');
|
/*$usingDefault = $this->in('Will your model be using a database connection setting other than the default?');
|
||||||
if (low($usingDefault) == 'y' || low($usingDefault) == 'yes')
|
if (low($usingDefault) == 'y' || low($usingDefault) == 'yes')
|
||||||
{
|
{
|
||||||
|
@ -300,7 +300,7 @@ class ModelTask extends Shell {
|
||||||
$wannaDoMoreAssoc = $this->in('Would you like to define some additional model associations?', array('y','n'), 'n');
|
$wannaDoMoreAssoc = $this->in('Would you like to define some additional model associations?', array('y','n'), 'n');
|
||||||
|
|
||||||
while((low($wannaDoMoreAssoc) == 'y' || low($wannaDoMoreAssoc) == 'yes')) {
|
while((low($wannaDoMoreAssoc) == 'y' || low($wannaDoMoreAssoc) == 'yes')) {
|
||||||
$assocs = array(1=>'belongsTo', 2=>'hasOne', 3=>'hasMany', 4=>'hasAndBelongsToMany');
|
$assocs = array(1 => 'belongsTo', 2 => 'hasOne', 3 => 'hasMany', 4 => 'hasAndBelongsToMany');
|
||||||
$bad = true;
|
$bad = true;
|
||||||
while($bad) {
|
while($bad) {
|
||||||
$this->out('What is the association type?');
|
$this->out('What is the association type?');
|
||||||
|
@ -383,25 +383,25 @@ class ModelTask extends Shell {
|
||||||
if(!empty($associations)) {
|
if(!empty($associations)) {
|
||||||
$this->out("Associations:");
|
$this->out("Associations:");
|
||||||
|
|
||||||
if(count($associations['belongsTo'])) {
|
if(!empty($associations['belongsTo'])) {
|
||||||
for($i = 0; $i < count($associations['belongsTo']); $i++) {
|
for($i = 0; $i < count($associations['belongsTo']); $i++) {
|
||||||
$this->out(" $currentModelName belongsTo {$associations['belongsTo'][$i]['alias']}");
|
$this->out(" $currentModelName belongsTo {$associations['belongsTo'][$i]['alias']}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($associations['hasOne'])) {
|
if(!empty($associations['hasOne'])) {
|
||||||
for($i = 0; $i < count($associations['hasOne']); $i++) {
|
for($i = 0; $i < count($associations['hasOne']); $i++) {
|
||||||
$this->out(" $currentModelName hasOne {$associations['hasOne'][$i]['alias']}");
|
$this->out(" $currentModelName hasOne {$associations['hasOne'][$i]['alias']}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($associations['hasMany'])) {
|
if(!empty($associations['hasMany'])) {
|
||||||
for($i = 0; $i < count($associations['hasMany']); $i++) {
|
for($i = 0; $i < count($associations['hasMany']); $i++) {
|
||||||
$this->out(" $currentModelName hasMany {$associations['hasMany'][$i]['alias']}");
|
$this->out(" $currentModelName hasMany {$associations['hasMany'][$i]['alias']}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($associations['hasAndBelongsToMany'])) {
|
if(!empty($associations['hasAndBelongsToMany'])) {
|
||||||
for($i = 0; $i < count($associations['hasAndBelongsToMany']); $i++) {
|
for($i = 0; $i < count($associations['hasAndBelongsToMany']); $i++) {
|
||||||
$this->out(" $currentModelName hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}");
|
$this->out(" $currentModelName hasAndBelongsToMany {$associations['hasAndBelongsToMany'][$i]['alias']}");
|
||||||
}
|
}
|
||||||
|
@ -437,7 +437,7 @@ class ModelTask extends Shell {
|
||||||
* @param array $validate
|
* @param array $validate
|
||||||
* @param array $associations
|
* @param array $associations
|
||||||
*/
|
*/
|
||||||
function __bake($name, $useDbConfig = 'default', $useTable = null, $primaryKey = 'id', $validate=array(), $associations=array()) {
|
function __bake($name, $useDbConfig = 'default', $useTable = null, $primaryKey = 'id', $validate = array(), $associations = array()) {
|
||||||
$out = "<?php\n";
|
$out = "<?php\n";
|
||||||
$out .= "class {$name} extends AppModel {\n\n";
|
$out .= "class {$name} extends AppModel {\n\n";
|
||||||
$out .= "\tvar \$name = '{$name}';\n";
|
$out .= "\tvar \$name = '{$name}';\n";
|
||||||
|
|
Loading…
Add table
Reference in a new issue