Verified Commit 0588470c authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Add counter on message references to avoid duplicate identifiers

parent 8a27a294
......@@ -131,12 +131,28 @@ class ArchiveDeliveryRequest extends abstractMessage
$archivesByOriginator[$archive->originatorOrgRegNumber][] = $archive;
}
$counter = 0;
if (!$identifier) {
$identifier = "archiveDeliveryRequest_".date("Y-m-d-H-i-s");
}
$reference = $identifier;
foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) {
$messageIdentifier = $identifier ? $identifier."_".++$counter : "archiveDeliveryRequest_".\laabs::newId();
$i = 1;
$unique = array(
'type' => 'ArchiveDeliveryRequest',
'senderOrgRegNumber' => $requesterOrgRegNumber,
'reference' => $reference,
);
while ($this->sdoFactory->exists("medona/message", $unique)) {
$i++;
$unique['reference'] = $reference = $identifier.'_'.$i;
}
$archiverOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$message = $this->send($messageIdentifier, $archives, $derogation, $comment, $requesterOrgRegNumber, $archiverOrgRegNumber);
$message = $this->send($reference, $archives, $derogation, $comment, $requesterOrgRegNumber, $archiverOrgRegNumber);
$messages[] = $message;
}
......
......@@ -70,18 +70,27 @@ class ArchiveDestruction
}
$requesterOrgRegNumber = $requesterOrg->registrationNumber;
$i = 0;
if (!$identifier) {
$identifier = "archiveDestructionRequest_".date("Y-m-d-H-i-s");
}
$reference = $identifier;
foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) {
$i = 1;
$recipientOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$i++;
if (!$identifier) {
$identifier = "archiveDestructionRequest_".\laabs::newId();
} else {
$identifier .= "_".$i;
$unique = array(
'type' => 'ArchiveDestructionRequest',
'senderOrgRegNumber' => $requesterOrgRegNumber,
'reference' => $reference,
);
while ($this->sdoFactory->exists("medona/message", $unique)) {
$i++;
$unique['reference'] = $reference = $identifier.'_'.$i;
}
$archiveDestructionRequestController->send($identifier, $archives, $comment, $requesterOrgRegNumber, $recipientOrgRegNumber, $originatorOrgRegNumber);
$archiveDestructionRequestController->send($reference, $archives, $comment, $requesterOrgRegNumber, $recipientOrgRegNumber, $originatorOrgRegNumber);
}
return $archiveList;
......
......@@ -169,17 +169,29 @@ class ArchiveModification
}
$archiveModificationNotificationController = \laabs::newController("medona/ArchiveModificationNotification");
$i = 0;
if (!$identifier) {
$identifier = "archiveModificationNotification_".date("Y-m-d-H-i-s");
}
$reference = $identifier;
foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) {
$i = 1;
$senderOrg = $archives[0]->archiverOrgRegNumber;
$recipientOrg = $originatorOrgRegNumber;
if ($identifier) {
$unique = array(
'type' => 'ArchiveModificationNotification',
'senderOrgRegNumber' => $senderOrg,
'reference' => $reference,
);
while ($this->sdoFactory->exists("medona/message", $unique)) {
$i++;
$identifier .= "_".$i;
$message = $archiveModificationNotificationController->send((string) $identifier, $archives, $senderOrg, $recipientOrg, $comment);
} else {
$message = $archiveModificationNotificationController->send((string) \laabs::newId(), $archives, $senderOrg, $recipientOrg, $comment);
$unique['reference'] = $reference = $identifier.'_'.$i;
}
$message = $archiveModificationNotificationController->send($reference, $archives, $senderOrg, $recipientOrg, $comment);
}
}
}
......@@ -253,17 +253,15 @@ class ArchiveRestitution extends abstractMessage
}
$result = array('success' => array(), 'error' => array());
$counter = 0;
$archiveRestitutionRequestController = \laabs::newController("medona/ArchiveRestitutionRequest");
foreach ($archivesIdsByOriginator as $originatorOrgRegNumber => $archiveIds) {
$communicable = $this->archiveController->accessVerification(($archiveIds[0]));
if (!$communicable) {
$result["error"] = array_merge($result["error"], $archiveIds);
continue;
}
if (!$identifier) {
$identifier = "archiveModificationNotification_".date("Y-m-d-H-i-s");
}
$reference = $identifier;
foreach ($archivesIdsByOriginator as $originatorOrgRegNumber => $archiveIds) {
$candidates = $this->archiveController->setForRestitution($archiveIds);
$result["success"] = array_merge($result["success"], $candidates["success"]);
$result["error"] = array_merge($result["error"], $candidates["error"]);
......@@ -280,11 +278,22 @@ class ArchiveRestitution extends abstractMessage
continue;
}
$messageIdentifier = $identifier ? $identifier."_".++$counter : "archiveRestitutionRequest_".\laabs::newId();
$i = 1;
$unique = array(
'type' => 'ArchiveModificationNotification',
'senderOrgRegNumber' => $senderOrgRegNumber,
'reference' => $reference,
);
while ($this->sdoFactory->exists("medona/message", $unique)) {
$i++;
$unique['reference'] = $reference = $identifier.'_'.$i;
}
$recipientOrgRegNumber = $archivesForRestitution[0]->archiverOrgRegNumber;
$archiveRestitutionRequestController->send($messageIdentifier, $archivesForRestitution, $comment, $senderOrgRegNumber, $recipientOrgRegNumber, $userName);
$archiveRestitutionRequestController->send($reference, $archivesForRestitution, $comment, $senderOrgRegNumber, $recipientOrgRegNumber, $userName);
}
return $result;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment