Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/decisionexporter/agent/decisionexporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ function processUploadId($uploadId)
$tableName = "decision_exporter_pfile_" . $uploadId;

$pfileData = $this->allDecisionsDao->getAllAgentPfileIdsForUpload($uploadId, $groupId, $userId);
if (!empty($pfileData)) {
$this->createPfileTable($uploadId, $tableName);
}
$this->createPfileTable($uploadId, $tableName);
$this->heartbeat(count($pfileData));

$this->insertPfileData($uploadId, $pfileData, $tableName);
$this->heartbeat(1);
$uploadTreeData = $this->allDecisionsDao->getAllAgentUploadTreeDataForUpload($uploadId, $tableName);
Expand Down Expand Up @@ -124,9 +123,8 @@ function processUploadId($uploadId)
'licenses'=>$licenseData,
'upload_clearing_license'=>array_values($mainLicenseData)
);
if (!empty($pfileData)) {
$this->dropPfileTable($uploadId, $tableName);
}

$this->dropPfileTable($uploadId, $tableName);
$this->writeReport($contents, $uploadId);

return true;
Expand Down
55 changes: 33 additions & 22 deletions src/decisionimporter/agent/DecisionImporterDataCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,19 @@ public function createClearingDecisions(FoDecisionData &$reportData,

$i = 0;
foreach ($clearingDecisionList as $oldDecisionId => $decisionItem) {
$newCdId = $this->dbManager->insertTableRow("clearing_decision", [
"uploadtree_fk" => $decisionItem["new_itemid"],
"pfile_fk" => $decisionItem["new_pfile"],
"decision_type" => $decisionItem["decision_type"],
"group_fk" => $this->groupId,
"user_fk" => $this->userId,
"scope" => $decisionItem["scope"],
"date_added" => $decisionItem["date_added"]
], __METHOD__ . ".insertCd", "clearing_decision_pk");
if ($decisionItem["new_itemid"] !== null) {
$newCdId = $this->dbManager->insertTableRow("clearing_decision", [
"uploadtree_fk" => $decisionItem["new_itemid"],
"pfile_fk" => $decisionItem["new_pfile"],
"decision_type" => $decisionItem["decision_type"],
"group_fk" => $this->groupId,
"user_fk" => $this->userId,
"scope" => $decisionItem["scope"],
"date_added" => $decisionItem["date_added"]
], __METHOD__ . ".insertCd", "clearing_decision_pk");
} else {
$newCdId = null;
}
$clearingDecisionList[$oldDecisionId]["new_decision"] = $newCdId;
$i++;
if ($i == DecisionImporterAgent::$UPDATE_COUNT) {
Expand All @@ -163,19 +167,23 @@ public function createClearingDecisions(FoDecisionData &$reportData,

$i = 0;
foreach ($clearingEventList as $oldEventId => $eventItem) {
$newCeId = $this->dbManager->insertTableRow("clearing_event", [
"uploadtree_fk" => $eventItem["new_itemid"],
"rf_fk" => $eventItem["new_rfid"],
"removed" => $eventItem["removed"],
"user_fk" => $this->userId,
"group_fk" => $this->groupId,
"job_fk" => null,
"type_fk" => $eventItem["type_fk"],
"comment" => $eventItem["comment"],
"reportinfo" => $eventItem["reportinfo"],
"acknowledgement" => $eventItem["acknowledgement"],
"date_added" => $eventItem["date_added"]
], __METHOD__ . ".insertCe", "clearing_event_pk");
if ($eventItem["new_itemid"] !== null) {
$newCeId = $this->dbManager->insertTableRow("clearing_event", [
"uploadtree_fk" => $eventItem["new_itemid"],
"rf_fk" => $eventItem["new_rfid"],
"removed" => $eventItem["removed"],
"user_fk" => $this->userId,
"group_fk" => $this->groupId,
"job_fk" => null,
"type_fk" => $eventItem["type_fk"],
"comment" => $eventItem["comment"],
"reportinfo" => $eventItem["reportinfo"],
"acknowledgement" => $eventItem["acknowledgement"],
"date_added" => $eventItem["date_added"]
], __METHOD__ . ".insertCe", "clearing_event_pk");
} else {
$newCeId = null;
}
$clearingEventList[$oldEventId]["new_event"] = $newCeId;
$i++;
if ($i == DecisionImporterAgent::$UPDATE_COUNT) {
Expand All @@ -189,6 +197,9 @@ public function createClearingDecisions(FoDecisionData &$reportData,

foreach ($clearingDecisionEventList as $oldCdId => $ceList) {
$newCdId = $clearingDecisionList[$oldCdId]["new_decision"];
if ($newCdId === null) {
continue;
}
foreach ($ceList as $oldCeId) {
$newCeId = $clearingEventList[$oldCeId]["new_event"];
$this->dbManager->insertTableRow("clearing_decision_event", [
Expand Down
17 changes: 15 additions & 2 deletions src/decisionimporter/agent/DecisionImporterIdFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private function updateUploadTreeIds(array &$uploadTreeList, array $pfileList,
foreach ($uploadTreeList as $oldItemId => $item) {
$new_pfile = $pfileList[$item["old_pfile"]]["new_pfile"];
$matchIndex = -INF;
$j = 0;
foreach ($allUploadTree as $index => $uploadTreeItem) {
if ($uploadTreeItem["pfile_fk"] == $new_pfile) {
if (array_key_exists("path", $item)) {
Expand All @@ -211,11 +212,23 @@ private function updateUploadTreeIds(array &$uploadTreeList, array $pfileList,
break;
}
}
$j++;
if ($j == DecisionImporterAgent::$UPDATE_COUNT) {
$agentObj->heartbeat(0);
$j = 0;
}
}
if ($matchIndex == -INF) {
throw new UnexpectedValueException("Can't find item with pfile '$new_pfile' in upload '$this->uploadId'");
$path = $oldItemId;
if (array_key_exists("path", $item)) {
$path = $item["path"];
}
echo "Can't find item with pfile '$new_pfile' in upload " .
"'$this->uploadId'.\nIgnoring: $path";
$uploadTreeList[$oldItemId]["new_itemid"] = null;
} else {
$uploadTreeList[$oldItemId]["new_itemid"] = $allUploadTree[$matchIndex]["uploadtree_pk"];
}
$uploadTreeList[$oldItemId]["new_itemid"] = $allUploadTree[$matchIndex]["uploadtree_pk"];
$i++;
if ($i == DecisionImporterAgent::$UPDATE_COUNT) {
$agentObj->heartbeat(0);
Expand Down