From 9e60917e0dd25ef8fba7f399b5ea2ae382e09487 Mon Sep 17 00:00:00 2001 From: Ryan Rathsam Date: Thu, 10 Oct 2019 12:51:07 -0400 Subject: [PATCH 1/3] Update DWI's `isRealmEnabled` to be config file based - Added a `getEnabledRealms` function that operates solely off of config files and not the db. This resolves some complexity / problems that arose with the ETL processes during install / upgrade. --- .../OpenXdmod/DataWarehouseInitializer.php | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/classes/OpenXdmod/DataWarehouseInitializer.php b/classes/OpenXdmod/DataWarehouseInitializer.php index 0a6f136862..6437e9fb1d 100644 --- a/classes/OpenXdmod/DataWarehouseInitializer.php +++ b/classes/OpenXdmod/DataWarehouseInitializer.php @@ -3,6 +3,7 @@ namespace OpenXdmod; use CCR\DB; +use Configuration\XdmodConfiguration; use Exception; use CCR\DB\iDatabase; use ETL\Configuration\EtlConfiguration; @@ -444,6 +445,34 @@ public function aggregate( */ public function isRealmEnabled($realm) { - return in_array($realm, Realms::getEnabledRealms()); + return in_array($realm, $this->getEnabledRealms()); + } + + /** + * Retrieve an array of the realms that are `enabled` for this XDMoD installation. `enabled` is defined as there + * being a resource present of a type that supports ( i.e. has a record in its `realms` property ) said realm. + * . + * @return array + */ + public function getEnabledRealms() + { + $resources = \Configuration\XdmodConfiguration::assocArrayFactory('resources.json', CONFIG_DIR); + $resourceTypes = \Configuration\XdmodConfiguration::assocArrayFactory('resource_types.json', CONFIG_DIR)['resource_types']; + + $currentResourceTypes = array(); + foreach($resources as $resource) { + if (isset($resource['resource_type'])) { + $currentResourceTypes[] = $resource['resource_type']; + } + } + $currentResourceTypes = array_unique($currentResourceTypes); + + $realms = array(); + foreach($currentResourceTypes as $currentResourceType) { + if (isset($resourceTypes[$currentResourceType])) { + $realms = array_merge($realms, $resourceTypes[$currentResourceType]['realms']); + } + } + return array_unique($realms); } } From 9b5fc0c58aa550434d6958557a1bfd90c60a6303 Mon Sep 17 00:00:00 2001 From: Ryan Rathsam Date: Thu, 10 Oct 2019 13:04:16 -0400 Subject: [PATCH 2/3] Added cacheing to the function --- classes/OpenXdmod/DataWarehouseInitializer.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/classes/OpenXdmod/DataWarehouseInitializer.php b/classes/OpenXdmod/DataWarehouseInitializer.php index 6437e9fb1d..ce5afaba7f 100644 --- a/classes/OpenXdmod/DataWarehouseInitializer.php +++ b/classes/OpenXdmod/DataWarehouseInitializer.php @@ -78,6 +78,13 @@ class DataWarehouseInitializer */ protected $append; + /** + * A String[] of the realms currently considered `enabled`. + * + * @var array + */ + protected $enabledRealms = null; + /** * @param iDatabase $hpcdbDb The HPcDB database. * @param iDatabase $warehouseDb The MoD warehouse database. @@ -456,6 +463,10 @@ public function isRealmEnabled($realm) */ public function getEnabledRealms() { + if ($this->enabledRealms !== null) { + return $this->enabledRealms; + } + $resources = \Configuration\XdmodConfiguration::assocArrayFactory('resources.json', CONFIG_DIR); $resourceTypes = \Configuration\XdmodConfiguration::assocArrayFactory('resource_types.json', CONFIG_DIR)['resource_types']; @@ -473,6 +484,8 @@ public function getEnabledRealms() $realms = array_merge($realms, $resourceTypes[$currentResourceType]['realms']); } } - return array_unique($realms); + $this->enabledRealms = array_unique($realms); + + return $this->enabledRealms; } } From 7b4c09afdc446c781bba3f2fbf5951c764c979cb Mon Sep 17 00:00:00 2001 From: Ryan Rathsam Date: Thu, 10 Oct 2019 13:11:22 -0400 Subject: [PATCH 3/3] Removing unneeded namespace for XDMoDConfiguration --- classes/OpenXdmod/DataWarehouseInitializer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/OpenXdmod/DataWarehouseInitializer.php b/classes/OpenXdmod/DataWarehouseInitializer.php index ce5afaba7f..a3015932c7 100644 --- a/classes/OpenXdmod/DataWarehouseInitializer.php +++ b/classes/OpenXdmod/DataWarehouseInitializer.php @@ -467,8 +467,8 @@ public function getEnabledRealms() return $this->enabledRealms; } - $resources = \Configuration\XdmodConfiguration::assocArrayFactory('resources.json', CONFIG_DIR); - $resourceTypes = \Configuration\XdmodConfiguration::assocArrayFactory('resource_types.json', CONFIG_DIR)['resource_types']; + $resources = XdmodConfiguration::assocArrayFactory('resources.json', CONFIG_DIR); + $resourceTypes = XdmodConfiguration::assocArrayFactory('resource_types.json', CONFIG_DIR)['resource_types']; $currentResourceTypes = array(); foreach($resources as $resource) {