Example #1
0
 /**
  * 
  */
 public function setEntityAction()
 {
     $this->setClientFolder($this->getRequestArg('folder', null, true));
     $this->setModuleName($this->getRequestArg('service', null, true));
     $lsDbPath = 'config' . DS . 'srv-service.php';
     $laDbClientConf = (require $this->_sClientPath . DS . $lsDbPath);
     $lsDbDriver = $this->getRequestArg('driver', $laDbClientConf['db']['driver']);
     $lsDbCharset = $this->getRequestArg('charset', $laDbClientConf['db']['charset']);
     $lsDbHost = $this->getRequestArg('host', $laDbClientConf['db']['hostname']);
     $lsDbPort = $this->getRequestArg('port', $laDbClientConf['db']['port']);
     $lsDbUser = $this->getRequestArg('user', $laDbClientConf['db']['username']);
     $lsDbPass = $this->getRequestArg('pass', $laDbClientConf['db']['password']);
     $lsDbName = $this->getRequestArg('dbname', $laDbClientConf['db']['database'], true);
     $laDbConf = array('driver' => $lsDbDriver, 'charset' => $lsDbCharset, 'hostname' => $lsDbHost, 'port' => $lsDbPort, 'username' => $lsDbUser, 'password' => $lsDbPass, 'database' => $lsDbName);
     $this->_aRepository['Db'] = new InstallRepository($laDbConf);
     if ($this->_aRepository['Db']->connect()) {
         $lsTableName = $this->getRequestArg('table', $this->_sModuleName, true);
         $laTable = $this->_aRepository['Db']->descEntity($lsTableName);
         if (is_array($laTable)) {
             $lsField = "";
             $lsData = "";
             foreach ($laTable as $laField) {
                 $lsF = $laField['Field'];
                 if ($lsF != 'id' && $lsF != 'User_id' && $lsF != 'dtInsert' && $lsF != 'dtUpdate' && $lsF != 'numStatus' && $lsF != 'isActive') {
                     $lsDefault = "";
                     $lsPri = "";
                     $lsPriORM = "";
                     $lsAuto = "";
                     $lsNull = '* @ORM\\Column(nullable=true)';
                     if ($laField['Default'] == '0' || !empty($laField['Default'])) {
                         $lsDefault = " = {$laField['Default']}";
                     }
                     if ($laField['Key'] == 'PRI') {
                         $lsPri = " PK";
                         $lsPriORM = "\n\t" . '* @ORM\\Id';
                     }
                     if ($laField['Extra'] == 'auto_increment') {
                         $lsAuto = "\n\t" . '* @ORM\\GeneratedValue(strategy="AUTO")';
                     }
                     if ($laField['Null'] == 'NO') {
                         $lsNull = '* @ORM\\Column(nullable=false)';
                     }
                     $laType = explode("(", $laField['Type']);
                     $lsType = $laType[0];
                     switch ($lsType) {
                         case 'int':
                         case 'tinyint':
                         case 'smallint':
                         case 'mediumint':
                         case 'bigint':
                             $lsFieldType = '* @var integer';
                             $lsFieldTypeORM = '* @ORM\\Column(type="integer")';
                             break;
                         case 'text':
                         case 'tinytext':
                         case 'mediumtext':
                         case 'longtext':
                         case 'blob':
                         case 'tinyblob':
                         case 'mediumblob':
                         case 'longblob':
                             $lsFieldType = '* @var text';
                             $lsFieldTypeORM = '* @ORM\\Column(type="text")';
                             break;
                         case 'date':
                         case 'time':
                         case 'timestamp':
                         case 'datetime':
                             $lsFieldType = '* @var datetime';
                             $lsFieldTypeORM = '* @ORM\\Column(type="datetime")';
                             break;
                         case 'decimal':
                         case 'float':
                         case 'double':
                         case 'real':
                             $lsFieldType = '* @var decimal';
                             $lsFieldTypeORM = '* @ORM\\Column(type="decimal")';
                             break;
                         case 'boolean':
                             $lsFieldType = '* @var boolean';
                             $lsFieldTypeORM = '* @ORM\\Column(type="boolean")';
                             break;
                         default:
                             $lsFieldType = '* @var string';
                             $lsFieldTypeORM = '* @ORM\\Column(type="string")';
                     }
                     $lsField .= "\t/**\n\t{$lsFieldType}{$lsPri}{$lsPriORM}{$lsAuto}\n\t{$lsFieldTypeORM}\n\t{$lsNull}*/\n\tprotected \${$laField['Field']}{$lsDefault};\n\n";
                 }
             }
             $lsPathSrcModule = $this->_sClientPath . DS . 'service' . DS . $this->_sModuleName . DS . 'src' . DS . $this->_sModuleName;
             $lsPathEntity = $lsPathSrcModule . DS . 'Entity' . DS . "{$lsTableName}.php";
             $lsFileContent = System::localRequest($lsPathEntity);
             if ($lsFileContent == false) {
                 $lsFileContent = System::localRequest($this->_sModelPath . DS . "Entity.model");
                 $lsFileLicense = $this->getLicense($this->_sModuleName);
                 Util::parse($lsFileContent, "#%LICENSE%#", $lsFileLicense);
                 Util::parse($lsFileContent, "#%MODULE%#", $this->_sModuleName);
                 Util::parse($lsFileContent, "#%TABLE%#", $lsTableName);
             }
             Util::parse($lsFileContent, "#%FIELDS%#", $lsField);
             System::saveFile($lsPathEntity, $lsFileContent);
         }
     }
 }
Example #2
0
 /**
  * 
  */
 public function virtualHostDevAction()
 {
     if ($_SERVER["USER"] == "root") {
         $laApacheConf = $this->getApacheConf();
         if (is_array($laApacheConf)) {
             $lsApacheGrp = $laApacheConf['Group'];
             $lsDocRoot = $laApacheConf['DocumentRoot'] . DS;
             $lsServerRoot = $laApacheConf['ServerRoot'] . DS;
         } else {
             $lsApacheGrp = "www-data";
             $lsDocRoot = DS . "var" . DS . "www" . DS;
             $lsServerRoot = DS . "etc" . DS . "apache2" . DS;
         }
         $lsApacheGroup = $this->getRequestArg('apachegrp', $lsApacheGrp);
         echo "CHGPR project folder\n";
         $laReturn = System::execute("chgrp {$lsApacheGroup} " . BASE_DIR . " -R");
         Debug::debug($laReturn);
         $lsDocRoot = $this->getRequestArg('docroot', $lsDocRoot, true);
         $laAppDirName = explode(DS, BASE_DIR);
         $lsAppDirName = array_pop($laAppDirName);
         if (!file_exists($lsDocRoot . DS . $lsAppDirName) || System::confirm("The link {$lsDocRoot}{$lsAppDirName} already exists! Overwrite?")) {
             echo "Create project link to document root: " . BASE_DIR . "  to {$lsDocRoot}\n";
             System::simblink(BASE_DIR, $lsDocRoot);
         }
         if (System::confirm("Create Apache virtual host?")) {
             $lsClientFolder = $this->getRequestArg('folder', $this->_sClientFolder, true);
             if (empty($this->_sClientDomain)) {
                 $this->_sClientDomain = "local.{$lsClientFolder}";
             }
             $lsDomain = $this->getRequestArg('domain', $this->_sClientDomain, true);
             $lsPort = $this->getRequestArg('httpport', '80', true);
             $lsHosts = $this->getRequestArg('hosts', DS . "etc" . DS . "hosts", true);
             $lsLocalhost = $this->getRequestArg('localhost', "127.0.0.1", true);
             $lsApacheDir = $this->getRequestArg('apachedir', $lsServerRoot);
             if (file_exists($lsHosts)) {
                 echo "Backuping {$lsHosts} to {$lsHosts}.bkp\n";
                 $laReturn = System::execute("cp {$lsHosts} {$lsHosts}.bkp");
                 Debug::debug($laReturn);
                 echo "Seting '{$lsLocalhost}\t{$lsDomain}' to {$lsHosts}\n";
                 $laReturn = System::execute("echo {$lsLocalhost}\t{$lsDomain} >> {$lsHosts}");
                 Debug::debug($laReturn);
             } else {
                 System::echoWarning("The {$lsHosts} does not exists!");
             }
             if ($this->_sController == 'Cms') {
                 $lsPublicFolder = 'public';
             } elseif ($this->_sController == 'Srv') {
                 $lsPublicFolder = 'srv-public';
             }
             $lsDocumentRoot = $lsDocRoot . $lsAppDirName . DS . 'client' . DS . $lsClientFolder . DS . $lsPublicFolder;
             $lsSitesAvailablePath = $lsApacheDir . 'sites-available' . DS . "{$lsDomain}.conf";
             if (!file_exists($lsSitesAvailablePath) || System::confirm("The vhost {$lsDomain}.conf already exists! Overwrite?")) {
                 echo "Creating vhost: {$lsSitesAvailablePath}\n";
                 $lsVirtualHost = $this->vHost($lsDocumentRoot, $lsDomain, $lsPort);
                 Debug::debug($lsVirtualHost);
                 $laReturn = System::saveFile($lsSitesAvailablePath, trim($lsVirtualHost));
                 Debug::debug($laReturn);
             }
             echo "Enable vhost {$lsDomain}\n";
             $laReturn = System::execute("a2ensite {$lsDomain}");
             Debug::debug($laReturn);
             if (System::confirm("Reload Apache2?")) {
                 echo "Apache reload\n";
                 $laReturn = System::execute(DS . "etc" . DS . "init.d" . DS . "apache2 reload");
                 Debug::debug($laReturn);
             }
         }
     } else {
         System::echoError("You need root access to run this action! Please try run this action using sudo.");
     }
 }