From 666b1a374326bbf700b9f189baadffa927755533 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Mon, 5 Feb 2024 19:17:19 +0200 Subject: [PATCH] Contain PrimaryName properly --- .../UnixCluster/Model/UnixCluster.php | 2 +- app/Controller/AdHocAttributesController.php | 12 ++-- app/Controller/AddressesController.php | 16 +++-- app/Controller/AuthenticatorsController.php | 4 +- app/Controller/CoNotificationsController.php | 20 ++++-- .../CoOrgIdentityLinksController.php | 4 +- app/Controller/CoPeopleController.php | 38 +++++++--- app/Controller/CoPersonRolesController.php | 14 ++-- .../CoPetitionHistoryRecordsController.php | 4 +- app/Controller/CoPetitionsController.php | 32 ++++++--- .../CoTermsAndConditionsController.php | 2 +- app/Controller/EmailAddressesController.php | 16 +++-- app/Controller/HistoryRecordsController.php | 16 ++--- app/Controller/MVPAController.php | 6 +- app/Controller/OrgIdentitiesController.php | 28 ++++++-- app/Controller/SAMController.php | 4 +- app/Controller/StandardPluginController.php | 2 +- app/Controller/UrlsController.php | 8 +-- app/Controller/UsersController.php | 16 +++-- app/Controller/VettingRequestsController.php | 2 +- app/Controller/VettingResultsController.php | 4 +- app/Model/Behavior/ChangelogBehavior.php | 69 +++++++++++-------- app/Model/CoPipeline.php | 2 +- 23 files changed, 210 insertions(+), 111 deletions(-) diff --git a/app/AvailablePlugin/UnixCluster/Model/UnixCluster.php b/app/AvailablePlugin/UnixCluster/Model/UnixCluster.php index 85fb5a5b1..05dd54e2e 100644 --- a/app/AvailablePlugin/UnixCluster/Model/UnixCluster.php +++ b/app/AvailablePlugin/UnixCluster/Model/UnixCluster.php @@ -245,7 +245,7 @@ public function assign($cluster, $coPersonId) { $args['conditions']['CoPerson.co_id'] = $cluster['Cluster']['co_id']; $args['contain'] = array( 'Identifier' => array('conditions' => array('Identifier.status' => SuspendableStatusEnum::Active)), - 'PrimaryName' + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)) ); $coPerson = $this->Cluster->Co->CoPerson->find('first', $args); diff --git a/app/Controller/AdHocAttributesController.php b/app/Controller/AdHocAttributesController.php index 00235bd3a..0b2aec658 100644 --- a/app/Controller/AdHocAttributesController.php +++ b/app/Controller/AdHocAttributesController.php @@ -41,17 +41,21 @@ class AdHocAttributesController extends MVPAController { public $edit_contains = array( 'CoDepartment', - 'CoPersonRole' => array('CoPerson' => 'PrimaryName'), + 'CoPersonRole' => array('CoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)) + )), 'Organization', - 'OrgIdentity' => array('PrimaryName') + 'OrgIdentity' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))) ); public $view_contains = array( 'CoDepartment', - 'CoPersonRole' => array('CoPerson' => 'PrimaryName'), + 'CoPersonRole' => array('CoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)) + )), 'Organization', 'OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource'), - 'PrimaryName'), + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'SourceAdHocAttribute' ); diff --git a/app/Controller/AddressesController.php b/app/Controller/AddressesController.php index 4bcb6acfd..ae7c34eea 100644 --- a/app/Controller/AddressesController.php +++ b/app/Controller/AddressesController.php @@ -42,17 +42,25 @@ class AddressesController extends MVPAController { public $edit_contains = array( 'CoDepartment', - 'CoPersonRole' => array('CoPerson' => 'PrimaryName'), + 'CoPersonRole' => array( + 'CoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + )), 'Organization', - 'OrgIdentity' => array('PrimaryName') + 'OrgIdentity' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ) ); public $view_contains = array( 'CoDepartment', - 'CoPersonRole' => array('CoPerson' => 'PrimaryName'), + 'CoPersonRole' => array('CoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + )), 'Organization', 'OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource'), - 'PrimaryName'), + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), 'SourceAddress' ); diff --git a/app/Controller/AuthenticatorsController.php b/app/Controller/AuthenticatorsController.php index d3185469e..e79c5a37d 100644 --- a/app/Controller/AuthenticatorsController.php +++ b/app/Controller/AuthenticatorsController.php @@ -353,7 +353,9 @@ public function status() { $args = array(); $args['conditions']['CoPerson.id'] = $this->request->params['named']['copersonid']; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ); $this->set('vv_co_person', $this->Authenticator->Co->CoPerson->find('first', $args)); } diff --git a/app/Controller/CoNotificationsController.php b/app/Controller/CoNotificationsController.php index 2c9bd27a5..36b7be910 100644 --- a/app/Controller/CoNotificationsController.php +++ b/app/Controller/CoNotificationsController.php @@ -45,11 +45,19 @@ class CoNotificationsController extends StandardController { // For rendering views, we need more information than just the various ID numbers // stored in a petition. public $view_contains = array( - 'SubjectCoPerson' => 'PrimaryName', - 'ActorCoPerson' => 'PrimaryName', - 'RecipientCoPerson' => 'PrimaryName', + 'SubjectCoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), + 'ActorCoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), + 'RecipientCoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), 'RecipientCoGroup', - 'ResolverCoPerson' => 'PrimaryName' + 'ResolverCoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ) ); /** @@ -199,7 +207,9 @@ public function index() { $args = array(); $args['conditions']['SubjectCoPerson.id'] = $this->cur_co_person_id; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ); $cop = $this->CoNotification->SubjectCoPerson->find('first', $args); diff --git a/app/Controller/CoOrgIdentityLinksController.php b/app/Controller/CoOrgIdentityLinksController.php index 91a3c0712..f3011fe7a 100644 --- a/app/Controller/CoOrgIdentityLinksController.php +++ b/app/Controller/CoOrgIdentityLinksController.php @@ -77,7 +77,9 @@ function checkWriteDependencies($reqdata, $curdata = null) { } // Can't contain OrgIdentity completely since Name is used for display - $this->CoOrgIdentityLink->OrgIdentity->contain('PrimaryName'); + $this->CoOrgIdentityLink->OrgIdentity->contain( + array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))) + ); $orgIdentity = $this->CoOrgIdentityLink->OrgIdentity->findById($reqdata['CoOrgIdentityLink']['org_identity_id']); if(empty($orgIdentity)) diff --git a/app/Controller/CoPeopleController.php b/app/Controller/CoPeopleController.php index 616cfe4cd..00272694c 100644 --- a/app/Controller/CoPeopleController.php +++ b/app/Controller/CoPeopleController.php @@ -50,14 +50,19 @@ class CoPeopleController extends StandardController { public $delete_contains = array( 'CoPersonRole', 'Name', - 'PrimaryName' + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), ); // Use edit_contains to select the associated models we need for canvas. public $edit_contains = array( 'CoGroupMember' => array('CoGroup'), 'CoNsfDemographic', - 'CoOrgIdentityLink' => array('OrgIdentity' => array('Identifier', 'PrimaryName')), + 'CoOrgIdentityLink' => array( + 'OrgIdentity' => array( + 'Identifier', + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ) + ), 'CoPersonRole' => array('CoPetition', 'Cou', 'order' => 'CoPersonRole.ordr ASC'), // This deep nesting will allow us to display the source of the attribute 'EmailAddress' => array('SourceEmailAddress' => array('OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource')))), @@ -75,7 +80,7 @@ class CoPeopleController extends StandardController { 'EmailAddress', 'Identifier', 'Name', - 'PrimaryName', + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), 'Url' ); @@ -695,7 +700,9 @@ public function generateDisplayKey($c = null) { // Pull the PrimaryName (we're probably here from an edit directly on canvas) $args = array(); $args['conditions']['CoPerson.id'] = $this->request->data['CoPerson']['id']; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ); $p = $this->CoPerson->find('first', $args); @@ -822,7 +829,9 @@ public function index() { public function invite() { $args = array(); $args['conditions']['OrgIdentity.id'] = $this->request->params['named']['orgidentityid']; - $args['contain'] = array('PrimaryName'); + $args['contain'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)) + ); $orgp = $this->CoPerson->CoOrgIdentityLink->OrgIdentity->find('first', $args); @@ -1126,7 +1135,10 @@ public function link($copersonid=null) { if(!empty($this->request->params['named']['orgidentityid'])) { $args = array(); $args['conditions']['OrgIdentity.id'] = $this->request->params['named']['orgidentityid']; - $args['contain'] = array('CoPetition', 'PrimaryName'); + $args['contain'] = array( + 'CoPetition', + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ); $this->set('vv_org_identity', $this->CoPerson->CoOrgIdentityLink->OrgIdentity->find('first', $args)); $this->set('title_for_layout', _txt('op.link')); @@ -1141,7 +1153,9 @@ public function link($copersonid=null) { if(!empty($copersonid)) { $args = array(); $args['conditions']['CoPerson.id'] = $copersonid; - $args['contain'] = 'PrimaryName'; + $args['contain'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)) + ); $this->set('vv_co_person', $this->CoPerson->find('first', $args)); } @@ -1362,7 +1376,7 @@ public function provision($id) { $args = array(); $args['conditions']['CoPerson.id'] = $id; $args['contain'] = array( - 'PrimaryName', + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), 'CoGroupMember', 'CoOrgIdentityLink' => array('OrgIdentity' => array('OrgIdentitySourceRecord')), 'Identifier' @@ -1451,7 +1465,9 @@ function getPrimaryName($names) { if(!empty($this->request->params['named']['copersonroleid'])) { $args = array(); $args['conditions']['CoPersonRole.id'] = $this->request->params['named']['copersonroleid']; - $args['contain']['CoPerson'] = 'PrimaryName'; + $args['contain']['CoPerson'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ); $args['contain'][] = 'CoPetition'; $this->set('vv_co_person_role', $this->CoPerson->CoPersonRole->find('first', $args)); @@ -1460,7 +1476,9 @@ function getPrimaryName($names) { if(!empty($this->request->params['named']['tocopersonid'])) { $args = array(); $args['conditions']['CoPerson.id'] = $this->request->params['named']['tocopersonid']; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)) + ); $this->set('vv_to_co_person', $this->CoPerson->find('first', $args)); $this->set('title_for_layout', _txt('op.relink')); diff --git a/app/Controller/CoPersonRolesController.php b/app/Controller/CoPersonRolesController.php index 344391cad..0f1976c29 100644 --- a/app/Controller/CoPersonRolesController.php +++ b/app/Controller/CoPersonRolesController.php @@ -52,8 +52,8 @@ class CoPersonRolesController extends StandardController { 'Address' => array('SourceAddress' => array('OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource')))), 'AdHocAttribute' => array('SourceAdHocAttribute' => array('OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource')))), 'CoPerson', // Used to check status recalculation on save - 'ManagerCoPerson' => array('PrimaryName'), - 'SponsorCoPerson' => array('PrimaryName'), + 'ManagerCoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), + 'SponsorCoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'TelephoneNumber' => array('SourceTelephoneNumber' => array('OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource')))) ); @@ -62,8 +62,8 @@ class CoPersonRolesController extends StandardController { 'Address' => array('SourceAddress' => array('OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource')))), 'AdHocAttribute' => array('SourceAdHocAttribute' => array('OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource')))), 'Cou', - 'ManagerCoPerson' => array('PrimaryName'), - 'SponsorCoPerson' => array('PrimaryName'), + 'ManagerCoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), + 'SponsorCoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'TelephoneNumber' => array('SourceTelephoneNumber' => array('OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource')))) ); @@ -131,7 +131,7 @@ function beforeFilter() { $args = array(); $args['conditions']['CoPerson.id'] = $copid; $args['contain'] = array('CoOrgIdentityLink' => array('OrgIdentity'), - 'PrimaryName'); + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $cop = $this->CoPersonRole->CoPerson->find('all', $args); @@ -739,7 +739,7 @@ public function relink($id) { $args = array(); $args['conditions']['CoPersonRole.id'] = $id; - $args['contain']['CoPerson'] = 'PrimaryName'; + $args['contain']['CoPerson'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $copr = $this->CoPersonRole->find('first', $args); @@ -752,7 +752,7 @@ public function relink($id) { $args = array(); $args['conditions']['CoPerson.id'] = filter_var($this->request->data['CoPersonRole']['co_person_id'],FILTER_SANITIZE_SPECIAL_CHARS); - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $newcop = $this->CoPersonRole->CoPerson->find('first', $args); diff --git a/app/Controller/CoPetitionHistoryRecordsController.php b/app/Controller/CoPetitionHistoryRecordsController.php index c6fff325d..49e5eb5b8 100644 --- a/app/Controller/CoPetitionHistoryRecordsController.php +++ b/app/Controller/CoPetitionHistoryRecordsController.php @@ -38,7 +38,7 @@ class CoPetitionHistoryRecordsController extends StandardController { 'modified' => 'asc' ), 'contain' => array( - 'ActorCoPerson' => 'PrimaryName' + 'ActorCoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))) ) ); @@ -48,7 +48,7 @@ class CoPetitionHistoryRecordsController extends StandardController { // For rendering views, we need more information than just the various ID numbers // stored in a petition. public $view_contains = array( - 'ActorCoPerson' => 'PrimaryName' + 'ActorCoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))) ); /** diff --git a/app/Controller/CoPetitionsController.php b/app/Controller/CoPetitionsController.php index 23cc817da..2bdfead7c 100644 --- a/app/Controller/CoPetitionsController.php +++ b/app/Controller/CoPetitionsController.php @@ -91,14 +91,24 @@ class CoPetitionsController extends StandardController { // For rendering views, we need more information than just the various ID numbers // stored in a petition. public $view_contains = array( - 'ApproverCoPerson' => 'PrimaryName', - 'EnrolleeCoPerson' => 'PrimaryName', - 'EnrolleeOrgIdentity' => 'PrimaryName', - 'PetitionerCoPerson' => 'PrimaryName', - 'SponsorCoPerson' => 'PrimaryName', + 'ApproverCoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), + 'EnrolleeCoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), + 'EnrolleeOrgIdentity' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), + 'PetitionerCoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), + 'SponsorCoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), 'CoPetitionHistoryRecord' => array( 'ActorCoPerson' => array( - 'PrimaryName' + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), ) ), 'CoEnrollmentFlow' => array( @@ -107,7 +117,9 @@ class CoPetitionsController extends StandardController { 'CoInvite', 'Cou', 'OrgIdentitySourceRecord' => array( - 'OrgIdentity' => 'PrimaryName', + 'OrgIdentity' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), 'OrgIdentitySource' ) ); @@ -493,7 +505,7 @@ function beforeRender() { if(!empty($a[$t.'_co_person_id'])) { $args = array(); $args['conditions']['CoPerson.id'] = $a[$t.'_co_person_id']; - $args['contain'] = array('PrimaryName'); + $args['contain'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $pName = $this->CoPetition->Co->CoPerson->find('first', $args); @@ -598,7 +610,7 @@ function beforeRender() { if($defaultCoPersonId) { $args = array(); $args['conditions']['CoPerson.id'] = $defaultCoPersonId; - $args['contain'] = array('PrimaryName'); + $args['contain'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $this->set('vv_default_sponsor', $this->CoPetition->Co->CoPerson->find('first', $args)); } @@ -618,7 +630,7 @@ function beforeRender() { if($defaultCoPersonId) { $args = array(); $args['conditions']['CoPerson.id'] = $defaultCoPersonId; - $args['contain'] = array('PrimaryName'); + $args['contain'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $this->set('vv_default_manager', $this->CoPetition->Co->CoPerson->find('first', $args)); } diff --git a/app/Controller/CoTermsAndConditionsController.php b/app/Controller/CoTermsAndConditionsController.php index f947ec869..d14217098 100644 --- a/app/Controller/CoTermsAndConditionsController.php +++ b/app/Controller/CoTermsAndConditionsController.php @@ -255,7 +255,7 @@ public function review() { // And also this CO Person $args = array(); $args['conditions']['CoPerson.id'] = $this->params['named']['copersonid']; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $this->set('vv_co_person', $this->Co->CoPerson->find('first', $args)); } diff --git a/app/Controller/EmailAddressesController.php b/app/Controller/EmailAddressesController.php index c40caeebc..09b0227f6 100644 --- a/app/Controller/EmailAddressesController.php +++ b/app/Controller/EmailAddressesController.php @@ -41,17 +41,25 @@ class EmailAddressesController extends MVPAController { public $edit_contains = array( 'CoDepartment', - 'CoPerson' => array('PrimaryName'), + 'CoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), 'Organization', - 'OrgIdentity' => array('PrimaryName') + 'OrgIdentity' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ) ); public $view_contains = array( 'CoDepartment', - 'CoPerson' => array('PrimaryName'), + 'CoPerson' => array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ), 'Organization', 'OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource'), - 'PrimaryName'), + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true) + ) + ), 'SourceEmailAddress' ); diff --git a/app/Controller/HistoryRecordsController.php b/app/Controller/HistoryRecordsController.php index 13c2662f0..fcacc1290 100644 --- a/app/Controller/HistoryRecordsController.php +++ b/app/Controller/HistoryRecordsController.php @@ -45,25 +45,25 @@ class HistoryRecordsController extends StandardController { 'HistoryRecord.id' => 'desc' ), 'contain' => array( - 'ActorCoPerson' => array('PrimaryName'), + 'ActorCoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'ActorApiUser', 'CoEmailList', - 'CoPerson' => array('PrimaryName'), + 'CoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'CoPersonRole', - 'OrgIdentity' => array('PrimaryName'), + 'OrgIdentity' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), ) ); public $requires_person = true; public $view_contains = array( - 'ActorCoPerson' => 'PrimaryName', + 'ActorCoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'ActorApiUser', 'CoEmailList', 'CoGroup', - 'CoPerson' => 'PrimaryName', + 'CoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'CoPersonRole', - 'OrgIdentity' => 'PrimaryName' + 'OrgIdentity' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))) ); // Use the lightbox layout for view @@ -96,13 +96,13 @@ public function add() { if(!empty($this->request->params['named']['copersonid'])) { $args = array(); $args['conditions']['CoPerson.id'] = $this->request->params['named']['copersonid']; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $n = $this->HistoryRecord->CoPerson->find('first', $args); } elseif(!empty($this->request->params['named']['orgidentityid'])) { $args = array(); $args['conditions']['OrgIdentity.id'] = $this->request->params['named']['orgidentityid']; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $n = $this->HistoryRecord->OrgIdentity->find('first', $args); } diff --git a/app/Controller/MVPAController.php b/app/Controller/MVPAController.php index 487a445c2..1bd0f08c8 100644 --- a/app/Controller/MVPAController.php +++ b/app/Controller/MVPAController.php @@ -128,7 +128,7 @@ public function beforeRender() { } elseif(!empty($pid['copersonid'])) { $args = array(); $args['conditions']['CoPerson.id'] = $pid['copersonid']; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $p = $model->CoPerson->find('first', $args); @@ -136,7 +136,7 @@ public function beforeRender() { } elseif(!empty($pid['copersonroleid'])) { $args = array(); $args['conditions']['CoPersonRole.id'] = $pid['copersonroleid']; - $args['contain']['CoPerson'] = 'PrimaryName'; + $args['contain']['CoPerson'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $p = $model->CoPersonRole->find('first', $args); @@ -155,7 +155,7 @@ public function beforeRender() { } elseif(!empty($pid['orgidentityid'])) { $args = array(); $args['conditions']['OrgIdentity.id'] = $pid['orgidentityid']; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))); $p = $model->OrgIdentity->find('first', $args); diff --git a/app/Controller/OrgIdentitiesController.php b/app/Controller/OrgIdentitiesController.php index b6a5f5046..91f1750f3 100644 --- a/app/Controller/OrgIdentitiesController.php +++ b/app/Controller/OrgIdentitiesController.php @@ -46,21 +46,31 @@ class OrgIdentitiesController extends StandardController { ); public $delete_contains = array( - 'CoOrgIdentityLink' => array('CoPerson' => array('Co', 'PrimaryName')), + 'CoOrgIdentityLink' => array( + 'CoPerson' => array( + 'Co', + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ) + ), 'Name', - 'PrimaryName' + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), ); public $edit_contains = array( 'Address', 'AdHocAttribute', 'Co', - 'CoOrgIdentityLink' => array('CoPerson' => array('Co', 'PrimaryName')), + 'CoOrgIdentityLink' => array( + 'CoPerson' => array( + 'Co', + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ) + ), 'EmailAddress', 'Identifier', 'Name', 'OrgIdentitySourceRecord' => array('OrgIdentitySource'), - 'PrimaryName', + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), 'TelephoneNumber', 'Url' ); @@ -77,7 +87,7 @@ class OrgIdentitiesController extends StandardController { // This causes slowness on MariaDB. See CO-1406. // 'PipelineCoPersonRole', 'PipelineCoGroupMember' => array('CoGroup'), - 'PrimaryName', + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), 'TelephoneNumber', 'Url' ); @@ -376,7 +386,9 @@ function find() { // Find the CO Person name $args = array(); $args['conditions']['CoPerson.id'] = $this->request->params['named']['copersonid']; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ); $cop = $this->OrgIdentity->CoOrgIdentityLink->CoPerson->find('first', $args); @@ -476,7 +488,9 @@ function generateDisplayKey($c = null) { // Pull the PrimaryName $args = array(); $args['conditions']['OrgIdentity.id'] = $this->request->data['OrgIdentity']['id']; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)) + ); $p = $this->OrgIdentity->find('first', $args); diff --git a/app/Controller/SAMController.php b/app/Controller/SAMController.php index 3c118c625..42f59304b 100644 --- a/app/Controller/SAMController.php +++ b/app/Controller/SAMController.php @@ -770,7 +770,9 @@ protected function setViewVars($authenticatorId, $coPersonId) { $args = array(); $args['conditions']['CoPerson.id'] = $coPersonId; - $args['contain'][] = 'PrimaryName'; + $args['contain'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + ); $this->set('vv_co_person', $this->CoPerson->find('first', $args)); } diff --git a/app/Controller/StandardPluginController.php b/app/Controller/StandardPluginController.php index 1bd1c2cd3..3b441ec61 100644 --- a/app/Controller/StandardPluginController.php +++ b/app/Controller/StandardPluginController.php @@ -194,7 +194,7 @@ public function review() { ) ), 'VettingStep', - 'VetterCoPerson' => array('PrimaryName') + 'VetterCoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))) ); $result = $model->VettingStep->VettingResult->find('first', $args); diff --git a/app/Controller/UrlsController.php b/app/Controller/UrlsController.php index 6b8c37f7d..4a4b9d6e9 100644 --- a/app/Controller/UrlsController.php +++ b/app/Controller/UrlsController.php @@ -41,17 +41,17 @@ class UrlsController extends MVPAController { public $edit_contains = array( 'CoDepartment', - 'CoPerson' => array('PrimaryName'), + 'CoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'Organization', - 'OrgIdentity' => array('PrimaryName') + 'OrgIdentity' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))) ); public $view_contains = array( 'CoDepartment', - 'CoPerson' => array('PrimaryName'), + 'CoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'Organization', 'OrgIdentity' => array('OrgIdentitySourceRecord' => array('OrgIdentitySource'), - 'PrimaryName'), + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'SourceUrl' ); diff --git a/app/Controller/UsersController.php b/app/Controller/UsersController.php index 5f4e2b6df..d45d5f411 100644 --- a/app/Controller/UsersController.php +++ b/app/Controller/UsersController.php @@ -154,11 +154,17 @@ public function login() { ) ); // data we need in one clever find - $oargs['contain'][] = 'PrimaryName'; - $oargs['contain'][] = 'Identifier'; - $oargs['contain']['CoOrgIdentityLink']['CoPerson'][0] = 'Co'; - $oargs['contain']['CoOrgIdentityLink']['CoPerson'][1] = 'CoPersonRole'; - $oargs['contain']['CoOrgIdentityLink']['CoPerson']['CoGroupMember'] = 'CoGroup'; + $oargs['contain'] = array( + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), + 'Identifier', + 'CoOrgIdentityLink' => array( + 'CoPerson' => array( + 'Co', + 'CoPersonRole', + 'CoGroupMember' => array('CoGroup') + ) + ) + ); $orgIdentities = $this->OrgIdentity->find('all', $oargs); // Grab the org IDs and CO information diff --git a/app/Controller/VettingRequestsController.php b/app/Controller/VettingRequestsController.php index 02b99e18b..37325ed28 100644 --- a/app/Controller/VettingRequestsController.php +++ b/app/Controller/VettingRequestsController.php @@ -61,7 +61,7 @@ class VettingRequestsController extends StandardController { public $edit_contains = array(); public $view_contains = array( - 'CoPerson' => array('PrimaryName'), + 'CoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'CoJob', 'VettingResult' => array( // This is the Vetting Step for this Vetting Result, of which there can diff --git a/app/Controller/VettingResultsController.php b/app/Controller/VettingResultsController.php index d62958032..320c0cbaf 100644 --- a/app/Controller/VettingResultsController.php +++ b/app/Controller/VettingResultsController.php @@ -37,9 +37,9 @@ class VettingResultsController extends StandardController { public $edit_contains = array(); public $view_contains = array( - 'VetterCoPerson' => array('PrimaryName'), + 'VetterCoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true))), 'VettingStep', - 'VettingRequest' => array('CoPerson' => array('PrimaryName')) + 'VettingRequest' => array('CoPerson' => array('PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)))) ); /** diff --git a/app/Model/Behavior/ChangelogBehavior.php b/app/Model/Behavior/ChangelogBehavior.php index 3c7e5d5af..93b5a38d1 100644 --- a/app/Model/Behavior/ChangelogBehavior.php +++ b/app/Model/Behavior/ChangelogBehavior.php @@ -576,11 +576,14 @@ protected function modifyContain($model, $contain) { if(empty($model->$vmodel->relinkToArchive) || !in_array($model->name, $model->$vmodel->relinkToArchive)) { $cparentfk = Inflector::underscore($model->$vmodel->name) . "_id"; - - $ret[$vmodel]['conditions'] = array( - $vmodel.'.'.$cparentfk => null, - $vmodel.'.deleted IS NOT true' - ); + + if(!isset($ret[$vmodel]['conditions']) + || !is_array($ret[$vmodel]['conditions'])) { + $ret[$vmodel]['conditions'] = array(); + } + + $ret[$vmodel]['conditions'][$vmodel.'.'.$cparentfk] = null; + $ret[$vmodel]['conditions'][] = $vmodel.'.deleted IS NOT true'; if(!empty($bits[1]) && strchr($bits[1], '=')) { // Insert the originally requested condition @@ -613,8 +616,8 @@ protected function modifyContain($model, $contain) { $parentfk = Inflector::underscore($model->name) . "_id"; $ret['conditions'] = array( - $model->name.'.'.$parentfk => null, - $model->name.'.deleted IS NOT true' + ($model->alias ?? $model->name) . '.' . $parentfk => null, + ($model->alias ?? $model->name) . '.deleted IS NOT true' ); $ret['conditions'] = array_merge($ret['conditions'], $v); @@ -626,11 +629,14 @@ protected function modifyContain($model, $contain) { } else { if($model->$k->Behaviors->enabled('Changelog')) { $cparentfk = Inflector::underscore($model->$k->name) . "_id"; - - $ret[$k]['conditions'] = array( - $k.'.'.$cparentfk => null, - $k.'.deleted IS NOT true' - ); + + if(!isset($ret[$k]['conditions']) + || !is_array($ret[$k]['conditions'])) { + $ret[$k]['conditions'] = array(); + } + + $ret[$k]['conditions'][$k.'.'.$cparentfk] = null; + $ret[$k]['conditions'][] = $k.'.deleted IS NOT true'; } } @@ -649,13 +655,15 @@ protected function modifyContain($model, $contain) { } elseif(is_array($v2)) { $ret[$k][$k2] = $this->modifyContain($model->$k->$k2, $v2); - if(is_string($k2) && !is_integer($k2)) { + if(is_string($k2) && !is_int($k2)) { $cparentfk = Inflector::underscore($model->$k->$k2->name) . "_id"; - - $ret[$k][$k2]['conditions'] = array( - $k2.'.'.$cparentfk => null, - $k2.'.deleted IS NOT true' - ); + if(!isset($ret[$k][$k2]['conditions']) + || !is_array($ret[$k][$k2]['conditions'])) { + $ret[$k][$k2]['conditions'] = array(); + } + + $ret[$k][$k2]['conditions'][$k2.'.'.$cparentfk] = null; + $ret[$k][$k2]['conditions'][] = $k2.'.deleted IS NOT true'; } } elseif(isset($model->$k->$k2)) { // Fifth example @@ -664,11 +672,13 @@ protected function modifyContain($model, $contain) { } else { if($model->$k->$v2->Behaviors->enabled('Changelog')) { $cparentfk = Inflector::underscore($model->$k->$v2->name) . "_id"; - - $ret[$k][$v2]['conditions'] = array( - $v2.'.'.$cparentfk => null, - $v2.'.deleted IS NOT true' - ); + if(!isset($ret[$k][$v2]['conditions']) + || !is_array($ret[$k][$v2]['conditions'])) { + $ret[$k][$v2]['conditions'] = array(); + } + + $ret[$k][$v2]['conditions'][$v2.'.'.$cparentfk] = null; + $ret[$k][$v2]['conditions'][] = $v2.'.deleted IS NOT true'; } } } @@ -681,11 +691,14 @@ protected function modifyContain($model, $contain) { if($model->$k->$v->Behaviors->enabled('Changelog')) { $cparentfk = Inflector::underscore($model->$k->$v->name) . "_id"; - - $ret[$k][$v]['conditions'] = array( - $v.'.'.$cparentfk => null, - $v.'.deleted IS NOT true' - ); + + if(!isset($ret[$k][$v]['conditions']) + || !is_array($ret[$k][$v]['conditions'])) { + $ret[$k][$v]['conditions'] = array(); + } + + $ret[$k][$v]['conditions'][$v.'.'.$cparentfk] = null; + $ret[$k][$v]['conditions'][] = $v.'.deleted IS NOT true'; } else { $ret[$k][] = $v; } diff --git a/app/Model/CoPipeline.php b/app/Model/CoPipeline.php index 066db2333..0ef05eca4 100644 --- a/app/Model/CoPipeline.php +++ b/app/Model/CoPipeline.php @@ -321,7 +321,7 @@ public function execute($id, $orgIdentityId, $syncAction, $actorCoPersonId=null, $args['conditions']['OrgIdentity.id'] = $orgIdentityId; $args['contain'] = array( 'Name', - 'PrimaryName', + 'PrimaryName' => array('conditions' => array('PrimaryName.primary_name' => true)), 'Address', 'AdHocAttribute', 'EmailAddress',