Commit c7c0a408 authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

FIX : destructionRequests manages originators AND their ascendants requesters

parent dca3da12
......@@ -105,11 +105,11 @@ class ArchiveDeliveryRequest extends abstractMessage
*/
public function requestDelivery($archiveIds, $identifier = null, $comment = null)
{
$senderOrg = \laabs::getToken('ORGANIZATION');
if (!$senderOrg) {
$requesterOrg = \laabs::getToken('ORGANIZATION');
if (!$requesterOrg) {
throw \laabs::newException('medona/invalidMessageException', "No current organization choosen");
}
$senderOrgRegNumber = $senderOrg->registrationNumber;
$requesterOrgRegNumber = $requesterOrg->registrationNumber;
if (!is_array($archiveIds)) {
$archiveIds = array($archiveIds);
......@@ -145,8 +145,8 @@ class ArchiveDeliveryRequest extends abstractMessage
}
}
$recipientOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$message = $this->send($messageIdentifier, $archives, $derogation, $comment, $senderOrgRegNumber, $recipientOrgRegNumber);
$archiverOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$message = $this->send($messageIdentifier, $archives, $derogation, $comment, $requesterOrgRegNumber, $archiverOrgRegNumber);
$controlAutorityControler = \laabs::newController("medona/ControlAuthority");
if (count($controlAutorityControler->index()) > 0) {
......@@ -167,13 +167,13 @@ class ArchiveDeliveryRequest extends abstractMessage
* @param array $archives An array of archives
* @param boolean $derogation Ask for an authorization
* @param string $comment The request comment
* @param object $senderOrgRegNumber The requesting org
* @param string $recipientOrgRegNumber The recipient org registration number
* @param object $requesterOrgRegNumber The requesting org reg number
* @param string $archiverOrgRegNumber The archiver org registration number
* @param string $userName The requester user name
*
* @return The reply message generated
*/
public function send($reference, $archives, $derogation = false, $comment = false, $senderOrgRegNumber = false, $recipientOrgRegNumber = false, $userName = false)
public function send($reference, $archives, $derogation = false, $comment = false, $requesterOrgRegNumber = false, $archiverOrgRegNumber = false, $userName = false)
{
if (!is_array($archives)) {
$archives = array($archives);
......@@ -195,8 +195,8 @@ class ArchiveDeliveryRequest extends abstractMessage
$message->comment[] = $comment;
$message->senderOrgRegNumber = $senderOrgRegNumber;
$message->recipientOrgRegNumber = $recipientOrgRegNumber;
$message->senderOrgRegNumber = $requesterOrgRegNumber;
$message->recipientOrgRegNumber = $archiverOrgRegNumber;
// read org names, addresses, communications, contacts
$this->readOrgs($message);
......
......@@ -50,7 +50,7 @@ class ArchiveDestruction
{
$archiveList = $this->archiveController->dispose($archiveIds);
$archiveDestructionController = \laabs::newController("medona/ArchiveDestructionRequest");
$archiveDestructionRequestController = \laabs::newController("medona/ArchiveDestructionRequest");
$archivesByOriginator = array();
foreach ($archiveList['success'] as $archiveId) {
......@@ -61,18 +61,18 @@ class ArchiveDestruction
$archivesByOriginator[$archive->originatorOrgRegNumber][] = $archive;
}
$senderOrg = null;
if (!$senderOrg) {
$senderOrg = \laabs::getToken('ORGANIZATION');
if (!$senderOrg) {
$requesterOrg = null;
if (!$requesterOrg) {
$requesterOrg = \laabs::getToken('ORGANIZATION');
if (!$requesterOrg) {
throw \laabs::newException('medona/invalidMessageException', "No current organization choosen");
}
}
$senderOrg = $senderOrg->registrationNumber;
$requesterOrgRegNumber = $requesterOrg->registrationNumber;
$i = 0;
foreach ($archivesByOriginator as $originatorOrgRegNumber => $archives) {
$recipientOrg = $archives[0]->archiverOrgRegNumber;
$recipientOrgRegNumber = $archives[0]->archiverOrgRegNumber;
$i++;
if (!$identifier) {
......@@ -81,7 +81,7 @@ class ArchiveDestruction
$identifier .= "_".$i;
}
$archiveDestructionController->send($identifier, $archives, $comment, $senderOrg, $recipientOrg);
$archiveDestructionRequestController->send($identifier, $archives, $comment, $requesterOrgRegNumber, $recipientOrgRegNumber, $originatorOrgRegNumber);
}
return $archiveList;
......
......@@ -87,15 +87,16 @@ class ArchiveDestructionRequest extends abstractMessage
/**
* Send a new a new delivery request
* @param string $reference The message identifier
* @param array $archives An array of archives
* @param string $comment The request comment
* @param string $senderOrg The requesting org
* @param string $recipientOrg The requesting org
* @param string $reference The message identifier
* @param array $archives An array of archives
* @param string $comment The request comment
* @param string $requesterOrgRegNumber The requesting org reg number
* @param string $archiverOrgRegNumber The recipient archiver org reg number
* @param string $originatorOrgRegNumber The originator org reg number
*
* @return The request message generated
*/
public function send($reference, $archives, $comment = null, $senderOrg = null, $recipientOrg = null)
public function send($reference, $archives, $comment = null, $requesterOrgRegNumber = null, $archiverOrgRegNumber = null, $originatorOrgRegNumber=null)
{
if (!is_array($archives)) {
$archives = array($archives);
......@@ -117,8 +118,8 @@ class ArchiveDestructionRequest extends abstractMessage
$message->comment[] = $comment;
$message->senderOrgRegNumber = $senderOrg;
$message->recipientOrgRegNumber = $recipientOrg;
$message->senderOrgRegNumber = $requesterOrgRegNumber;
$message->recipientOrgRegNumber = $archiverOrgRegNumber;
$this->readOrgs($message); // read org names, addresses, communications, contacts
try {
......@@ -157,10 +158,12 @@ class ArchiveDestructionRequest extends abstractMessage
throw $e;
}
$senderOrg = \laabs::getToken('ORGANIZATION');
// Requested by archiver: send auth request to originator
if ($message->senderOrgRegNumber != $archives[0]->originatorOrgRegNumber) {
if ($senderOrg->registrationNumber == $message->recipientOrg) {
$authorizationOriginatingAgencyRequestController = \laabs::newController('medona/AuthorizationOriginatingAgencyRequest');
$authorizationOriginatingAgencyRequestController->send($message, $archives[0]->originatorOrgRegNumber);
$authorizationOriginatingAgencyRequestController->send($message, $originatorOrgRegNumber);
$message->status == "originator_authorization_wait";
} else {
......@@ -171,7 +174,7 @@ class ArchiveDestructionRequest extends abstractMessage
if (count($controlAuthorities)) {
$message->status == "control_authorization_wait";
$authorizationControlAuthorityRequestController = \laabs::newController('medona/AuthorizationControlAuthorityRequest');
$authorizationControlAuthorityRequestController->send($message, $archives[0]->originatorOrgRegNumber);
$authorizationControlAuthorityRequestController->send($message, $originatorOrgRegNumber);
}
}
......
......@@ -80,6 +80,7 @@ class ArchiveRestitutionRequest extends abstractMessage
$registrationNumber = $this->getCurrentRegistrationNumber();
$queryParts[] = "type='ArchiveRestitutionRequest'";
$queryParts[] = "senderOrgRegNumber=$registrationNumber";
$queryParts[] = "active=true";
return $this->sdoFactory->find('medona/message', implode(' and ', $queryParts), null, false, false, 300);
......
......@@ -23,18 +23,19 @@ namespace ext\thirdPartyArchiving\bundle\medona\Controller;
/**
* Class for originating agency request auhorisation message
*
* @author Alexis Ragot <alexis.ragot@maarch.org>
*/
class AuthorizationOriginatingAgencyRequest extends AuthorizationRequest
{
/**
* Send authorization originating agency request
* @param string $requestMessage The request message identifier
* @param string $recipientOrgRegNumber The originating agency reg number
* @param string $requestMessage The request message identifier
* @param string $originatorOrgRegNumber The originating agency reg number
*
* @return medona/message
*/
public function send($requestMessage, $recipientOrgRegNumber)
public function send($requestMessage, $originatorOrgRegNumber)
{
if (is_scalar($requestMessage)) {
$requestMessage = $this->read($requestMessage);
......@@ -54,7 +55,7 @@ class AuthorizationOriginatingAgencyRequest extends AuthorizationRequest
$message->authorizationReason = $requestMessage->type;
$message->senderOrgRegNumber = $requestMessage->recipientOrgRegNumber;
$message->recipientOrgRegNumber = $recipientOrgRegNumber;
$message->recipientOrgRegNumber = $originatorOrgRegNumber;
$message->comment = $requestMessage->object->comment;
$this->readOrgs($message);
......
......@@ -93,11 +93,11 @@ class message
$messageDirectory,
\dependency\sdo\Factory $sdoFactory,
$messageStandard = 'medona',
$parentsDerogation = false,
$parentsDerogation = true,
$removeMessageTask = null,
$autoValidateSize = 0,
$autoProcessSize = 0
) {
$autoProcessSize = 0)
{
$this->orgController = \laabs::newController('organization/organization');
$this->archiveController = \laabs::newController('recordsManagement/archive');
$this->archiveRelationshipController = \laabs::newController('recordsManagement/archiveRelationship');
......@@ -1119,7 +1119,8 @@ class message
*
* @return int The number of messages with this organization
*/
public function countByOrg($orgRegNumber) {
public function countByOrg($orgRegNumber)
{
$queryString = [];
$queryString[] = "senderOrgRegNumber='$orgRegNumber'";
$queryString[] = "recipientOrgRegNumber='$orgRegNumber'";
......
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