- Thu Nov 30, 2017 10:43 am
#812369
Hi, for the past day, I've been trying to make a script task work after a 1 minute timer event but this specific trigger doesn't work in it (if I reassign the task to myself and execute it, it works great so I don't think there is any fatal error in my trigger..). I used a timer event because the script trigger is pretty long (about 30 seconds) so we don't want the user to wait while populating the database with the excel fields.. I thought about using parallel tasks + timer event of 1 minute to delay the script task to execute so the user won't notice anything
I'm reading an excel calculation file with PHPExcel (it's installed and everything works great). After that, I'm sending the data in this file in my database (119 rows are inserted when i execute the trigger).
Here's the code:
I'm reading an excel calculation file with PHPExcel (it's installed and everything works great). After that, I'm sending the data in this file in my database (119 rows are inserted when i execute the trigger).
Here's the code:
Code: Select all
@@varRevision = 1;
if(@@uploaded_file_id != "")
{
$uploaded_file_id = @@uploaded_file_id;
$DOC_VERSION = @@uploaded_file_version;
$oAppDocument = new AppDocument();
$oAppDocument->Fields = $oAppDocument->load($uploaded_file_id, $DOC_VERSION);
$ext = pathinfo($oAppDocument->Fields['APP_DOC_FILENAME'], PATHINFO_EXTENSION);
$app_uid = G::getPathFromUID($oAppDocument->Fields['APP_UID']);
$file = G::getPathFromFileUID($oAppDocument->Fields['APP_UID'], $uploaded_file_id);
$realPath = PATH_DOCUMENT . $app_uid . '/' . $file[0] . $file[1] . '_' . $DOC_VERSION . '.' . $ext;
$realPath1 = PATH_DOCUMENT . $app_uid . '/' . $file[0] . $file[1] . '.' . $ext;
if(file_exists($realPath) || file_exists($realPath1))
{
if(!file_exists($realPath) && file_exists($realPath1))
{
$realPath = $realPath1;
}
@@realPath = $realPath;
require_once('../engine/PHPExcel/PHPExcel.php');
$excel_file_type = PHPExcel_IOFactory::identify($realPath);
@@excel_file_type=$excel_file_type;
if($excel_file_type == 'Excel5' || $excel_file_type == 'Excel2007')
{
$excel_reader = PHPExcel_IOFactory::createReader($excel_file_type);
$excel_reader->setReadDataOnly(true);
$excel_reader->setLoadSheetsOnly( array("Global") );
$excel = $excel_reader->load($realPath);
$excel_file_creator = $excel->getProperties()->getCreator();
$excel_file_created = $excel->getProperties()->getCreated();
$excel_sheets_temp = $excel->getSheetNames();
@=Excel_Sheets = array();
foreach($excel_sheets_temp AS $key => $row)
{
@=Excel_Sheets[] = array($key, $row);
}
@@Excel_File_PATH = $realPath;
@@fileName = $oAppDocument->Fields['APP_DOC_FILENAME'];
@@fileType = $excel_file_type;
@@uploader = $excel_file_creator;
@@dateUploaded = date('Y-m-d', $excel_file_created);
$aData = $excel->getActiveSheet()->toArray(null, true, true, true);
@@aData = $aData;
$queryType = "SELECT ID,NAME FROM QUALTECH_RFQ_CALCULATIONS_TYPES WHERE NAME='QS_CUSTOM'";
@@queryType = $queryType;
$resultType = executeQuery($queryType);
if(!empty($resultType) && count($resultType) > 0)
{
$idType = $resultType[1]['ID'];
$REVISION=@@varRevision;
$DATE_UPLOADED=@@dateUploaded;
$NAME=@@fileName;
$CASE_ID=@@APPLICATION;
$queryCalculationSelect = "SELECT * FROM QUALTECH_RFQ_CALCULATIONS WHERE CASE_ID='$CASE_ID' AND REVISION=$REVISION AND CALCULATIONS_TYPES_ID=$idType";
@@queryCalculationSelect = $queryCalculationSelect;
$resultCalculationsSelect = executeQuery($queryCalculationSelect);
if(!empty($resultCalculationsSelect) && count($resultCalculationsSelect) > 0)
{
$calculationId = $resultCalculationsSelect[1]['ID'];
$queryCalculation = "UPDATE QUALTECH_RFQ_CALCULATIONS SET DATE_UPLOADED='$DATE_UPLOADED',NAME='$NAME' WHERE CASE_ID='$CASE_ID' AND REVISION=$REVISION AND CALCULATIONS_TYPES_ID=$idType";
executeQuery($queryCalculation);
}
else
{
$queryCalculation = "INSERT INTO QUALTECH_RFQ_CALCULATIONS(CASE_ID,REVISION,CALCULATIONS_TYPES_ID,DATE_UPLOADED,NAME) VALUES('$CASE_ID',$REVISION,$idType,'$DATE_UPLOADED','$NAME')";
executeQuery($queryCalculation);
$queryCalculationSelect = "SELECT * FROM QUALTECH_RFQ_CALCULATIONS WHERE CASE_ID='$CASE_ID' AND REVISION=$REVISION AND CALCULATIONS_TYPES_ID=$idType";
$resultCalculationsSelect = executeQuery($queryCalculationSelect);
if(!empty($resultCalculationsSelect) && count($resultCalculationsSelect) > 0)
{
$calculationId = $resultCalculationsSelect[1]['ID'];
}
}
@@calculationId = $calculationId;
@@queryCalculation = $queryCalculation;
$queryFields = "SELECT CF.ID,CF.NAME,CF.CALCULATIONS_ZONES_ID,CF.CALCULATIONS_JOB_TYPES_ID,CF.CELL FROM wf_workflow.QUALTECH_RFQ_CALCULATIONS_FIELDS AS CF INNER JOIN
QUALTECH_RFQ_CALCULATIONS_TYPES AS CT ON CF.CALCULATIONS_TYPES_ID=CT.ID WHERE CT.ID=$idType";
@@queryFields = $queryFields;
$resultFields = executeQuery($queryFields);
if(!empty($resultFields) && count($resultFields) > 0)
{
for($i = 1; $i <= count($resultFields); $i++)
{
$fieldId = $resultFields[$i]['ID'];
$zoneId = $resultFields[$i]['CALCULATIONS_ZONES_ID'];
$jobTypeId = $resultFields[$i]['CALCULATIONS_JOB_TYPES_ID'];
$cell = $resultFields[$i]['CELL'];
$letter = preg_replace("/[^A-Z]+/", "", $cell);
$number = preg_replace('/[^0-9]/', '', $cell);
//$value = $aData[$number][$letter];
$value = $excel->getActiveSheet()->getCell($cell)->getOldCalculatedValue();
if($value != "" && $value != null)
{
$queryFieldValueSelect = "SELECT * FROM QUALTECH_RFQ_CALCULATIONS_FIELD_VALUES WHERE CALCULATIONS_FIELDS_ID=$fieldId AND CALCULATIONS_ID=$calculationId";
@@queryFieldValueSelect = $queryFieldValueSelect;
$resultFieldValueSelect = executeQuery($queryFieldValueSelect);
if(!empty($resultFieldValueSelect) && count($resultFieldValueSelect) > 0)
{
$queryFieldValue = "UPDATE QUALTECH_RFQ_CALCULATIONS_FIELD_VALUES SET VALUE='$value' WHERE CALCULATIONS_FIELDS_ID=$fieldId AND CALCULATIONS_ID=$calculationId";
}
else
{
$queryFieldValue = "INSERT INTO QUALTECH_RFQ_CALCULATIONS_FIELD_VALUES(CALCULATIONS_FIELDS_ID,CALCULATIONS_ID,VALUE) VALUES($fieldId,$calculationId,'$value')";
}
@@queryFieldValue = $queryFieldValue;
executeQuery($queryFieldValue);
}
}
}
}
}
}
}