added commit command

Esse commit está contido em:
Felipe Nascimento de Moura
2011-03-24 12:24:32 -03:00
commit 7466439dfb
7 arquivos alterados com 265 adições e 184 exclusões
+165
Ver Arquivo
@@ -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();
+7 -170
Ver Arquivo
@@ -1,166 +1,19 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
* This file is part of theWebMind Project.
* It offers features to deal with the project table into the database
*/
namespace DAO;
/**
* Description of TableFactory
* TableFactory: will work with the DAO\Table class
*
* @package VCS
* @subpackage DAO
* @author felipe
*/
class ProjectFactory extends Project{
public $data= null;
public $versionId= 0;
public $tag= '';
public $description= '';
public $originalCode= '';
public $framework= '';
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 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;
+15 -13
Ver Arquivo
@@ -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();
}
}
+64
Ver Arquivo
@@ -0,0 +1,64 @@
<?php
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
/**
* This class represents the program auth, receiving the user and
* may also receive the password. It will start your session
* allowing you to run the restricted programs
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
*/
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(<<<EOT
This command will increase the current version and also will persist the currently analyzed structure into the system's knowledge base.
EOT
);
}
public function execute(Console\Input\InputInterface $input,
Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
return false;
Mind::write('thinking');
$this->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;
}
}
+1
Ver Arquivo
@@ -21,6 +21,7 @@
EOT
);
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
+1
Ver Arquivo
@@ -40,6 +40,7 @@
new Quit(),
new Auth(),
new Clear(),
new Commit(),
new Info(),
new Create(),
new Show(),
+12 -1
Ver Arquivo
@@ -16,7 +16,18 @@ abstract class WinSetup extends Setup{
*/
public function createExecFile()
{
self::$content= '';
// inspired on Doctrine bat for windows
self::$content= <<<BAT
@echo off
if "%PHPBIN%" == "" set PHPBIN=@php_bin@
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "@bin_dir@\mind" %*
BAT;
// TODO: any good soul to help with it?
}