From a6a9c2dc4752bbaaf5d680d2ecfd5eb181c954e2 Mon Sep 17 00:00:00 2001 From: Felipe Nascimento de Moura Date: Wed, 6 Apr 2011 22:58:18 -0300 Subject: [PATCH] working on file manager for projects --- Tests/config.php | 2 +- docs/ide/index.php | 16 ++++++ mind3rd/API/DBMS/mysql.php | 4 +- mind3rd/API/DBMS/pgsql.php | 4 +- mind3rd/API/DBMS/sqlite.php | 4 +- mind3rd/API/L10N/en.php | 5 +- mind3rd/API/L10N/pt.php | 5 +- mind3rd/API/Lobe/Neuron.php | 16 ++++++ mind3rd/API/Lobe/db/db.php | 57 +++++++++++++++++++ mind3rd/API/Lobe/sql/sql.php | 26 +++++++++ mind3rd/API/classes/DQB/Query.php | 2 +- mind3rd/API/classes/MindDir.php | 1 + mind3rd/API/classes/MindException.php | 14 +++++ mind3rd/API/classes/theos/DBGen.php | 11 ++-- mind3rd/API/classes/theos/Gosh.php | 13 +++-- .../API/classes/theos/ProjectFileManager.php | 57 +++++++++++++++++++ mind3rd/API/interfaces/DBMS.php | 14 +++++ mind3rd/API/interfaces/l10n.php | 17 ++++++ mind3rd/API/interfaces/neuron.php | 14 +++++ mind3rd/API/programs/Generate.php | 36 ++++++++++-- mind3rd/API/utils/header.php | 1 + 21 files changed, 294 insertions(+), 25 deletions(-) create mode 100644 mind3rd/API/Lobe/Neuron.php create mode 100644 mind3rd/API/Lobe/db/db.php create mode 100644 mind3rd/API/Lobe/sql/sql.php create mode 100644 mind3rd/API/classes/MindException.php create mode 100644 mind3rd/API/classes/theos/ProjectFileManager.php create mode 100644 mind3rd/API/interfaces/l10n.php create mode 100644 mind3rd/API/interfaces/neuron.php diff --git a/Tests/config.php b/Tests/config.php index 9eb064f..f949da0 100755 --- a/Tests/config.php +++ b/Tests/config.php @@ -1,7 +1,7 @@ +
@@ -245,6 +246,21 @@ } }); } + function genDocs() + { + setLoading(); + $.ajax({ + type:'POST', + url:'../../', + data:{ + program:'generate', + what: 'sql' + }, + success: function(retQ){ + document.getElementById('result').innerHTML= retQ; + } + }); + } function logoff() { diff --git a/mind3rd/API/DBMS/mysql.php b/mind3rd/API/DBMS/mysql.php index 4108a2e..a07f537 100644 --- a/mind3rd/API/DBMS/mysql.php +++ b/mind3rd/API/DBMS/mysql.php @@ -81,7 +81,7 @@ class mysql implements DBMS{ public function createPrimaryKeys() { return " - CONSTRAINT PRIMARY KEY () + CONSTRAINT PRIMARY KEY () "; } @@ -89,7 +89,7 @@ class mysql implements DBMS{ { return " ALTER TABLE - ADD PRIMARY KEY (); + ADD PRIMARY KEY (); "; } diff --git a/mind3rd/API/DBMS/pgsql.php b/mind3rd/API/DBMS/pgsql.php index 30f6c4d..d3c490c 100644 --- a/mind3rd/API/DBMS/pgsql.php +++ b/mind3rd/API/DBMS/pgsql.php @@ -142,7 +142,7 @@ class pgsql implements DBMS{ public function createPrimaryKeys() { return " - CONSTRAINT PRIMARY KEY () + CONSTRAINT PRIMARY KEY () "; } @@ -154,7 +154,7 @@ class pgsql implements DBMS{ { return " ALTER TABLE - ADD PRIMARY KEY (); + ADD PRIMARY KEY (); "; } diff --git a/mind3rd/API/DBMS/sqlite.php b/mind3rd/API/DBMS/sqlite.php index faa2650..3121ec3 100644 --- a/mind3rd/API/DBMS/sqlite.php +++ b/mind3rd/API/DBMS/sqlite.php @@ -76,7 +76,7 @@ class sqlite implements DBMS{ public function createPrimaryKeys() { return " - CONSTRAINT PRIMARY KEY () + CONSTRAINT PRIMARY KEY () "; } @@ -84,7 +84,7 @@ class sqlite implements DBMS{ { return " ALTER TABLE - ADD PRIMARY KEY (); + ADD PRIMARY KEY (); "; } diff --git a/mind3rd/API/L10N/en.php b/mind3rd/API/L10N/en.php index b83ed57..44dd725 100755 --- a/mind3rd/API/L10N/en.php +++ b/mind3rd/API/L10N/en.php @@ -4,7 +4,7 @@ * * @author felipe */ -class En { +class En implements l10n{ private $messages= Array(); public $name= 'en'; @@ -49,6 +49,9 @@ class En { $this->messages['additionalCounterCol'] = "This field was automatically added to allow an insertion of a new tuple using repeated values for the other keys."; $this->messages['commitChanged'] = Mind::message("VCS: Commited to version %s", '[Ok]', false); $this->messages['commitUnchanged'] = Mind::message("VCS: Nothing to commit. Still in version %s", '[Ok]', false); + $this->messages['theosDBQrFail'] = Mind::message("Theos: A problem occurred in the following query\n", '[Fail]', false); + $this->messages['theosDBQrFailAbort'] = Mind::message("Theos: All the queries will be aborted", '[Fail]', false); + $this->messages['theosDBQrOk'] = Mind::message("Theos: Database created successfuly", '[Ok]', false); $this->messages['http_invalid_requisition'] = <<messages['additionalCounterCol'] = "Campo adicionado automaticamente, a ser usado como diferencial para cada tupla, a fim de possibilizar um novo registro utilizando as mesmas demais chaves."; $this->messages['commitChanged'] = Mind::message("VCS: Consignado para versão %s", '[Ok]', false); $this->messages['commitUnchanged'] = Mind::message("VCS: Nada a consignar. Ainda na versão %s", '[Ok]', false); + $this->messages['theosDBQrFail'] = Mind::message("Theos: Ocorreu um problema durante a execução da query abaixo:\n", '[Fail]', false); + $this->messages['theosDBQrFailAbort'] = Mind::message("Theos: Todas as queries serão abortadas", '[Fail]', false); + $this->messages['theosDBQrOk'] = Mind::message("Theos: Base de dados gerada com sucesso", '[Ok]', false); $this->messages['http_invalid_requisition'] = << + */ +class db extends \Lobe\Neuron implements \neuron{ + + private $dbData= false; + + public function __construct(Array $data) + { + $projectData= \Mind::$currentProject; + $this->generateDatabase($projectData); + } + + public function generateDatabase(Array $projectData) + { + $ar= Array( + 'driver'=>$projectData['database_drive'], + 'dbName'=>$projectData['database_name'], + 'host' =>$projectData['database_addr'], + 'port' =>$projectData['database_port'], + 'user' =>$projectData['database_user'], + 'pwd' =>$projectData['database_pwd'] + ); + $this->dbData= $ar; + $this->dbal= new \MindDBAL($ar); + \DQB\QueryFactory::$showHeader= false; + \DQB\QueryFactory::setUp($ar['driver']); + \DQB\QueryFactory::buildQuery('*'); + $qrs= \DQB\QueryFactory::getCompleteQuery(false, true, 'array'); + + $this->dbal->begin(); + foreach($qrs as $qr) + { + $exec = $this->dbal->execute($qr); + + if($exec === false) + { + \Mind::write('theosDBQrFail'); + echo $qr."\n"; + \Mind::write('theosDBQrFailAbort'); + return false; + } + } + $this->dbal->commit(); + \Mind::write('theosDBQrOk'); + return true; + } +} \ No newline at end of file diff --git a/mind3rd/API/Lobe/sql/sql.php b/mind3rd/API/Lobe/sql/sql.php new file mode 100644 index 0000000..15f4c6b --- /dev/null +++ b/mind3rd/API/Lobe/sql/sql.php @@ -0,0 +1,26 @@ + + */ +class sql extends \Lobe\Neuron implements \neuron{ + + public function __construct(Array $data) + { + $projectData= \Mind::$currentProject; + \DQB\QueryFactory::$showHeader= true; + \DQB\QueryFactory::setUp(\Mind::$currentProject['database_drive']); + \DQB\QueryFactory::buildQuery('*'); + $qrs= \DQB\QueryFactory::getCompleteQuery(false, true, 'string'); + + $file= \theos\ProjectFileManager::createFile('docs/create.sql'); + \fwrite($file, $qrs); + } +} \ No newline at end of file diff --git a/mind3rd/API/classes/DQB/Query.php b/mind3rd/API/classes/DQB/Query.php index 7603404..c170a5a 100644 --- a/mind3rd/API/classes/DQB/Query.php +++ b/mind3rd/API/classes/DQB/Query.php @@ -20,7 +20,7 @@ class Query { const TABLE_NAME = '//'; const PROPS = '//'; - const PROPS_NAME = '//'; + const PROPS_NAME = '//'; const PROP_NAME = '//'; const PROP_TYPE = '//'; const PROP_SIZE = '//'; diff --git a/mind3rd/API/classes/MindDir.php b/mind3rd/API/classes/MindDir.php index 2c208a9..48cc5b0 100755 --- a/mind3rd/API/classes/MindDir.php +++ b/mind3rd/API/classes/MindDir.php @@ -83,4 +83,5 @@ } return rmdir($dir); } + } \ No newline at end of file diff --git a/mind3rd/API/classes/MindException.php b/mind3rd/API/classes/MindException.php new file mode 100644 index 0000000..23ae713 --- /dev/null +++ b/mind3rd/API/classes/MindException.php @@ -0,0 +1,14 @@ + */ class DBGen{ @@ -38,13 +38,14 @@ class DBGen{ if($exec === false) { - echo "ERROR: a problem occurred in the following query\n"; - echo "All the queries will be aborted...\n"; - echo $qr."\n\n"; + Mind::write('theosDBQrFail'); + echo $qr."\n"; + Mind::write('theosDBQrFailAbort'); return false; } } $this->dbal->commit(); - echo "Database created successfuly\n"; + Mind::write('theosDBQrOk'); + return true; } } \ No newline at end of file diff --git a/mind3rd/API/classes/theos/Gosh.php b/mind3rd/API/classes/theos/Gosh.php index 7822b0e..69fa068 100644 --- a/mind3rd/API/classes/theos/Gosh.php +++ b/mind3rd/API/classes/theos/Gosh.php @@ -13,12 +13,17 @@ namespace theos; class Gosh { public $bdGen= null; - public function generate() + public function generate($data) { - $this->dbGen->generateDatabase(\Mind::$currentProject); + //$this->dbGen->generateDatabase(\Mind::$currentProject); + $program = strtolower(array_shift($data)); + $program = 'Lobe\\'.$program.'\\'.$program; + if(\class_exists($program)) + new $program($data); + else + throw new \MindException("Invalid lobe program: ".$program); } - public function __construct() { - $this->dbGen= new DBGen; + public function __construct(){ } } \ No newline at end of file diff --git a/mind3rd/API/classes/theos/ProjectFileManager.php b/mind3rd/API/classes/theos/ProjectFileManager.php new file mode 100644 index 0000000..af81c17 --- /dev/null +++ b/mind3rd/API/classes/theos/ProjectFileManager.php @@ -0,0 +1,57 @@ + * @package DBMS diff --git a/mind3rd/API/interfaces/l10n.php b/mind3rd/API/interfaces/l10n.php new file mode 100644 index 0000000..1f3b081 --- /dev/null +++ b/mind3rd/API/interfaces/l10n.php @@ -0,0 +1,17 @@ + + * @license licenses/mind3rd.license + */ + +/** + * Interface for l10n + * + * @author Felipe Nascimento de Moura + */ +interface l10n { + public function getMessage($msg); + public function __construct(); +} \ No newline at end of file diff --git a/mind3rd/API/interfaces/neuron.php b/mind3rd/API/interfaces/neuron.php new file mode 100644 index 0000000..cdb7594 --- /dev/null +++ b/mind3rd/API/interfaces/neuron.php @@ -0,0 +1,14 @@ + + */ +interface neuron { + +} diff --git a/mind3rd/API/programs/Generate.php b/mind3rd/API/programs/Generate.php index 84c1f37..927c0b0 100644 --- a/mind3rd/API/programs/Generate.php +++ b/mind3rd/API/programs/Generate.php @@ -12,20 +12,28 @@ */ class Generate extends MindCommand implements program { - private $nameSpace= false; - public $autoCommit= false; + public $what; + public $param; + public $detail; + public $optional; + public $extra; public function configure() { $this->setName('generate') ->setDescription('Commits the analyzed content to a new version') ->setRestrict(true) - ->setDefinition(Array( - new InputArgument('what', InputArgument::REQUIRED, 'What to create'))) ->setHelp(<<setDefinition(Array( + new InputArgument('what', InputArgument::REQUIRED, 'What to create'), + new InputArgument('param', InputArgument::OPTIONAL, 'A param for that command'), + new InputArgument('detail', InputArgument::OPTIONAL, 'A detail for that command'), + new InputArgument('optional', InputArgument::OPTIONAL, 'An optional argument'), + new InputArgument('extra', InputArgument::OPTIONAL, 'Extra data to pass'), + )); } public function execute(Console\Input\InputInterface $input, @@ -33,6 +41,11 @@ EOT { if(!parent::execute($input, $output)) return false; + $this->what= $input->getArgument('what'); + $this->param= $input->getArgument('param'); + $this->detail= $input->getArgument('detail'); + $this->optional= $input->getArgument('optional'); + $this->extra= $input->getArgument('extra'); Mind::write('thinking'); $this->runAction(); } @@ -42,6 +55,11 @@ EOT GLOBAL $_REQ; if(!parent::HTTPExecute()) return false; + $this->what = $_REQ['data']['what']; + $this->param = (isset($_REQ['data']['param']))? $_REQ['data']['param']: false; + $this->detail = (isset($_REQ['data']['detail']))? $_REQ['data']['detail']: false; + $this->optional= (isset($_REQ['data']['optional']))? $_REQ['data']['optional']: false; + $this->extra = (isset($_REQ['data']['extra']))? $_REQ['data']['extra']: false; $this->runAction(); } @@ -53,7 +71,13 @@ EOT Mind::write('currentProjectRequiredTip'); return false; } - Mind::$gosh->generate(); + Mind::$gosh->generate(Array( + $this->what, + $this->param, + $this->detail, + $this->optional, + $this->extra + )); return $this; } diff --git a/mind3rd/API/utils/header.php b/mind3rd/API/utils/header.php index 35208f0..2549901 100755 --- a/mind3rd/API/utils/header.php +++ b/mind3rd/API/utils/header.php @@ -22,6 +22,7 @@ _MINDSRC_.'/mind3rd/API/cortex/analyst/', _MINDSRC_.'/mind3rd/API/languages/', _MINDSRC_.'/mind3rd/API/DBMS/', + _MINDSRC_.'/mind3rd/API/Lobe/', _MINDSRC_.'/mind3rd/API/' ));