PMCORE-876 The files are not shown, when we create a PM_Table from an external DB

This commit is contained in:
Roly Gutierrez
2020-04-03 10:59:24 -04:00
parent 449f7a2315
commit f8aba2ab03
12 changed files with 1605 additions and 5 deletions

View File

@@ -3,10 +3,11 @@
use Faker\Generator as Faker;
$factory->define(\ProcessMaker\Model\AdditionalTables::class, function(Faker $faker) {
$name = $faker->regexify("/[a-zA-Z]{6}/");
return [
'ADD_TAB_UID' => G::generateUniqueID(),
'ADD_TAB_NAME' => $faker->name,
'ADD_TAB_CLASS_NAME' => $faker->name,
'ADD_TAB_NAME' => 'PMT_' . strtoupper($name),
'ADD_TAB_CLASS_NAME' => 'Pmt' . $name,
'ADD_TAB_DESCRIPTION' => $faker->text,
'ADD_TAB_SDW_LOG_INSERT' => 0,
'ADD_TAB_SDW_LOG_UPDATE' => 0,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
<?php
require_once 'classes/om/Base{tableName}.php';
/**
* Skeleton subclass for representing a row from the '{tableName}' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package classes
*/
class {tableName} extends Base{tableName} {
} // {tableName}

View File

@@ -0,0 +1,78 @@
<?php
require_once 'propel/map/MapBuilder.php';
include_once 'creole/CreoleTypes.php';
/**
* This class adds structure of '{tableName}' table to 'workflow' DatabaseMap object.
*
*
*
* These statically-built map classes are used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
* @package workflow.classes.map
*/
class {tableName}MapBuilder
{
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'classes.map.{tableName}MapBuilder';
/**
* The database map.
*/
private $dbMap;
/**
* Tells us if this DatabaseMapBuilder is built so that we
* don't have to re-build it every time.
*
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
*/
public function isBuilt()
{
return ($this->dbMap !== null);
}
/**
* Gets the databasemap this map builder built.
*
* @return the databasemap
*/
public function getDatabaseMap()
{
return $this->dbMap;
}
/**
* The doBuild() method builds the DatabaseMap
*
* @return void
* @throws PropelException
*/
public function doBuild()
{
$this->dbMap = Propel::getDatabaseMap('workflow');
$tMap = $this->dbMap->addTable('{tableName}');
$tMap->setPhpName('{tableName}');
$tMap->setUseIdGenerator(false);
$tMap->addPrimaryKey('APP_UID', 'AppUid', 'string', CreoleTypes::VARCHAR, true, 32);
$tMap->addColumn('APP_NUMBER', 'AppNumber', 'int', CreoleTypes::INTEGER, true, 11);
$tMap->addColumn('APP_STATUS', 'AppStatus', 'string', CreoleTypes::VARCHAR, true, 10);
$tMap->addColumn('VAR1', 'Var1', 'string', CreoleTypes::VARCHAR, false, 255);
} // doBuild()
} // {tableName}MapBuilder

View File

@@ -0,0 +1,23 @@
<?php
// include base peer class
require_once 'classes/om/Base{tableName}Peer.php';
// include object class
include_once 'classes/{tableName}.php';
/**
* Skeleton subclass for performing query and update operations on the '{tableName}' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package classes
*/
class {tableName}Peer extends Base{tableName}Peer {
} // {tableName}Peer

View File

@@ -122,6 +122,10 @@ class SpoolRunTest extends TestCase
*/
public function it_should_handle_mail_option()
{
$string = ini_get("sendmail_path");
if (!is_executable($string)) {
$this->markTestIncomplete($string . " not found");
}
$appMsgUid = G::generateUniqueID();
factory(AppMessage::class)->create([
'APP_MSG_UID' => $appMsgUid

View File

@@ -5,6 +5,9 @@ namespace Tests\unit\workflow\engine\classes\model;
use AdditionalTables;
use Exception;
use G;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use ProcessMaker\BusinessModel\ReportTable;
use ProcessMaker\Model\AdditionalTables as AdditionalTablesModel;
use Tests\TestCase;
@@ -106,4 +109,173 @@ class AdditionalTablesTest extends TestCase
$additionalTables = new AdditionalTables();
$additionalTables->update($expected);
}
/**
* It tries to getAll() method.
* @test
* @covers \AdditionalTables::getAll()
*/
public function it_should_get_all_registries()
{
$proUid = factory(\ProcessMaker\Model\Process::class)->create()->PRO_UID;
//local connections
$additionalTables = factory(AdditionalTablesModel::class, 3);
$dbSource = factory(\ProcessMaker\Model\DbSource::class)->create([
'PRO_UID' => $proUid,
'DBS_SERVER' => env('DB_HOST'),
'DBS_DATABASE_NAME' => env('DB_DATABASE'),
'DBS_USERNAME' => env('DB_USERNAME'),
'DBS_PASSWORD' => G::encrypt(env('DB_PASSWORD'), env('DB_DATABASE')) . "_2NnV3ujj3w",
'DBS_PORT' => '3306',
'DBS_CONNECTION_TYPE' => 'NORMAL'
]);
$additionalTable = factory(AdditionalTablesModel::class)->create([
'PRO_UID' => $proUid,
'DBS_UID' => $dbSource->DBS_UID,
]);
$tableName = $additionalTable->ADD_TAB_NAME;
$name = $additionalTable->ADD_TAB_CLASS_NAME;
$this->createSchema($dbSource->DBS_DATABASE_NAME, $tableName, $name, $dbSource->DBS_UID);
//external connection
$dbSource = factory(\ProcessMaker\Model\DbSource::class)->create([
'PRO_UID' => $proUid,
'DBS_SERVER' => config('database.connections.testexternal.host'),
'DBS_DATABASE_NAME' => config('database.connections.testexternal.database'),
'DBS_USERNAME' => config('database.connections.testexternal.username'),
'DBS_PASSWORD' => G::encrypt(config('database.connections.testexternal.password'), config('database.connections.testexternal.database')) . "_2NnV3ujj3w",
'DBS_PORT' => '3306',
'DBS_CONNECTION_TYPE' => 'NORMAL'
]);
$additionalTable = factory(AdditionalTablesModel::class)->create([
'PRO_UID' => $proUid,
'DBS_UID' => $dbSource->DBS_UID,
]);
$tableName = $additionalTable->ADD_TAB_NAME;
$name = $additionalTable->ADD_TAB_CLASS_NAME;
$this->createSchema($dbSource->DBS_DATABASE_NAME, $tableName, $name, $dbSource->DBS_UID);
//expected
$expected = AdditionalTablesModel::select()
->get()
->toArray();
$expected = array_column($expected, 'ADD_TAB_UID');
//assertions
$additionalTables = new AdditionalTables();
$actual = $additionalTables->getAll();
$actual = array_column($actual['rows'], 'ADD_TAB_UID');
$this->assertContains($actual[0], $expected, false);
$actual = $additionalTables->getAll(0, 20, 'a');
$actual = array_column($actual['rows'], 'ADD_TAB_UID');
$this->assertContains($actual[0], $expected, false);
$actual = $additionalTables->getAll(0, 20, '', ['equal' => $proUid]);
$actual = array_column($actual['rows'], 'ADD_TAB_UID');
$this->assertContains($actual[0], $expected, false);
$_POST['sort'] = 'ADD_TAB_NAME';
$_POST['dir'] = 'ASC';
$actual = $additionalTables->getAll(0, 20, '', ['notequal' => $proUid]);
$actual = array_column($actual['rows'], 'ADD_TAB_UID');
$this->assertContains($actual[0], $expected, false);
$_POST['sort'] = 'NUM_ROWS';
$_POST['dir'] = 'DESC';
$actual = $additionalTables->getAll(0, 20, '', ['notequal' => $proUid]);
$actual = array_column($actual['rows'], 'ADD_TAB_UID');
$this->assertContains($actual[0], $expected, false);
$actual = $additionalTables->getAll(0, 20, '', ['equal' => $proUid]);
$actual = array_column($actual['rows'], 'ADD_TAB_UID');
$this->assertContains($actual[0], $expected, false);
$actual = $additionalTables->getAll(0, 20, $tableName);
$actual = array_column($actual['rows'], 'ADD_TAB_UID');
$this->assertContains($actual[0], $expected, false);
}
/**
* This gets the content from template file.
* @param string $pathData
* @param string $tableName
* @param string $tableName2
* @param string $database
* @return string
*/
private function getTemplate(string $pathData, string $tableName, string $tableName2 = "", string $database = ""): string
{
$pathData = PATH_TRUNK . "/tests/resources/{$pathData}";
$result = file_get_contents($pathData);
$result = str_replace("{tableName}", $tableName, $result);
if (!empty($tableName2)) {
$result = str_replace("{tableName2}", $tableName2, $result);
}
if (!empty($database)) {
$result = str_replace("{database}", $database, $result);
}
return $result;
}
/**
* Create directory if not exist.
* @param string $path
* @return string
*/
private function createDirectory(string $path): string
{
if (!is_dir($path)) {
mkdir($path);
}
return $path;
}
/**
* Create the schema of the table.
* @param string $connection
* @param string $tableName
* @param string $className
* @param string $dbsUid
*/
private function createSchema(string $connection, string $tableName, string $className, string $dbsUid = 'workflow')
{
$query = ""
. "CREATE TABLE IF NOT EXISTS `{$tableName}` ("
. "`APP_UID` varchar(32) NOT NULL,"
. "`APP_NUMBER` int(11) NOT NULL,"
. "`APP_STATUS` varchar(10) NOT NULL,"
. "`VAR1` varchar(255) DEFAULT NULL,"
. "`VAR2` varchar(255) DEFAULT NULL,"
. "`VAR3` varchar(255) DEFAULT NULL,"
. "PRIMARY KEY (`APP_UID`),"
. "KEY `indexTable` (`APP_UID`))";
if (!empty(config("database.connections.{$connection}"))) {
DB::connection($connection)->statement($query);
} else {
DB::statement($query);
}
$this->createDirectory(PATH_DB);
$this->createDirectory(PATH_DB . env('MAIN_SYS_SYS'));
$pathClasses = PATH_DB . env('MAIN_SYS_SYS') . "/classes";
$this->createDirectory($pathClasses);
$this->createDirectory("{$pathClasses}/om");
$this->createDirectory("{$pathClasses}/map");
$template1 = $this->getTemplate("PmtTableName.tpl", $className);
$template2 = $this->getTemplate("PmtTableNamePeer.tpl", $className);
$template3 = $this->getTemplate("BasePmtTableName.tpl", $className);
$template4 = $this->getTemplate("BasePmtTableNamePeer.tpl", $className, $tableName, $dbsUid);
$template5 = $this->getTemplate("PmtTableNameMapBuilder.tpl", $className);
file_put_contents("{$pathClasses}/{$className}.php", $template1);
file_put_contents("{$pathClasses}/{$className}Peer.php", $template2);
file_put_contents("{$pathClasses}/om/Base{$className}.php", $template3);
file_put_contents("{$pathClasses}/om/Base{$className}Peer.php", $template4);
file_put_contents("{$pathClasses}/map/{$className}MapBuilder.php", $template5);
}
}

View File

@@ -23,7 +23,7 @@
* Stores the file name and line number of a XML file
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright <20> 2001,2002 THYRELL. All rights reserved
* @copyright 2001,2002 THYRELL. All rights reserved
* @version $Revision: 1.6 $ $Date: 2003/12/24 13:02:09 $
* @access public
* @package phing.parser
@@ -43,7 +43,7 @@ class Location {
* @param integer the column number
* @access public
*/
function Location($fileName = null, $lineNumber = null, $columnNumber = null) {
function __construct($fileName = null, $lineNumber = null, $columnNumber = null) {
$this->fileName = $fileName;
$this->lineNumber = $lineNumber;
$this->columnNumber = $columnNumber;

View File

@@ -446,7 +446,7 @@ class Win32FileSystem extends FileSystem {
/* -- Basic infrastructure -- */
/** compares file paths lexicographically */
function compare(PhingFile $f1, PhingFile $f2) {
function compare($f1, $f2) {
$f1Path = $f1->getPath();
$f2Path = $f2->getPath();
return (boolean) strcasecmp((string) $f1Path, (string) $f2Path);

View File

@@ -1010,6 +1010,9 @@ class AdditionalTables extends BaseAdditionalTables
. ")";
$buildNumberRows = clone $criteria;
$buildNumberRows->clear();
$buildNumberRows->addSelectColumn(AdditionalTablesPeer::PRO_UID);
$buildNumberRows->addSelectColumn(AdditionalTablesPeer::DBS_UID);
$buildNumberRows->addSelectColumn(AdditionalTablesPeer::ADD_TAB_CLASS_NAME);
$buildNumberRows->addSelectColumn(AdditionalTablesPeer::ADD_TAB_NAME);
$buildNumberRows->addAsColumn("EXISTS_TABLE", $stringSql);
$dataset1 = AdditionalTablesPeer::doSelectRS($buildNumberRows);
@@ -1020,6 +1023,27 @@ class AdditionalTables extends BaseAdditionalTables
if ($row["EXISTS_TABLE"] === "1") {
$stringCount = "(SELECT COUNT(*) FROM " . $row["ADD_TAB_NAME"] . ")";
}
if ($row["EXISTS_TABLE"] === "0") {
$className = $row['ADD_TAB_CLASS_NAME'];
$pathWorkspace = PATH_DB . config("system.workspace") . PATH_SEP;
if (file_exists($pathWorkspace . 'classes/' . $className . '.php')) {
$_SESSION['PROCESS'] = $row['PRO_UID']; //is required by method Propel::getConnection()
require_once $pathWorkspace . 'classes/' . $className . '.php';
$externalCriteria = new Criteria(PmTable::resolveDbSource($row['DBS_UID']));
$externalCriteria->addSelectColumn(($className . "Peer")::COUNT);
//if the external database is not available we catch the exception.
try {
$externalResultSet = ($className . "Peer")::doSelectRS($externalCriteria);
if ($externalResultSet->next()) {
$stringCount = $externalResultSet->getInt(1);
}
} catch (Exception $externalException) {
$context = Bootstrap::getDefaultContextLog();
$context = array_merge($context, $row);
Bootstrap::registerMonolog("additional tables", 400, $externalException->getMessage(), $context);
}
}
}
$stringBuild = $stringBuild
. "WHEN '" . $row["ADD_TAB_NAME"]
. "' THEN " . $stringCount

View File

@@ -63,6 +63,9 @@ class MultiProcOpen
sleep($this->sleepTime); //this sleep is very important
$i = 0;
$n = count($processes);
if ($n === 0) {
return [];
}
$outputs = [];
do {
$index = $i % $n;