Commit 888a9b24 authored by Charlotte Bataille's avatar Charlotte Bataille
Browse files

fix/21614 : prevent delete used archival profile

parent a0e05e96
Pipeline #19744 failed with stages
in 21 seconds
......@@ -359,14 +359,27 @@ class archivalProfile
*/
public function isUsed($archivalProfile)
{
$archivalProfileReference = $archivalProfile->reference;
$archivalAgreementController = \laabs::newController('medona/archivalAgreement');
$archivalAgreement = $archivalAgreementController->getByProfileReference($archivalProfile->reference);
if (!empty($archivalAgreement)) {
return false;
return true;
}
$archivalProfileAccessController = \laabs::newController('organization/organization');
$archivalProfileAccess = $archivalProfileAccessController->getArchivalProfileAccess(null,$archivalProfileReference);
if (!empty($archivalProfileAccess)) {
return true;
}
return (bool) $this->sdoFactory->count('recordsManagement/archive', "archivalProfileReference = '$archivalProfile->reference'");
if((bool) $this->sdoFactory->count('recordsManagement/archivalProfileContents', "containedProfileId = '$archivalProfile->archivalProfileId'")) {
return true;
}
if((bool) $this->sdoFactory->count('recordsManagement/archive', "archivalProfileReference = '$archivalProfileReference'")) {
return true;
}
return false;
}
/**
......@@ -619,20 +632,4 @@ class archivalProfile
return $archivalProfile->archivalProfileId;
}
/**
* Get identifiers of used archival profiles
*
* @return recordsManagement/archivalProfile[] Array of archival profiles
*/
public function getUsedArchivalProfilesReference() {
$usedArchivalProfilesReference = [];
$archivalProfileUses = $this->sdoFactory->summarise("organization/archivalProfileAccess","archivalProfileReference");
foreach($archivalProfileUses as $archivalProfileReference => $uses) {
if (($uses > 0) && ($archivalProfileReference!='*')) {
$usedArchivalProfilesReference[] = $archivalProfileReference;
}
}
return $usedArchivalProfilesReference;
}
}
......@@ -129,11 +129,4 @@ interface archivalProfileInterface
*/
public function readArchivalprofileExport_profileReference_();
/**
* Get used archival profiles
*
* @action recordsManagement/archivalProfile/getUsedArchivalProfilesReference
*/
public function readUsedArchivalProfiles();
}
......@@ -61,7 +61,6 @@ class archivalProfile
public function index()
{
$archivalProfiles = \laabs::callService('recordsManagement/archivalProfile/readIndex');
$usedArchivalProfilesReference = \laabs::callService('recordsManagement/archivalProfile/readUsedArchivalProfiles');
$this->view->addContentFile('recordsManagement/archivalProfile/index.html');
......@@ -70,12 +69,6 @@ class archivalProfile
$dataTable->setUnsortableColumns(3);
$this->view->translate();
foreach($archivalProfiles as $key => $archivalProfile) {
if (in_array($archivalProfile->reference, $usedArchivalProfilesReference)) {
$archivalProfile->used = true;
}
}
$this->view->setSource("profile", $archivalProfiles);
$this->view->merge();
......
......@@ -47,7 +47,7 @@ file that was distributed with this source code.
<button type="button" data-edit-archivalProfile="[?merge .archivalProfileId ?]" class="btn btn-info" title="Edit">
<span class="fa fa-fw fa-edit"></span>
</button>
<button type="button" data-profileid="[?merge .archivalProfileId ?]" class="deleteProfile btn btn-danger [?merge .used.bool().then('disabled') ?]" title="Delete">
<button type="button" data-profileid="[?merge .archivalProfileId ?]" class="deleteProfile btn btn-danger" title="Delete">
<span class="fa fa-fw fa-trash"></span>
</button>
<button type="button" data-reference="[?merge .reference ?]" class="generateBarCode btn btn-warning" title="Generate bar code" data-label="[?merge .name ?]">
......
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