diff --git a/classes/OpenXdmod/DataWarehouseInitializer.php b/classes/OpenXdmod/DataWarehouseInitializer.php index 0a6f136862..a3015932c7 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; @@ -77,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. @@ -444,6 +452,40 @@ 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() + { + if ($this->enabledRealms !== null) { + return $this->enabledRealms; + } + + $resources = XdmodConfiguration::assocArrayFactory('resources.json', CONFIG_DIR); + $resourceTypes = 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']); + } + } + $this->enabledRealms = array_unique($realms); + + return $this->enabledRealms; } }