diff --git a/mind3rd/API/classes/DAO/Project.php b/mind3rd/API/classes/DAO/Project.php index aeaaa21..7adece9 100644 --- a/mind3rd/API/classes/DAO/Project.php +++ b/mind3rd/API/classes/DAO/Project.php @@ -12,6 +12,171 @@ namespace DAO; * @author felipe */ class Project{ + public $data= null; + public $versionId= 0; + public $tag= ''; + public $description= ''; + public $originalCode= ''; + public $framework= ''; + + public function getCurrentEntities($vs=false) + { + $qr= "SELECT entity.name as name, + pk_entity, + entity.version as version + from entity, + version + where fk_project = ".\Mind::$currentProject['pk_project']." + and fk_version= pk_version + and status = ".\COMMIT_STATUS_OK; + if($vs) + $qr.= " and fk_version = ".$vs.""; + + $entities= $this->db->query($qr); + return $entities; + } + + public function insertProperty(\MindProperty $prop, $enKey) + { + $refs= ""; + if($prop->refTo) + $refs= $prop->refTo[0]->name.".".$prop->refTo[1]->name; + $qr= "INSERT into property + ( + name, + type, + size, + options, + default_value, + unique_value, + required, + comment, + status, + fk_entity, + ref_to_property + ) + VALUES + ( + '".$prop->name."', + '".$prop->type."', + '".$prop->size."', + '".JSON_encode($prop->options)."', + '".$prop->default."', + '".$prop->unique."', + '".$prop->required."', + '".$prop->comment."', + ".\COMMIT_STATUS_OK.", + ".$enKey.", + '".$refs."' + )"; + $this->db->execute($qr); + } + + public function getProperties(Array $entity) + { + $qr= "select pk_property, + property.name as name, + type, + size, + options, + default_value, + unique_value, + required, + comment, + ref_to_property + from property, + entity + where pk_entity = fk_entity + and entity.pk_entity='".$entity['pk_entity']."'"; + $props= $this->db->query($qr); + $ret= Array(); + foreach($props as $prop) + { + $ret[$prop['name']]= $prop; + } + return $ret; + } + + public function markAsChanged(Array $en) + { + $qr= "UPDATE entity + SET status= ".\COMMIT_STATUS_CHANGED." + WHERE pk_entity= ".$en['pk_entity']; + return $this->db->execute($qr); + } + + public function markAsDopped(Array $en) + { + $qr= "UPDATE entity + SET status= ".\COMMIT_STATUS_DROP." + WHERE pk_entity= ".$en['pk_entity']; + return $this->db->execute($qr); + } + + public function addNewVersion() + { + $this->data['version']++; + + $qr_vsProj= "INSERT into version + ( + version, + tag, + obs, + originalcode, + machine_lang, + framework, + database, + fk_project, + fk_user + ) + values + ( + '".$this->data['version']."', + '".$this->tag."', + '".$this->description."', + '".$this->originalCode."', + '".$this->data['technology']."', + '".$this->framework."', + '".$this->data['database_drive']."', + ".$this->data['pk_project'].", + ".$_SESSION['pk_user']." + )"; + if($this->db->execute($qr_vsProj)) + { + $this->versionId= $this->db->lastInsertedId; + return true; + } + return false; + } + + public function insertEntity(\MindEntity $entity, + $vs=1, + $status=\COMMIT_STATUS_OK) + { + $qr= "INSERT into entity + ( + name, + version, + status, + fk_version + ) + VALUES + ( + '".$entity->name."', + ".$vs.", + ".$status.", + ".$this->versionId." + )"; + $entities= $this->db->execute($qr); + $enKey= $this->db->lastInsertedId; + + foreach($entity->properties as &$prop) + { + $this->insertProperty($prop, $enKey); + } + return $enKey; + } + public function __construct() { $this->db= new \MindDB(); diff --git a/mind3rd/API/classes/DAO/ProjectFactory.php b/mind3rd/API/classes/DAO/ProjectFactory.php index 72032de..5590f1d 100644 --- a/mind3rd/API/classes/DAO/ProjectFactory.php +++ b/mind3rd/API/classes/DAO/ProjectFactory.php @@ -1,166 +1,19 @@ data['version']++; - - $qr_vsProj= "INSERT into version - ( - version, - tag, - obs, - originalcode, - machine_lang, - framework, - database, - fk_project, - fk_user - ) - values - ( - '".$this->data['version']."', - '".$this->tag."', - '".$this->description."', - '".$this->originalCode."', - '".$this->data['technology']."', - '".$this->framework."', - '".$this->data['database_drive']."', - ".$this->data['pk_project'].", - ".$_SESSION['pk_user']." - )"; - if($this->db->execute($qr_vsProj)) - { - $this->versionId= $this->db->lastInsertedId; - return true; - } - return false; - } - - public function getCurrentEntities($vs=false) - { - $qr= "SELECT entity.name as name, - pk_entity, - entity.version as version - from entity, - version - where fk_project = ".\Mind::$currentProject['pk_project']." - and fk_version= pk_version - and status = ".\COMMIT_STATUS_OK; - if($vs) - $qr.= " and fk_version = ".$vs.""; - - $entities= $this->db->query($qr); - return $entities; - } - - public function insertProperty(\MindProperty $prop, $enKey) - { - $refs= ""; - if($prop->refTo) - $refs= $prop->refTo[0]->name.".".$prop->refTo[1]->name; - $qr= "INSERT into property - ( - name, - type, - size, - options, - default_value, - unique_value, - required, - comment, - status, - fk_entity, - ref_to_property - ) - VALUES - ( - '".$prop->name."', - '".$prop->type."', - '".$prop->size."', - '".JSON_encode($prop->options)."', - '".$prop->default."', - '".$prop->unique."', - '".$prop->required."', - '".$prop->comment."', - ".\COMMIT_STATUS_OK.", - ".$enKey.", - '".$refs."' - )"; - $this->db->execute($qr); - } - - public function insertEntity(\MindEntity $entity, - $vs=1, - $status=\COMMIT_STATUS_OK) - { - $qr= "INSERT into entity - ( - name, - version, - status, - fk_version - ) - VALUES - ( - '".$entity->name."', - ".$vs.", - ".$status.", - ".$this->versionId." - )"; - $entities= $this->db->execute($qr); - $enKey= $this->db->lastInsertedId; - - foreach($entity->properties as &$prop) - { - $this->insertProperty($prop, $enKey); - } - return $enKey; - } - - public function getProperties(Array $entity) - { - $qr= "select pk_property, - property.name as name, - type, - size, - options, - default_value, - unique_value, - required, - comment, - ref_to_property - from property, - entity - where pk_entity = fk_entity - and entity.pk_entity='".$entity['pk_entity']."'"; - $props= $this->db->query($qr); - $ret= Array(); - foreach($props as $prop) - { - $ret[$prop['name']]= $prop; - } - return $ret; - } - - public function areDifferent(Array $entity1, \MindEntity $entity2) { $props= $this->getProperties($entity1); @@ -202,22 +55,6 @@ class ProjectFactory extends Project{ return false; } - public function markAsChanged(Array $en) - { - $qr= "UPDATE entity - SET status= ".\COMMIT_STATUS_CHANGED." - WHERE pk_entity= ".$en['pk_entity']; - return $this->db->execute($qr); - } - - public function markAsDopped(Array $en) - { - $qr= "UPDATE entity - SET status= ".\COMMIT_STATUS_DROP." - WHERE pk_entity= ".$en['pk_entity']; - return $this->db->execute($qr); - } - public function saveEntities(&$currentEntities) { $enKey= null; @@ -254,11 +91,11 @@ class ProjectFactory extends Project{ } if($commited) - echo "CVS: Commited to version ".$this->data['version']."\n"; + echo "VCS: Commited to version ".$this->data['version']."\n"; else { $this->data['version']--; - echo "CVS: Nothing to commit...still in version ". + echo "VCS: Nothing to commit...still in version ". $this->data['version']."\n"; } $this->changed= $commited; diff --git a/mind3rd/API/classes/MindProject.php b/mind3rd/API/classes/MindProject.php index 706e081..aecc43e 100755 --- a/mind3rd/API/classes/MindProject.php +++ b/mind3rd/API/classes/MindProject.php @@ -150,7 +150,7 @@ class MindProject extends VersionManager{ Mind::$lexer= new Lexer(); self::loadSources(); } - public static function analyze($autoCommit=false) + public static function analyze($autoCommit=false, $echo=true) { self::setUp(); $init= false; @@ -183,18 +183,20 @@ class MindProject extends VersionManager{ MindTimer::end(); - if($init) - echo Analyst::printWhatYouGet(); - else - echo " Nothing to show\n"; - echo "--------------------\n"; - echo "Time: ". - MindTimer::getElapsedTime(). - "s\n"; - $memory= ((memory_get_usage() / 1024)/1024); - $memory= number_format($memory, 2); - echo "Memory: ".$memory."MBs\n"; - + if($echo) + { + if($init) + echo Analyst::printWhatYouGet(); + else + echo " Nothing to show\n"; + echo "--------------------\n"; + echo "Time: ". + MindTimer::getElapsedTime(). + "s\n"; + $memory= ((memory_get_usage() / 1024)/1024); + $memory= number_format($memory, 2); + echo "Memory: ".$memory."MBs\n"; + } self::cleanUp(); } } \ No newline at end of file diff --git a/mind3rd/API/programs/Commit.php b/mind3rd/API/programs/Commit.php new file mode 100644 index 0000000..9797859 --- /dev/null +++ b/mind3rd/API/programs/Commit.php @@ -0,0 +1,64 @@ + + */ + class Commit extends MindCommand implements program + { + private $nameSpace= false; + public $autoCommit= false; + + public function configure() + { + $this->setName('commit') + ->setDescription('Commits the analyzed content to a new version') + ->setRestrict(true) + ->setHelp(<<runAction(); + } + + public function HTTPExecute() + { + GLOBAL $_REQ; + if(!parent::HTTPExecute()) + return false; + $this->runAction(); + } + + private function action() + { + if(!isset($_SESSION['currentProject'])) + { + Mind::write('currentProjectRequired'); + Mind::write('currentProjectRequiredTip'); + return false; + } + MindProject::analyze(true, false); + return $this; + } + + public function runAction() + { + $ret= $this->action(); + parent::runAction(); + return $ret; + } + } diff --git a/mind3rd/API/programs/Show.php b/mind3rd/API/programs/Show.php index 749c4ec..5e6a140 100755 --- a/mind3rd/API/programs/Show.php +++ b/mind3rd/API/programs/Show.php @@ -21,6 +21,7 @@ EOT ); } + public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { if(!parent::execute($input, $output)) diff --git a/mind3rd/API/utils.php b/mind3rd/API/utils.php index 1c00a86..1f84e5d 100755 --- a/mind3rd/API/utils.php +++ b/mind3rd/API/utils.php @@ -40,6 +40,7 @@ new Quit(), new Auth(), new Clear(), + new Commit(), new Info(), new Create(), new Show(), diff --git a/mind3rd/env/setup/WinSetup.php b/mind3rd/env/setup/WinSetup.php index 3bb8506..a131cc1 100755 --- a/mind3rd/env/setup/WinSetup.php +++ b/mind3rd/env/setup/WinSetup.php @@ -16,7 +16,18 @@ abstract class WinSetup extends Setup{ */ public function createExecFile() { - self::$content= ''; + // inspired on Doctrine bat for windows + self::$content= <<