Skip to content

Commit

Permalink
Merge pull request #18 from digitalutsc/redirect_count
Browse files Browse the repository at this point in the history
Added Redirect count
  • Loading branch information
kylehuynh205 authored Feb 4, 2022
2 parents 148a391 + 12e54bc commit f149956
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
14 changes: 8 additions & 6 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ className: 'select-checkbox',
{data: 'select'},
{data: 'id'},
{data: 'PID'},
{data: 'redirect'},
//{data: 'LOCAL_ID'},
{data: 'ark_url'},
{data: 'metadata'},
Expand Down Expand Up @@ -313,21 +314,21 @@ className: 'select-checkbox',
orderable: false,
targets: 4
},
/*{
{
"targets": 3,
"data": "LOCAL_ID",
"data": "redirect",
"render": function (data, type, row) {
if (data) {
return data;
} else {
return " ";
return "0";
}

}
},*/
},

{
"targets": 4,
"targets": 5,
"data": "metadata",
"render": function (data, type, row) {
if (data !== undefined && data.indexOf("|") != -1) {
Expand All @@ -348,7 +349,7 @@ className: 'select-checkbox',
}
},
{
"targets": 3,
"targets": 4,
"data": "ark_url",
"render": function (data, type, row) {
data.sort();
Expand Down Expand Up @@ -1337,6 +1338,7 @@ function processPostSuccess(index, csvResult, data) {
<th></th>
<th>Ark ID</th>
<th>PID</th>
<th>Number <br />of Redirects</th>
<!-- <th>LOCAL_ID</th>-->
<th>Ark URL</th>
<th>Metadata</th>
Expand Down
2 changes: 2 additions & 0 deletions admin/rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ function selectBound()
$r['PID'] = (!empty($column['_value'])) ? $column['_value'] : ' ';
if ($key_data[1] == "LOCAL_ID")
$r['LOCAL_ID'] = (!empty($column['_value'])) ? $column['_value'] : ' ';
if ($key_data[1] == "REDIRECT")
$r['redirect'] = (!empty($column['_value'])) ? $column['_value'] : ' ';
$r['metadata'] = (!empty($r['metadata']) ? $r['metadata'] . "|" : "") . $key_data[1] .':' .$column['_value'];

// check if server have https://, if not, go with http://
Expand Down
45 changes: 45 additions & 0 deletions resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
if (!empty($result)) {
// found URL field bound associated with the ark id
$url = $result;

// TODO: add a counter here
increase_reidrection($db, $arkid);
break;
}
}
Expand All @@ -84,6 +87,9 @@
// found URL field bound associated with the ark id
$dns = getNAA($db);
$url = "https://$dns/islandora/object/" . $pid;

// TODO: add a counter here
increase_reidrection($db, $arkid);
break;
}
}
Expand All @@ -95,6 +101,45 @@
print "invalid argument";
}

/**
* Counting redirection
*/
function increase_reidrection($db, $ark_id) {

// TODO UPDATE REDIRECTION COUNT HERE
$link = mysqli_connect(MysqlArkConf::$mysql_host, MysqlArkConf::$mysql_user, MysqlArkConf::$mysql_passwd, MysqlArkConf::$mysql_dbname);

if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}

// get existed redirection count.
$count = lookup($db, $ark_id, "REDIRECT");
if ($count == false) {
$count = 1;
// do insert
$query = "INSERT INTO `$db` (_key, _value) VALUES('$ark_id REDIRECT', $count)";
}
else {
$where = 'WHERE _key regexp "(^|[[:space:]])'.$ark_id.'([[:space:]])REDIRECT$"';
$count++;
// do update
$query = "UPDATE `$db` SET _value = $count ". $where;
}

$count++;
if (mysqli_query($link, $query)) {
echo "New record created successfully";
}
else {
echo "New record created failed";
}
mysqli_close($link);
}

/**
* Get Org registered info
*/
Expand Down

0 comments on commit f149956

Please sign in to comment.