14 namespace Fossology\DecisionImporter;
19 use UnexpectedValueException;
21 require_once
"FoDecisionData.php";
63 $this->pfileDao = $pfileDao;
64 $this->licenseDao = $licenseDao;
150 ->setUploadtreeList($uploadTreeList)
151 ->setClearingDecisionList($clearingDecisionList)
152 ->setCopyrightList($copyrightList)
153 ->setCopyrightDecisionList($copyrightDecisionList)
154 ->setCopyrightEventList($copyrightEventList)
155 ->setEccList($eccList)
156 ->setEccDecisionList($eccDecisionList)
157 ->setEccEventList($eccEventList)
158 ->setIpraList($ipraList)
159 ->setIpraDecisionList($ipraDecisionList)
160 ->setIpraEventList($ipraEventList)
161 ->setLicensesList($licenseList)
162 ->setClearingEventList($clearingEventList)
163 ->setLicenseSetBulkList($licenseSetBulkList)
164 ->setMainLicenseList($mainLicenseList);
173 foreach ($pfileList as $oldId => $item) {
174 $hash = $item[
"hash"];
175 $hashList = explode(
".", $item[
"hash"]);
176 $pfile = $this->pfileDao->getPfile($hashList[0], $hashList[1],
null, $hashList[2]);
177 if ($pfile ==
null) {
178 echo
"Can't find pfile with hash '$hash' in DB";
180 $pfileList[$oldId][
"new_pfile"] = $pfile[
'pfile_pk'];
193 $sqlAllTree =
"SELECT * FROM uploadtree WHERE upload_fk = $1 AND ufile_mode & (1<<28) = 0;";
194 $statementAllTree = __METHOD__ .
".allTree";
195 $allUploadTree = $this->
dbManager->getRows($sqlAllTree, [$this->uploadId], $statementAllTree);
197 foreach ($uploadTreeList as $oldItemId => $item) {
198 $new_pfile = $pfileList[$item[
"old_pfile"]][
"new_pfile"];
201 foreach ($allUploadTree as $index => $uploadTreeItem) {
202 if ($uploadTreeItem[
"pfile_fk"] == $new_pfile) {
203 if (array_key_exists(
"path", $item)) {
204 $newpath =
Dir2Path($uploadTreeItem[
"uploadtree_pk"]);
205 $newpath = implode(
"/", array_column($newpath,
"ufile_name"));
206 if ($newpath == $item[
"path"]) {
207 $matchIndex = $index;
210 } elseif ($uploadTreeItem[
"lft"] == $item[
"lft"] && $uploadTreeItem[
"rgt"] == $item[
"rgt"]) {
211 $matchIndex = $index;
221 if ($matchIndex == -INF) {
223 if (array_key_exists(
"path", $item)) {
224 $path = $item[
"path"];
226 echo
"Can't find item with pfile '$new_pfile' in upload " .
227 "'$this->uploadId'.\nIgnoring: $path";
228 $uploadTreeList[$oldItemId][
"new_itemid"] =
null;
230 $uploadTreeList[$oldItemId][
"new_itemid"] = $allUploadTree[$matchIndex][
"uploadtree_pk"];
248 foreach ($clearingDecisionList as $index => $item) {
249 $newItemId = $uploadTreeList[$item[
"old_itemid"]][
"new_itemid"];
250 $newPfileId = $pfileList[$item[
"old_pfile"]][
"new_pfile"];
251 $clearingDecisionList[$index][
"new_itemid"] = $newItemId;
252 $clearingDecisionList[$index][
"new_pfile"] = $newPfileId;
263 foreach ($cxList as $index => $item) {
264 $newPfileId = $pfileList[$item[
"old_pfile"]][
"new_pfile"];
265 $cxList[$index][
"new_pfile"] = $newPfileId;
276 foreach ($decisionList as $index => $decisionItem) {
277 $newPfileId = $pfileList[$decisionItem[
"old_pfile"]][
"new_pfile"];
278 $decisionList[$index][
"new_pfile"] = $newPfileId;
289 foreach ($eventList as $index => $eventItem) {
290 if (!array_key_exists($eventItem[
"old_itemid"], $uploadtreeList)) {
291 echo
"Unable to find item id for old_id: " . $eventItem[
"old_itemid"] .
"\n";
294 $newItemId = $uploadtreeList[$eventItem[
"old_itemid"]][
"new_itemid"];
296 $eventList[$index][
"new_itemid"] = $newItemId;
306 foreach ($licenseList as $index => $item) {
307 $newLicenseId =
null;
308 $license = $this->licenseDao->getLicenseByShortName($item[
"rf_shortname"], $this->groupId);
309 if ($license ==
null) {
311 "rf_fullname" => $item[
"rf_fullname"],
312 "rf_url" => $item[
"rf_url"],
313 "rf_notes" => $item[
"rf_notes"],
314 "rf_risk" => $item[
"rf_risk"],
315 "rf_md5" => $item[
"rf_md5"],
317 if ($item[
"is_candidate"] ==
"t") {
318 $newLicenseId = $this->licenseDao->insertUploadLicense($item[
"rf_shortname"], $item[
"rf_text"],
319 $this->groupId, $this->userId);
321 $newLicenseId = $this->licenseDao->insertLicense($item[
"rf_shortname"], $item[
"rf_text"]);
323 $this->
dbManager->updateTableRow(
"license_ref", $newLicenseData,
"rf_pk", $newLicenseId);
325 $newLicenseId = $license->getId();
327 $licenseList[$index][
"new_rfid"] = $newLicenseId;
337 private function updateClearingEvent(array &$clearingEventList, array $uploadTreeList, array $licenseList): void
339 foreach ($clearingEventList as $index => $item) {
340 $newItemId = $uploadTreeList[$item[
"old_itemid"]][
"new_itemid"];
341 $newLicenseId = $licenseList[$item[
"old_rfid"]][
"new_rfid"];
342 $clearingEventList[$index][
"new_itemid"] = $newItemId;
343 $clearingEventList[$index][
"new_rfid"] = $newLicenseId;
354 foreach ($licenseSetBulkList as $lrbId => $licenseSetBulks) {
355 foreach ($licenseSetBulks as $index => $licenseSetBulkItem) {
356 $newRfId = $licenseList[$licenseSetBulkItem[
"old_rfid"]][
"new_rfid"];
357 $licenseSetBulkList[$lrbId][$index][
"new_rfid"] = $newRfId;
369 foreach ($mainLicenseList as $oldId => $mainLicenseItem) {
370 $newLicenseId = $licenseList[$mainLicenseItem[
"old_rfid"]][
"new_rfid"];
371 $mainLicenseList[$oldId][
"new_rfid"] = $newLicenseId;
Import decisions generated by Decision Exporter from JSON files.
setUploadId(int $uploadId)
updateMainLicenseList(array &$mainLicenseList, array $licenseList)
updateCxList(array &$cxList, array $pfileList)
updateLicenses(array &$licenseList)
__construct(DbManager $dbManager, PfileDao $pfileDao, LicenseDao $licenseDao)
updateClearingEvent(array &$clearingEventList, array $uploadTreeList, array $licenseList)
updateEventList(array &$eventList, array $uploadtreeList)
getOrCreateIds(FoDecisionData &$reportData, DecisionImporterAgent &$agentObj)
updateLicenseSetBulk(array &$licenseSetBulkList, array $licenseList)
updateClearingDecision(array &$clearingDecisionList, array $uploadTreeList, array $pfileList)
updateDecisionList(array &$decisionList, array $pfileList)
updatePfileIds(array &$pfileList)
updateUploadTreeIds(array &$uploadTreeList, array $pfileList, DecisionImporterAgent &$agentObj)
setPfileList(array $pfileList)
getCopyrightDecisionList()
getClearingDecisionList()
heartbeat($newProcessed)
Send hear beat to the scheduler.
Dir2Path($uploadtree_pk, $uploadtree_tablename='uploadtree')
Return the path (without artifacts) of an uploadtree_pk.
fo_dbManager * dbManager
fo_dbManager object