Commit 1f2a3e61 authored by Arnaud Pauget's avatar Arnaud Pauget
Browse files

feat() : add presenter on changing originator to custom message and preparing for multi changing

parent a60bf6bf
Pipeline #14353 failed with stages
in 1 minute and 2 seconds
......@@ -979,30 +979,48 @@ trait archiveModificationTrait
/**
* Update originator service of an array of archives
*
* @param string $archiveIds List of archive identifiers
* @param array $archiveIds Array of archive identifiers
* @param string $orgId Organization identified destined to be new originator of archive
*
*/
public function updateOriginator($archiveIds, $orgId)
{
$archive = $this->sdoFactory->read('recordsManagement/archive', $archiveIds);
$currentOwnerOrgId = $archive->originatorOwnerOrgId;
$newOriginatorOrg = $this->sdoFactory->read('organization/organization', $orgId);
if (!is_array($archiveIds)) {
$archiveIds = [$archiveIds];
}
$result = [];
$result["success"] = [];
$result["error"] = [];
$newOriginatorOrg = $this->sdoFactory->read('organization/organization', $orgId);
if ($newOriginatorOrg->enabled == false) {
throw new \bundle\recordsManagement\Exception\organizationException(
"This organization is disabled."
);
}
if ($currentOwnerOrgId == $newOriginatorOrg->ownerOrgId) {
foreach ($archiveIds as $archiveId) {
$archive = $this->sdoFactory->read('recordsManagement/archive', $archiveId);
$currentOwnerOrgId = $archive->originatorOwnerOrgId;
if ($currentOwnerOrgId != $newOriginatorOrg->ownerOrgId) {
$result["error"][] = $archiveId;
continue;
// throw new \bundle\recordsManagement\Exception\organizationException(
// "The new originator organization of the archive must have the same owner organization as the current one."
// );
}
$archive->originatorOrgRegNumber = $newOriginatorOrg->registrationNumber;
$archive->lastModificationDate = \laabs::newTimestamp();
$this->sdoFactory->update($archive,'recordsManagement/archive');
} else {
throw new \bundle\recordsManagement\Exception\organizationException(
"The new originator organization of the archive must have the same owner organization as the current one."
);
$result["success"][] = $archiveId;
}
return $result;
}
}
......@@ -1461,4 +1461,30 @@ class archive
return $file;
}
/**
* Serializer JSON for changing originator method
* @param array $result
*
* @return object JSON object with a status and message parameters
*/
public function setOriginator($result)
{
$success = count($result['success']);
$echec = count($result['error']);
$this->json->message = '%1$s archive(s) modified.';
$this->json->message = $this->translator->getText($this->json->message);
$this->json->message = sprintf($this->json->message, $success);
if ($echec > 0) {
$message = '%1$s archive(s) can not be modified.';
$message = $this->translator->getText($message);
$message = sprintf($message, $echec);
$this->json->message .= ' '.$message;
}
return $this->json->save();
}
}
......@@ -31,6 +31,7 @@ interface adminOriginatorInterface
/**
* @uses recordsManagement/archives/updateOriginator
* @return recordsManagement/archive/setOriginator
*/
public function updateRecordsmanagementArchiveOriginator($archiveIds, $orgId);
}
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