logging, new unique ID and improve start case

This commit is contained in:
Fernando Ontiveros
2025-04-24 17:55:41 +00:00
parent 85020fbdbd
commit 66d2c7a6a4
5 changed files with 69 additions and 45 deletions

View File

@@ -42,16 +42,16 @@ return [
'single' => [ 'single' => [
'driver' => 'single', 'driver' => 'single',
'path' => storage_path('logs/processmaker.log'), 'path' => storage_path('logs/laravel.log'),
'level' => 'debug', 'level' => 'debug',
], ],
'daily' => [ 'daily' => [
'driver' => 'daily', 'driver' => 'daily',
'tap' => [App\Logging\CustomizeFormatter::class], 'tap' => [App\Logging\CustomizeFormatter::class],
'path' => storage_path('logs/processmaker.log'), 'path' => storage_path('logs/laravel.log'),
'level' => 'debug', 'level' => 'debug',
'days' => $app->make('config')->get('app.log_max_files', 60), 'days' => $app->make('config')->get('app.log_max_files', 30),
], ],
'audit' => [ 'audit' => [
@@ -59,7 +59,7 @@ return [
'tap' => [App\Logging\CustomizeFormatter::class], 'tap' => [App\Logging\CustomizeFormatter::class],
'path' => storage_path('logs/audit.log'), 'path' => storage_path('logs/audit.log'),
'level' => 'debug', 'level' => 'debug',
'days' => $app->make('config')->get('app.log_max_files', 60), 'days' => $app->make('config')->get('app.log_max_files', 30),
], ],
'taskScheduler' => [ 'taskScheduler' => [
@@ -67,25 +67,7 @@ return [
'tap' => [App\Logging\CustomizeFormatter::class], 'tap' => [App\Logging\CustomizeFormatter::class],
'path' => storage_path('logs/taskScheduler.log'), 'path' => storage_path('logs/taskScheduler.log'),
'level' => 'debug', 'level' => 'debug',
'days' => $app->make('config')->get('app.log_max_files', 60), 'days' => $app->make('config')->get('app.log_max_files', 30),
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'papertrail' => [
'driver' => 'monolog',
'level' => 'debug',
'handler' => SyslogUdpHandler::class,
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
],
], ],
'stderr' => [ 'stderr' => [

View File

@@ -2858,6 +2858,31 @@ class G
//return strtoupper(substr(uniqid(rand(0, 9), false),0,14)); //return strtoupper(substr(uniqid(rand(0, 9), false),0,14));
} }
/**
* Generate random number
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return int
*/
public static function generateUid($prefix = '')
{
// Ensure the prefix is exactly 3 alphabetical characters if not return default prefix
if (strlen($prefix) !== 3 || !ctype_alpha($prefix)) {
$prefix = "abc";
}
// Generate a unique ID based on the current time in microseconds
$uniqueId = uniqid('', true);
// Remove the prefix from the unique ID and ensure it's 29 characters long
$uniqueId = date('YmdH') . str_replace('.', '', $uniqueId); // Remove any dots
$uniqueId = substr($uniqueId, -29); // Trim to 29 characters
// Combine the prefix with the unique ID
return strtolower($prefix) . $uniqueId; // Convert prefix to uppercase
}
/** /**
* Generate a numeric or alphanumeric code * Generate a numeric or alphanumeric code
* *
@@ -2873,19 +2898,23 @@ class G
if (($sType != 'NUMERIC') && ($sType != 'ALPHA') && ($sType != 'ALPHANUMERIC')) { if (($sType != 'NUMERIC') && ($sType != 'ALPHA') && ($sType != 'ALPHANUMERIC')) {
$sType = 'NUMERIC'; $sType = 'NUMERIC';
} }
$aValidCharacters = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); // Define a character set excluding visually similar characters
$aValidCharacters = array(
'2', '3', '4', '5', '6', '7', '8', '9', // Numbers excluding 0 and 1
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'V', 'W', 'X', 'Y' // Uppercase letters excluding O, I, L, S, Z
);
switch ($sType) { switch ($sType) {
case 'NUMERIC': case 'NUMERIC':
$iMin = 0; $iMin = 0;
$iMax = 9; $iMax = 7;
break; break;
case 'ALPHA': case 'ALPHA':
$iMin = 10; $iMin = 8;
$iMax = 35; $iMax = 28;
break; break;
case 'ALPHANUMERIC': case 'ALPHANUMERIC':
$iMin = 0; $iMin = 0;
$iMax = 35; $iMax = 28;
break; break;
} }
$sCode = ''; $sCode = '';

View File

@@ -2163,10 +2163,11 @@ class Cases
$event = new Event(); $event = new Event();
$event->createAppEvents($proUid, $appUid, $delIndex, $tasUid); $event->createAppEvents($proUid, $appUid, $delIndex, $tasUid);
//todo: remove Solr
// Update solr // Update solr
if ($this->appSolr != null) { //if ($this->appSolr != null) {
$this->appSolr->updateApplicationSearchIndex($appUid); // $this->appSolr->updateApplicationSearchIndex($appUid);
} //}
$fields['TAS_UID'] = $tasUid; $fields['TAS_UID'] = $tasUid;
$fields['USR_UID'] = $usrUid; $fields['USR_UID'] = $usrUid;
@@ -2197,7 +2198,7 @@ class Cases
// Log // Log
$message = 'Create case'; $message = 'Create case';
$context = $data = [ $context = [
"appUid" => $appUid, "appUid" => $appUid,
"usrUid" => $usrUid, "usrUid" => $usrUid,
"tasUid" => $tasUid, "tasUid" => $tasUid,
@@ -2207,14 +2208,17 @@ class Cases
"appInitDate" => $fields['APP_INIT_DATE'] "appInitDate" => $fields['APP_INIT_DATE']
]; ];
Log::channel(':CreateCase')->info($message, Bootstrap::context($context)); Log::channel(':CreateCase')->info($message, Bootstrap::context($context));
// Call plugin // Call plugin
if (class_exists('folderData')) { if (class_exists('folderData')) {
$folderData = new folderData($proUid, $proFields['PRO_TITLE'], $appUid, '', $usrUid); $folderData = new folderData($proUid, $proFields['PRO_TITLE'], $appUid, '', $usrUid);
$oPluginRegistry = PluginRegistry::loadSingleton(); $oPluginRegistry = PluginRegistry::loadSingleton();
$oPluginRegistry->executeTriggers(PM_CREATE_CASE, $folderData); $oPluginRegistry->executeTriggers(PM_CREATE_CASE, $folderData);
} }
$this->getExecuteTriggerProcess($appUid, 'CREATE', false);
//end plugin //end plugin
//Exceute trigger if any configured for this create case
$this->getExecuteTriggerProcess($appUid, 'CREATE', false);
return [ return [
'APPLICATION' => $appUid, 'APPLICATION' => $appUid,
'INDEX' => $delIndex, 'INDEX' => $delIndex,

View File

@@ -181,22 +181,29 @@ class Application extends BaseApplication
} }
/** /**
* Creates an Application * Creates a new Application entry in the database.
* *
* @param string $processUid * This method initializes a new application with default values and saves it to the database.
* @param string $userUid * It generates a unique application ID, sets various properties related to the application,
* @param string $sequenceType * and handles the creation process within a database transaction.
* @throws PropelException *
* @throws Exception * @param string $processUid The unique identifier for the process associated with the application.
* @return string * @param string $userUid The unique identifier for the user initiating the application.
* @param string $sequenceType The type of sequence to be used for generating the application number NORMAL or WEBENTRY.
*
* @throws PropelException If the application cannot be created due to validation failures or database errors.
* @throws Exception If an unexpected error occurs during the application creation process.
*
* @return string Returns the unique identifier of the newly created application.
*/ */
public function create($processUid, $userUid, $sequenceType) public function create($processUid, $userUid, $sequenceType)
{ {
$con = Propel::getConnection('workflow'); $con = Propel::getConnection('workflow');
try { try {
// Fill the default values for new application row // Fill the default values for new application row
$this->setAppUid(G::generateUniqueID()); $this->setAppUid(G::generateUid('app'));
$this->setAppParent(''); $this->setAppParent('');
$this->setAppStatus('DRAFT'); $this->setAppStatus('DRAFT');
$this->setAppStatusId(1); $this->setAppStatusId(1);

View File

@@ -35,6 +35,7 @@ if (! function_exists( $_REQUEST['action'] ) || !G::isUserFunction($_REQUEST['ac
die(); die();
} }
$functionName = $_REQUEST['action']; $functionName = $_REQUEST['action'];
$functionParams = isset( $_REQUEST['params'] ) ? $_REQUEST['params'] : array (); $functionParams = isset( $_REQUEST['params'] ) ? $_REQUEST['params'] : array ();
@@ -209,7 +210,6 @@ function startCase()
try { try {
// Initializing variables // Initializing variables
$sequenceType = (!empty($_REQUEST['actionFrom']) && $_REQUEST['actionFrom'] === 'webEntry') ? AppSequence::APP_TYPE_WEB_ENTRY : AppSequence::APP_TYPE_NORMAL; $sequenceType = (!empty($_REQUEST['actionFrom']) && $_REQUEST['actionFrom'] === 'webEntry') ? AppSequence::APP_TYPE_WEB_ENTRY : AppSequence::APP_TYPE_NORMAL;
// Update CONTENT table // Update CONTENT table
lookinginforContentProcess($_POST['processId']); lookinginforContentProcess($_POST['processId']);
@@ -237,11 +237,13 @@ function startCase()
$newCase['status'] = 'success'; $newCase['status'] = 'success';
// Print JSON response // Print JSON response
print (G::json_encode($newCase)); ob_end_clean();
header('Content-Type: application/json');
print (json_encode($newCase));
} catch (Exception $e) { } catch (Exception $e) {
$newCase['status'] = 'failure'; $newCase['status'] = 'failure';
$newCase['message'] = $e->getMessage(); $newCase['message'] = $e->getMessage();
print_r(G::json_encode($newCase)); print_r(json_encode($newCase));
} }
} }