Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix roles file comparison to use object not string #878

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ class ConfigFilesMigration extends AbstractConfigFilesMigration

private $cloudRolesFilePath;

private $templateCloudRolesFile;

public function __construct($currentVersion, $newVersion)
{
$this->cloudRolesFilePath = CONFIG_DIR."/roles.d/cloud.json";
parent::__construct($currentVersion, $newVersion);
$this->templateCloudRolesFile = DATA_DIR . '/templates/roles.d/cloud.json';
$this->cloudRolesFilePath = CONFIG_DIR . '/roles.d/cloud.json';
parent::__construct($currentVersion, $newVersion);
}

/**
Expand All @@ -29,7 +32,7 @@ public function __construct($currentVersion, $newVersion)
public function execute()
{
if (file_exists($this->cloudRolesFilePath)) {
$this->addCloudRolesGroupBy();
$this->addtoCloudRoles();
}
$this->assertPortalSettingsIsWritable();

Expand All @@ -42,13 +45,14 @@ public function execute()
/**
* Adds new group bys to roles.d/cloud.json
*/
public function addCloudRolesGroupBy()
public function addtoCloudRoles()
{
// Json::loadFile throws an exception if the file is completely empty or if there some other
// problem loading the file. If those exceptions are thrown catch them so the rest of the
// migration script can continue to run
try{
$cloudRolesFile = Json::loadFile($this->cloudRolesFilePath);
$templateCloudRoles = Json::loadFile($this->templateCloudRolesFile);
}
catch(Exception $e){
return false;
Expand All @@ -58,6 +62,9 @@ public function addCloudRolesGroupBy()
foreach($cloudRolesFile['+roles'] as $key => $unused) {
$cloudRolesFile['+roles'][$key]['+query_descripters'][] = array('realm' => 'Cloud', 'group_by' => 'person');
$cloudRolesFile['+roles'][$key]['+query_descripters'][] = array('realm' => 'Cloud', 'group_by' => 'username');
if ($key === '+default') {
$cloudRolesFile['+roles'][$key]['+summary_charts'] = $templateCloudRoles['+roles'][$key]['+summary_charts'];
}
}

// An exception can be thrown if there is a problem writing the file. Catch and log the issue
Expand Down
6 changes: 4 additions & 2 deletions classes/OpenXdmod/Setup/ResourcesSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace OpenXdmod\Setup;

use \CCR\Json;

/**
* Resources setup.
*/
Expand Down Expand Up @@ -195,8 +197,8 @@ private function rolesFileMatches($realm)
return false;
}

return file_get_contents(TEMPLATE_DIR . '/roles.d/' . $realm . '.json')
=== file_get_contents($rolesFile);
return JSON::loadFile(TEMPLATE_DIR . '/roles.d/' . $realm . '.json', false)
=== JSON::loadFile($rolesFile, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two different object instances will never be === (https://www.php.net/manual/en/language.oop5.object-comparison.php).

}

/**
Expand Down
82 changes: 0 additions & 82 deletions configuration/roles.d/cloud.json

This file was deleted.

28 changes: 14 additions & 14 deletions templates/roles.d/cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
"data_series": {
"data": [{
"combine_type": "stack",
"display_type": "column",
"display_type": "area",
"filters": {
"data": [],
"total": 0
},
"group_by": "project",
"has_std_err": true,
"group_by": "resource",
"has_std_err": false,
"ignore_global": false,
"log_scale": false,
"long_legend": true,
Expand All @@ -69,20 +69,20 @@
"limit": 10,
"show_filters": true,
"start": 0,
"timeseries": false,
"title": "Cloud - Total CPU Hours by Project"
"timeseries": true,
"title": "Cloud - Total CPU Hours by Resource"
},
{
"data_series": {
"data": [{
"combine_type": "stack",
"display_type": "column",
"display_type": "area",
"filters": {
"data": [],
"total": 0
},
"group_by": "project",
"has_std_err": true,
"has_std_err": false,
"ignore_global": false,
"log_scale": false,
"long_legend": true,
Expand All @@ -103,7 +103,7 @@
"limit": 10,
"show_filters": true,
"start": 0,
"timeseries": false,
"timeseries": true,
"title": "Cloud - Number of Sessions Started by Project"
}
]
Expand Down Expand Up @@ -134,16 +134,16 @@
"group_by": "vm_size_memory"
},
{
"realm": "Cloud",
"group_by": "submission_venue"
"realm": "Cloud",
"group_by": "submission_venue"
},
{
"realm": "Cloud",
"group_by": "person"
"realm": "Cloud",
"group_by": "person"
},
{
"realm": "Cloud",
"group_by": "username"
"realm": "Cloud",
"group_by": "username"
}
]
}
Expand Down