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 storage realm username GroupBy #1156

Merged
merged 1 commit into from
Nov 27, 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
5 changes: 3 additions & 2 deletions classes/DataWarehouse/Query/Storage/GroupBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function applyTo(
$pk_field = new TableField(
$this->table,
$this->pk_field_name,
$this->getIdColumnName($multi_group)
'pk'
);
$query->addField($pk_field);

Expand All @@ -185,7 +185,8 @@ public function applyTo(

$fact_table_fk_field = new TableField(
$data_table,
$this->fk_field_name
$this->fk_field_name,
'fk'
);
$query->addWhereCondition(
new WhereCondition(
Expand Down
27 changes: 22 additions & 5 deletions classes/DataWarehouse/Query/Storage/GroupBys/GroupByUsername.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct()
SELECT DISTINCT
gt.username AS id,
gt.username AS short_name,
gt.username as long_name
gt.username AS long_name
FROM systemaccount gt
WHERE 1
ORDER BY gt.username
Expand All @@ -43,6 +43,23 @@ public function __construct()
$this->info = 'The specific system username of the users who stores data.';
}

public function pullQueryParameters(&$request)
{
return parent::pullQueryParameters2(
$request,
'SELECT id FROM modw.systemaccount WHERE username IN (_filter_)',
'systemaccount_id'
);
}

public function pullQueryParameterDescriptions(&$request)
{
return parent::pullQueryParameterDescriptions2(
$request,
'SELECT DISTINCT username AS field_label FROM modw.systemaccount WHERE username IN (_filter_) ORDER BY username'
);
}

public function getPossibleValues(
$hint = null,
$limit = null,
Expand All @@ -57,16 +74,16 @@ public function getPossibleValues(

foreach ($parameters as $pname => $pvalue) {
if ($pname == 'person') {
$possible_values_query = str_ireplace('WHERE ', 'WHERE gt.person_id = $pvalue AND ', $possible_values_query);
$possible_values_query = str_ireplace('WHERE ', 'WHERE gt.person_id = ' . $pvalue . ' AND ', $possible_values_query);
} elseif ($pname == 'provider') {
$possible_values_query = str_ireplace('FROM ', 'FROM modw.resourcefact rf, ', $possible_values_query);
$possible_values_query = str_ireplace('WHERE ', 'WHERE rf.organization_id = $pvalue AND gt.resource_id = rf.id AND ', $possible_values_query);
$possible_values_query = str_ireplace('WHERE ', 'WHERE rf.organization_id = ' . $pvalue . ' AND gt.resource_id = rf.id AND ', $possible_values_query);
} elseif ($pname == 'institution') {
$possible_values_query = str_ireplace('FROM ', 'FROM modw.person p, ', $possible_values_query);
$possible_values_query = str_ireplace('WHERE ', 'WHERE p.organization_id = $pvalue AND gt.person_id = p.id AND ', $possible_values_query);
$possible_values_query = str_ireplace('WHERE ', 'WHERE p.organization_id = ' . $pvalue . ' AND gt.person_id = p.id AND ', $possible_values_query);
} elseif ($pname == 'pi') {
$possible_values_query = str_ireplace('FROM ', 'FROM modw.peopleunderpi pup, ', $possible_values_query);
$possible_values_query = str_ireplace('WHERE ', 'WHERE pup.principalinvestigator_person_id = $pvalue AND gt.person_id = pup.person_id AND ', $possible_values_query);
$possible_values_query = str_ireplace('WHERE ', 'WHERE pup.principalinvestigator_person_id = ' . $pvalue . ' AND gt.person_id = pup.person_id AND ', $possible_values_query);
}
}

Expand Down
35 changes: 35 additions & 0 deletions classes/OpenXdmod/Migration/Version851To900/DatabaseMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace OpenXdmod\Migration\Version851To900;

use Exception;
use OpenXdmod\Setup\Console;
use FilterListBuilder;
use CCR\DB;

/**
* Migrate databases from version 8.5.1 to 9.0.0.
*/
class DatabasesMigration extends \OpenXdmod\Migration\DatabasesMigration
{
public function execute()
{
parent::execute();

// NOTE: It's possible that this should be removed after the GroupBy
// refactoring is merged.
$dbh = DB::factory('datawarehouse');
$dbh->execute('DROP TABLE IF EXISTS modw_filters.Storage_person___username');
$dbh->execute('DROP TABLE IF EXISTS modw_filters.Storage_pi___username');
$dbh->execute('DROP TABLE IF EXISTS modw_filters.Storage_username');
$this->logger->notice('Rebuilding filter lists');
try {
$builder = new FilterListBuilder();
$builder->setLogger($this->logger);
$builder->buildRealmLists('Storage');
$this->logger->notice('Done building filter lists');
} catch (Exception $e) {
$this->logger->warning('Failed to build filter list: ' . $e->getMessage());
$this->logger->warning('You may need to run xdmod-build-filter-lists manually');
}
}
}