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