diff --git a/app/src/Controller/Component/AuthorizationComponent.php b/app/src/Controller/Component/AuthorizationComponent.php index 689dfb46f..e6cf71684 100644 --- a/app/src/Controller/Component/AuthorizationComponent.php +++ b/app/src/Controller/Component/AuthorizationComponent.php @@ -43,7 +43,7 @@ class AuthorizationComponent extends Component { * @since COmanage Match v1.0.0 */ - public function initialize($config) { + public function initialize(array $config) { parent::initialize($config); $this->Permissions = TableRegistry::get('Permissions'); diff --git a/app/src/Lib/Match/MatchService.php b/app/src/Lib/Match/MatchService.php index b3c53ff5d..286b4f735 100644 --- a/app/src/Lib/Match/MatchService.php +++ b/app/src/Lib/Match/MatchService.php @@ -712,7 +712,7 @@ protected function upsert(string $sor, string $sorid, AttributeManager $attribut $rowid = null; - $dbh->startTrans(); + $this->dbc->startTrans(); try { // SELECT FOR UPDATE only locks rows of matching records. ie: On an insert @@ -726,16 +726,16 @@ protected function upsert(string $sor, string $sorid, AttributeManager $attribut $stmt = $this->dbc->Prepare($sql); - $rowid = (int)$this->dbc->GetOne($stmt, [$sor, $sorid]); + $rowid = $this->dbc->GetOne($stmt, [$sor, $sorid]); if($rowid !== null) { // $rowid should be the same before and after - $rowid = $this->update($rowid, $attributes, $referenceId); + $rowid = $this->update((int)$rowid, $attributes, $referenceId); } else { $rowid = $this->insert($sor, $sorid, $attributes, $referenceId); } - $dbh->commit(); + $this->dbc->completeTrans(); } catch(\Exception $e) { $dbh->failTrans(); diff --git a/app/src/Lib/Match/ResultManager.php b/app/src/Lib/Match/ResultManager.php index 66493d527..92b05c0f4 100644 --- a/app/src/Lib/Match/ResultManager.php +++ b/app/src/Lib/Match/ResultManager.php @@ -52,13 +52,10 @@ class ResultManager { * @since COmanage Match v1.0.0 * @param string $referenceId Reference ID * @param array $attributes Array of matchgrid attributes + * @throws RuntimeException */ public function add(array $attributes) { -// XXX note this overwrites any previous candidate with the same referenceId, is that OK? -// what if there are two SOR entries with different attributes but the same referenceId? -// $this->results[$referenceId][$rowId] = $attributes; - if(empty($attributes)) { return; } @@ -83,7 +80,12 @@ public function add(array $attributes) { } } -// XXX throw error if !$referenceId || $rowid + // We might get a null $referenceId (pending matches), but we shouldn't get + // a null $rowId. + if(!$rowId) { + throw new \RuntimeException(__('match.er.format')); + } + $this->results[$referenceId][$rowId] = $parsed; $this->rawResults[$rowId] = $attributes; @@ -142,13 +144,11 @@ public function getReferenceIds() { */ public function getResultsForJson($mode="search") { -// XXX why does this set everything BUT the top level attribute? ("candidates" or "matchRequests") $ret = []; foreach($this->results as $referenceId => $sorRow) { -// XXX note $candidate is NOT used by mode=pending + // Note $candidate is not used by mode=pending $candidate = ['referenceId' => $referenceId]; -// XXX add confidence? foreach($sorRow as $rowId => $attrs) { $parsed = ['matchRequest' => $rowId]; @@ -172,7 +172,6 @@ public function getResultsForJson($mode="search") { $complex[ $super[0] ][ $sub[1] ][ $sub[0] ] = $v; } } elseif($a == 'sorid') { -// XXX should this be handled via Attribute Manager? or a config entry? // Special case $parsed['identifiers'][] = [ "type" => "sor", @@ -203,7 +202,6 @@ public function getResultsForJson($mode="search") { unset($candidate['sorAttributes']['request_time']); -// XXX Note resolutionTime not yet defined in strawman if(!empty($candidate['sorAttributes']['resolution_time'])) { $candidate['resolutionTime'] = strftime("%FT%TZ", strtotime($candidate['sorAttributes']['resolution_time'])); @@ -228,8 +226,11 @@ public function getResultsForJson($mode="search") { $ret[$rowId]['referenceId'] = $referenceId; } } else { -// XXX request/resolution time are not defined in the strawman for potential match -// results, should they be? + // Bump up request time, there shouldn't be a resolution_time for + // pending requests + $candidate['requestTime'] = strftime("%FT%TZ", + strtotime($parsed['request_time'])); + unset($parsed['request_time']); unset($parsed['resolution_time']); diff --git a/app/src/Template/Matchgrids/fields.inc b/app/src/Template/Matchgrids/fields.inc index d39a8e65b..e4d7afd38 100644 --- a/app/src/Template/Matchgrids/fields.inc +++ b/app/src/Template/Matchgrids/fields.inc @@ -65,7 +65,7 @@ if($action == 'add' || $action == 'edit') { print $this->Field->control('referenceid_start', ['default' => 1001]); - print $this->Field->control('referenceid_prefix', + print $this->Field->control('referenceid-prefix', [], false); }