working on file manager for projects

Esse commit está contido em:
Felipe Nascimento de Moura
2011-04-06 22:58:18 -03:00
commit a6a9c2dc47
21 arquivos alterados com 294 adições e 25 exclusões
+1 -1
Ver Arquivo
@@ -1,7 +1,7 @@
<?php
require_once dirname(__FILE__) . '/../mind3rd/API/classes/Mind.php';
require_once dirname(__FILE__) . '/../mind3rd/API/classes/MindSpeaker.php';
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/Darwin/Darwin.php';
require_once dirname(__FILE__) . '/../mind3rd/API/classes/scientia/Darwin.php';
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/Lexer/Lexer.php';
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/canonic/Canonic.php';
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/syntaxer/Syntaxer.php';
+16
Ver Arquivo
@@ -47,6 +47,7 @@
<input type='button' value='commit project demo_en' onclick="commit()"/>
<input type='button' value='show queries' onclick="showQueries()"/>
<input type='button' value='generate db' onclick="genDB()"/>
<input type='button' value='generate docs' onclick="genDocs()"/>
<input type='button' value='logoff' onclick="logoff()"/>
<pre><div id='result' style='border:solid 1px #777;'></div></pre>
</body>
@@ -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()
{
+2 -2
Ver Arquivo
@@ -81,7 +81,7 @@ class mysql implements DBMS{
public function createPrimaryKeys()
{
return "
<object>CONSTRAINT</object> <element><fkname></element> <object>PRIMARY KEY</object> (<element><propertienames></element>)
<object>CONSTRAINT</object> <element><fkname></element> <object>PRIMARY KEY</object> (<element><propertiesnames></element>)
";
}
@@ -89,7 +89,7 @@ class mysql implements DBMS{
{
return "
<keyword>ALTER</keyword> <object>TABLE</object> <tablename>
<keyword>ADD</keyword> <object>PRIMARY KEY</object> (<propertienames>);
<keyword>ADD</keyword> <object>PRIMARY KEY</object> (<propertiesnames>);
";
}
+2 -2
Ver Arquivo
@@ -142,7 +142,7 @@ class pgsql implements DBMS{
public function createPrimaryKeys()
{
return "
<object>CONSTRAINT</object> <element><fkname></element> <object>PRIMARY KEY</object> (<element><propertienames></element>)
<object>CONSTRAINT</object> <element><fkname></element> <object>PRIMARY KEY</object> (<element><propertiesnames></element>)
";
}
@@ -154,7 +154,7 @@ class pgsql implements DBMS{
{
return "
<keyword>ALTER</keyword> <object>TABLE</object> <tablename>
<keyword>ADD</keyword> <object>PRIMARY KEY</object> (<propertienames>);
<keyword>ADD</keyword> <object>PRIMARY KEY</object> (<propertiesnames>);
";
}
+2 -2
Ver Arquivo
@@ -76,7 +76,7 @@ class sqlite implements DBMS{
public function createPrimaryKeys()
{
return "
<object>CONSTRAINT</object> <element><fkname></element> <object>PRIMARY KEY</object> (<element><propertienames></element>)
<object>CONSTRAINT</object> <element><fkname></element> <object>PRIMARY KEY</object> (<element><propertiesnames></element>)
";
}
@@ -84,7 +84,7 @@ class sqlite implements DBMS{
{
return "
<keyword>ALTER</keyword> <object>TABLE</object> <tablename>
<keyword>ADD</keyword> <object>PRIMARY KEY</object> (<propertienames>);
<keyword>ADD</keyword> <object>PRIMARY KEY</object> (<propertiesnames>);
";
}
+4 -1
Ver Arquivo
@@ -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'] = <<<MESSAGE
Invalid HTTP requisition.
+4 -1
Ver Arquivo
@@ -4,7 +4,7 @@
*
* @author felipe
*/
class pt {
class pt implements l10n{
private $messages= Array();
public $name= 'pt';
@@ -56,6 +56,9 @@ class pt {
$this->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'] = <<<MESSAGE
Requisição HTTP inválida.
+16
Ver Arquivo
@@ -0,0 +1,16 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace Lobe;
/**
* Description of Neuron
*
* @author felipe
*/
abstract class Neuron {
}
+57
Ver Arquivo
@@ -0,0 +1,57 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace Lobe\DB;
/**
* Description of DBGen
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
*/
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;
}
}
+26
Ver Arquivo
@@ -0,0 +1,26 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace Lobe\sql;
/**
* Description of sql
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
*/
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);
}
}
+1 -1
Ver Arquivo
@@ -20,7 +20,7 @@ class Query {
const TABLE_NAME = '/<tablename(\/)?>/';
const PROPS = '/<properties(\/)?>/';
const PROPS_NAME = '/<propertienames(\/)?>/';
const PROPS_NAME = '/<propertiesnames(\/)?>/';
const PROP_NAME = '/<propertyname(\/)?>/';
const PROP_TYPE = '/<propertytype(\/)?>/';
const PROP_SIZE = '/<propertysize(\/)?>/';
+1
Ver Arquivo
@@ -83,4 +83,5 @@
}
return rmdir($dir);
}
}
+14
Ver Arquivo
@@ -0,0 +1,14 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of MindException
*
* @author felipe
*/
class MindException extends Exception{
}
+6 -5
Ver Arquivo
@@ -8,7 +8,7 @@ namespace theos;
/**
* Description of DBGen
*
* @author felipe
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
*/
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;
}
}
+9 -4
Ver Arquivo
@@ -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(){
}
}
@@ -0,0 +1,57 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace theos;
/**
* Description of ProjectFileManager
*
* @author felipe
*/
final class ProjectFileManager {
private static function filterURI($uri, $allowSlashes=false)
{
$uri= \urlencode(\utf8_encode($uri));
if($allowSlashes)
$uri= preg_replace('/%2F/', '/', $uri);
while(false !== \strpos('..', $uri))
{
$uri= str_replace('..', '', $uri);
}
$uri= preg_replace('/^\\|\//', '', $uri);
return $uri;
}
private static function mountURI($uri= '', $allowSlashes= false)
{
$tmpURI = \Mind::$currentProject['path']."/";
$tmpURI.= self::filterURI($uri, $allowSlashes);
return $tmpURI;
}
public static function createDir()
{
}
private static function fixDirectory($uri)
{
if(file_exists($uri))
return true;
if(!file_exists(dirname($uri)))
self::fixDirectory(dirname($uri));
mkdir(filterURI($uri));
\chmod($uri, 0777);
}
public static function createFile($uri)
{
self::fixDirectory(dirname($uri));
$uri= self::mountURI($uri, true);
return fopen($uri, 'wb+');
}
}
+14
Ver Arquivo
@@ -16,6 +16,20 @@
* keyword
* comment
*
* Possible tags for template's usage:
* defaultvalue
* propertyname
* propertytype
* propertysize
* propertydetails
* options
* tablename
* constraintname
* referencetablename
* referencecolumnname
* fkname
* propertiesnames
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
* @package DBMS
*/
+17
Ver Arquivo
@@ -0,0 +1,17 @@
<?php
/**
* This file is part of TheWebMind 3rd generation.
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
* @license licenses/mind3rd.license
*/
/**
* Interface for l10n
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
*/
interface l10n {
public function getMessage($msg);
public function __construct();
}
+14
Ver Arquivo
@@ -0,0 +1,14 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
*/
interface neuron {
}
+30 -6
Ver Arquivo
@@ -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(<<<EOT
This command will increase the current version and also will persist the currently analyzed structure into the system's knowledge base.
EOT
);
)
->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;
}
+1
Ver Arquivo
@@ -22,6 +22,7 @@
_MINDSRC_.'/mind3rd/API/cortex/analyst/',
_MINDSRC_.'/mind3rd/API/languages/',
_MINDSRC_.'/mind3rd/API/DBMS/',
_MINDSRC_.'/mind3rd/API/Lobe/',
_MINDSRC_.'/mind3rd/API/'
));