Skip to content

Commit

Permalink
Update DWI's isRealmEnabled to be config file based (#1102)
Browse files Browse the repository at this point in the history
* 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.

* Added cacheing to the  function

* Removing unneeded namespace for XDMoDConfiguration
  • Loading branch information
ryanrath authored Oct 15, 2019
1 parent c8632a5 commit 2198dec
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion classes/OpenXdmod/DataWarehouseInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OpenXdmod;

use CCR\DB;
use Configuration\XdmodConfiguration;
use Exception;
use CCR\DB\iDatabase;
use ETL\Configuration\EtlConfiguration;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 2198dec

Please sign in to comment.