Skip to content

Commit

Permalink
Bugfix/collection meta data status fix (#1334)
Browse files Browse the repository at this point in the history
* adds check for duplicate collectionCode / institutionalCode key when updating collection meta data and gives status msg upon failure closes #1311

* changes wording of duplicate error

* link error to new tab

* fixes lang tag error for collmetadata.php title
  • Loading branch information
MuchQuak authored May 17, 2024
1 parent b19d741 commit 288e43f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
37 changes: 36 additions & 1 deletion classes/OmCollections.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

include_once($SERVER_ROOT.'/classes/Manager.php');
include_once($SERVER_ROOT.'/classes/UuidFactory.php');

Expand All @@ -14,10 +15,44 @@ public function __destruct(){
parent::__destruct();
}

// Needed to
private function isCollUnique(String $collectionCode, String $institutionCode): bool {
global $CLIENT_ROOT;
try {
$sql = <<<'SQL'
SELECT collectionName, collid FROM omcollections
WHERE collid != ? AND collectionCode = ? AND institutionCode = ?
SQL;
$result = $this->conn->execute_query($sql, [$this->collid, $collectionCode, $institutionCode]);
if($col = $result->fetch_object()) {
$this->errorMessage = 'Error: Duplicate collection + institution code found in '
. '<a target="_blank" href="'
. $CLIENT_ROOT
. '/collections/misc/collprofiles.php?collid='
. $col->collid
. '">'
. $col->collectionName
.'</a>';

return false;
} else {
return true;
}
} catch (\Throwable $th) {
error_log('error: Omcollections->isCollUnique: ' . $th->getMessage());
$this->errorMessage = $th->getMessage();
return false;
}
}

public function collectionUpdate($postArr){
$status = false;
if($this->collid){
$reqArr = $this->getRequestArr($postArr);
if(!$this->isCollUnique($reqArr['collectionCode'], $reqArr['institutionCode'])) {
return false;
}
return false;
//Update core fields
$sql = 'UPDATE omcollections '.
'SET institutionCode = ?, collectionCode = ?, collectionName = ?, collectionID = ?, fullDescription = ?, latitudeDecimal = ?, longitudeDecimal = ?, publishToGbif = ?, '.
Expand Down Expand Up @@ -311,4 +346,4 @@ public function setCollid($collid){
if(is_numeric($collid)) $this->collid = $collid;
}
}
?>
?>
8 changes: 6 additions & 2 deletions collections/misc/collmetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
if ($isEditor) {
if ($action == 'saveEdits') {
$statusStr = $collManager->collectionUpdate($_POST);
if ($statusStr === true) header('Location: collprofiles.php?collid=' . $collid);
if ($statusStr === true) {
header('Location: collprofiles.php?collid=' . $collid);
} else {
$statusStr = $collManager->getErrorMessage();
}
}
elseif ($action == 'newCollection') {
if ($IS_ADMIN) {
Expand Down Expand Up @@ -67,7 +71,7 @@
<html lang="<?php echo $LANG_TAG ?>">

<head>
<title><?php echo $DEFAULT_TITLE . ' ' . ($collid ? $collData['collectionname'] : '') . ' ' . $LANG['COLL_PROFS']; ?></title>
<title><?php echo $DEFAULT_TITLE . ' ' . ($collid ? $collData['collectionname'] : '') . ' ' . $LANG['COL_PROFS']; ?></title>
<link href="<?php echo $CSS_BASE_PATH; ?>/jquery-ui.css" type="text/css" rel="stylesheet">
<?php
include_once($SERVER_ROOT . '/includes/head.php');
Expand Down

0 comments on commit 288e43f

Please sign in to comment.