Skip to content

Commit

Permalink
Fix DefautlAffiliationTypes foreign key
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Feb 24, 2025
1 parent 66a2b91 commit e6ea40b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
44 changes: 35 additions & 9 deletions app/plugins/EnvSource/src/Model/Table/EnvSourceCollectorsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,7 @@ public function parse(\EnvSource\Model\Entity\EnvSource $envSource): array {
// The look aside file is for debugging purposes. If the file is specified but not found,
// we throw an error to prevent unintended configurations.

$src = parse_ini_file($envSource->lookaside_file);

if(!$src) {
throw new \InvalidArgumentException(__d('env_source', 'error.lookaside_file', [$envSource->lookaside_file]));
}
// Put the values in the environment
foreach($src as $k => $v) {
putenv("$k=$v");
}
return $this->loadFromLookasideFile($envSource->lookaside_file, $envSource);
}

// We walk through our configuration and only copy the variables that were configured
Expand All @@ -281,6 +273,40 @@ public function parse(\EnvSource\Model\Entity\EnvSource $envSource): array {
return $ret;
}

/**
* Load environment variables from a lookaside file based on the given configuration.
*
* @param string $filename Path to the lookaside file
* @param \EnvSource\Model\Entity\EnvSource $envSource EnvSource configuration entity
* @return array Array of environment variables and their parsed values
* @throws InvalidArgumentException
*@since COmanage Registry v5.1.0
*/
public function loadFromLookasideFile(string $filename, \EnvSource\Model\Entity\EnvSource $envSource): array {
$src = parse_ini_file($filename);
$ret = [];

if(!$src) {
throw new \InvalidArgumentException(__d('env_source', 'error.lookaside_file', [$filename]));
}

// We walk through our configuration and only copy the variables that were configured
foreach($envSource->getVisible() as $field) {
// We only want the fields starting env_ (except env_source_id, which is changelog metadata)

if(strncmp($field, "env_", 4)==0 && $field != "env_source_id"
&& !empty($envSource->$field) // This field is configured with an env var name
&& isset($src[$envSource->$field]) // This env var is populated
) {
// Note we're using the EnvSource field name (eg: env_name_given) as the key
// and not the configured variable name (which might be something like SHIB_FIRST_NAME)
$ret[$field] = $src[$envSource->$field];
}
}

return $ret;
}

/**
* Insert or update a Petition Env Identity.
*
Expand Down
4 changes: 2 additions & 2 deletions app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected function resultToEntityData(
\EnvSource\Model\Entity\EnvSource $EnvSource,
array $result
): array {
// We don't need most of the $EnvSource configuation since EnvSourceCollector::parse
// We don't need most of the $EnvSource configuration since EnvSourceCollector::parse
// already mapped the variable names for us. We do need to know the sp_mode for parsing
// multiple values, and also we need the types.

Expand All @@ -218,7 +218,7 @@ protected function resultToEntityData(
$role = [
// We only support one role per record
'role_key' => '1',
'affiliation' => $this->DefaultAffiliationTypes->getTypeLabel($EnvSource->name_type_id)
'affiliation' => $this->DefaultAffiliationTypes->getTypeLabel($EnvSource->default_affiliation_type_id)
];

foreach([
Expand Down

0 comments on commit e6ea40b

Please sign in to comment.