Skip to content

Commit

Permalink
* 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc-business-account committed Jul 7, 2022
1 parent 3652992 commit 7390412
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 37 deletions.
20 changes: 3 additions & 17 deletions examples/clitest/c1.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
<?php http_response_code(404); die(1); // eftec/CliOne configuration file ?>
{
"interactive": "",
"databasetype": "mysql",
"server": "127.0.0.1",
"user": "root",
"password": "abc.123",
"database": "sakila",
"input": "",
"output": "",
"namespace": "",
"tablexclass": [],
"conversion": [],
"extracolumn": [],
"removecolumn": [],
"columnsTable": []
}
<?php

echo "\u{221a}";
2 changes: 1 addition & 1 deletion lib/PdoOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -2511,7 +2511,7 @@ public function generateGetRelations(string $tableName,?array $columnRelations,$
$refcol2 = isset($v['refcol2']) ? ltrim($v['refcol2'], '_') : null;
$col2 = $v['col2'] ?? null;

$aliasRef = '_' . $aliasesAllTables[$v['reftable']][$refcol] ?? $refcol;
$aliasRef = '_' . @$aliasesAllTables[$v['reftable']][$refcol] ?? $refcol;

$relation[$k]['alias'] = $alias;
if (isset($v['col'])) {
Expand Down
68 changes: 49 additions & 19 deletions lib/PdoOneCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ public function cliEngine(): void
->setInput(false)
->add();
$this->cli->evalParam('export');

$this->inJectInitParam();

$this->cli->createParam('databasetype', 'dt', 'longflag')
->setRelated(['common', 'export', 'generate'])
->setRequired(false)
Expand Down Expand Up @@ -345,6 +347,7 @@ public function cliEngine(): void
$this->inJectInitParam2($first->value, $interactive);
break;
}
$ok=false;
switch ($first->value) {
case 'definition':
case 'export':
Expand Down Expand Up @@ -378,18 +381,20 @@ public function cliEngine(): void
$this->injectLoadFile($first->value, $interactive);
break;
}
if ($first->value) {
if (!$ok) {// $first->value) {
var_dump('load');
$database = $this->cli->evalParam('databasetype', $interactive, true);
$server = $this->cli->evalParam('server', $interactive, true);
$user = $this->cli->evalParam('user', $interactive, true);
$pwd = $this->cli->evalParam('password', $interactive, true);
$db = $this->cli->evalParam('database', $interactive, true);
var_dump('two');
} else {
$database = '';
$server = '';
$user = '';
$pwd = '';
$db = '';
$database = $this->cli->getValue('databasetype');
$server = $this->cli->getValue('server');
$user = $this->cli->getValue('user');
$pwd = $this->cli->getValue('password');
$db = $this->cli->getValue('database');
}
switch ($first->value) {
case 'definition':
Expand Down Expand Up @@ -515,20 +520,29 @@ protected function showHelpExport(): void
, null, 'export', 25);
}

protected function runCliConnection(): ?PdoOne
protected function runCliConnection($force=false): ?PdoOne
{
if (!$this->cli->getValue('databasetype')) {
if (!$this->cli->getValue('databasetype') && $force===false) {
return null;
}
if($force) {
$this->cli->evalParam('databasetype',true);
$this->cli->evalParam('server',true);
$this->cli->evalParam('user',true);
$this->cli->evalParam('password',true);
$this->cli->evalParam('database',true);
}
$result = null;
while (true) {
try {
$pdo = $this->createPdoInstance();
if($pdo===null) {
throw new RuntimeException('trying');
}
$this->cli->showCheck('OK', 'green', 'Connected to the database <bold>' . $this->cli->getValue('database') . '</bold>');
$result = $pdo;
break;
} catch (Exception $ex) {
$this->cli->showCheck('ERROR', 'red', 'Unable to connect to the database: ' . $ex->getMessage());
}
$rt = $this->cli->createParam('retry')
->setDescription('', 'Do you want to retry?')
Expand Down Expand Up @@ -730,15 +744,21 @@ protected function databaseDetail(): void
} // end while tablecommand
} // end while table
}
public function createPdoInstance(): PdoOne {
$pdo = new PdoOne(
$this->cli->getValue('databasetype'),
$this->cli->getValue('server'),
$this->cli->getValue('user'),
$this->cli->getValue('password'),
$this->cli->getValue('database'));
$pdo->logLevel = 3;
$pdo->connect();
public function createPdoInstance(): ?PdoOne {
try {
$pdo = new PdoOne(
$this->cli->getValue('databasetype'),
$this->cli->getValue('server'),
$this->cli->getValue('user'),
$this->cli->getValue('password'),
$this->cli->getValue('database'));
$pdo->logLevel = 1;
$pdo->connect();
} catch(Exception $ex) {
$this->cli->showCheck('ERROR','red',['Unable to connect to database',$pdo->lastError(),$pdo->errorText]);
return null;
}
$pdo->logLevel = 2;
return $pdo;
}

Expand Down Expand Up @@ -913,6 +933,7 @@ protected function runCliGenerationParams(): void
, ['<cyan><optionkey/></cyan>:<option/>'], 'cmd')
->setAllowEmpty()
->setInput(true, 'option', [
'connect' => 'Connect to the database or change the connection',
'folder' => 'Configure the repository folder and namespace',
'scan' => 'Scan for changes to the database. It adds or removes tables and classes',
'select' => 'Select or de-select the tables to work',
Expand Down Expand Up @@ -1047,6 +1068,7 @@ protected function runCliGeneration(): void
$this->cli->evalParam('user');
$this->cli->evalParam('password');
$this->cli->evalParam('database');

$pdo = $this->runCliConnection();
if ($pdo === null) {
$this->cli->showCheck('CRITICAL', 'red', 'No connection');
Expand Down Expand Up @@ -1098,6 +1120,9 @@ protected function runCliGeneration(): void
'you must set the directory and namespace',
'Use the option <bold><cyan>[folder]</cyan></bold> to set the directory and namespace'], 'stderr');
break;
case 'connect':
$pdo=$this->runCliConnection(true);
break;
case 'scan':
$this->databaseScan($tablesmarked, $pdo);
break;
Expand Down Expand Up @@ -1153,7 +1178,12 @@ protected function databaseScan($tablesmarked, $pdo): void
$columnsTable[$table][$v['colname']] = null;
}
$pk[$table] = $pdo->getPK($table);
$def2[$table] = $pdo->getRelations($table, $pk[$table][0]);

if($pk[$table]===false) {
$def2[$table] = $pdo->getRelations($table, null);
} else {
$def2[$table] = $pdo->getRelations($table, $pk[$table][0]);
}
foreach ($def2[$table] as $k => $v) {
if (isset($v['key']) && $v['key'] !== 'FOREIGN KEY') {
$columnsTable[$table][$k] = $v['key'];
Expand Down

0 comments on commit 7390412

Please sign in to comment.