cleaning and fixing

This commit is contained in:
Usuario Moodle 2013-05-07 17:01:22 -03:00
parent a89f4b7fa1
commit 91a657ae57
13 changed files with 919 additions and 951 deletions

View File

@ -17,7 +17,6 @@ require_once('xml_creater.php');
* The protected member functions are the backbone functions which can be used for creating any ANDS RIF-CS records. * The protected member functions are the backbone functions which can be used for creating any ANDS RIF-CS records.
* *
*/ */
class ANDS_RIFCS { class ANDS_RIFCS {
/** /**
* \var $oai_pmh * \var $oai_pmh
@ -257,4 +256,3 @@ class ANDS_RIFCS {
$c->setAttribute('type',$subject_type); $c->setAttribute('type',$subject_type);
} }
} // end of class ANDS_RIFCS } // end of class ANDS_RIFCS

View File

@ -109,13 +109,13 @@ class ANDS_TPA extends ANDS_RIFCS {
$this->create_rifcs_node('activity','project'); $this->create_rifcs_node('activity','project');
$c = $this->create_name_node(); $c = $this->create_name_node();
$this->create_namePart($c,'The Plant Accelerator Project '.$record['inter_no']); $this->create_namePart($c,'The Plant Accelerator Project '.$record['inter_no']);
// Test codes for rich format. // Test codes for rich format.
# // \n works # // \n works
# $this->create_description_node(sprintf("Line one:%s,\nLine two:%s.\nThird",'a','b')); # $this->create_description_node(sprintf("Line one:%s,\nLine two:%s.\nThird",'a','b'));
$this->create_description_node(str_replace("\r\n","\n",$record['pub_descrip'])); $this->create_description_node(str_replace("\r\n","\n",$record['pub_descrip']));
$this->create_description_node('The experiment was carried out between '.$record['start_date'].' and '.$record['end_date'],'note'); $this->create_description_node('The experiment was carried out between '.$record['start_date'].' and '.$record['end_date'],'note');
$query = sprintf("select idr,stype from list_prj_ids_v2(%d) where stype in ('dataset','person')",$id_project); $query = sprintf("select idr,stype from list_prj_ids_v2 where stype in ('dataset','person')",$id_project);
// echo $query; // echo $query;
try { try {
$res = $db->query($query,PDO::FETCH_ASSOC); $res = $db->query($query,PDO::FETCH_ASSOC);
@ -346,4 +346,3 @@ class ANDS_TPA extends ANDS_RIFCS {
} }
} }
} // end of class ANDS_TPA } // end of class ANDS_TPA

View File

@ -16,8 +16,7 @@ $metadataPrefix = $args['metadataPrefix'];
// myhandler is a php file which will be included to generate metadata node. // myhandler is a php file which will be included to generate metadata node.
// $inc_record = $METADATAFORMATS[$metadataPrefix]['myhandler']; // $inc_record = $METADATAFORMATS[$metadataPrefix]['myhandler'];
if (is_array($METADATAFORMATS[$metadataPrefix]) if (is_array($METADATAFORMATS[$metadataPrefix]) && isset($METADATAFORMATS[$metadataPrefix]['myhandler'])) {
&& isset($METADATAFORMATS[$metadataPrefix]['myhandler'])) {
$inc_record = $METADATAFORMATS[$metadataPrefix]['myhandler']; $inc_record = $METADATAFORMATS[$metadataPrefix]['myhandler'];
} else { } else {
$errors[] = oai_error('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix); $errors[] = oai_error('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix);
@ -42,7 +41,6 @@ if ($res===false) {
$errors[] = oai_error('idDoesNotExist', '', $identifier); $errors[] = oai_error('idDoesNotExist', '', $identifier);
} }
if (!empty($errors)) { if (!empty($errors)) {
oai_exit(); oai_exit();
} }
@ -60,12 +58,8 @@ $identifier = $record[$SQL['identifier']];;
$datestamp = formatDatestamp($record[$SQL['datestamp']]); $datestamp = formatDatestamp($record[$SQL['datestamp']]);
if (isset($record[$SQL['deleted']]) && ($record[$SQL['deleted']] == 'true') && $status_deleted = (isset($record[$SQL['deleted']]) && ($record[$SQL['deleted']] == 'true') &&
($deletedRecord == 'transient' || $deletedRecord == 'persistent')) { ($deletedRecord == 'transient' || $deletedRecord == 'persistent'));
$status_deleted = TRUE;
} else {
$status_deleted = FALSE;
}
$outputObj = new ANDS_Response_XML($args); $outputObj = new ANDS_Response_XML($args);
$cur_record = $outputObj->create_record(); $cur_record = $outputObj->create_record();
@ -77,4 +71,3 @@ if (!$status_deleted) {
} else { } else {
$cur_header->setAttribute("status","deleted"); $cur_header->setAttribute("status","deleted");
} }
?>

View File

@ -18,6 +18,7 @@ if (SHOW_QUERY_ERROR) {
echo 'XMLSCHEMA: ',XMLSCHEMA,"\n"; echo 'XMLSCHEMA: ',XMLSCHEMA,"\n";
echo "\n"; echo "\n";
} }
$outputObj = new ANDS_Response_XML($args); $outputObj = new ANDS_Response_XML($args);
foreach($identifyResponse as $key => $val) { foreach($identifyResponse as $key => $val) {
$outputObj->add2_verbNode($key, $val); $outputObj->add2_verbNode($key, $val);
@ -132,4 +133,3 @@ if(strlen($output)>10) {
$des->appendXML($output); $des->appendXML($output);
$outputObj->verbNode->appendChild($des); $outputObj->verbNode->appendChild($des);
} }
?>

View File

@ -136,6 +136,3 @@ University of Adelaide
</p> </p>
</body> </body>
</html> </html>

View File

@ -59,9 +59,7 @@ if (isset($mf)) {
foreach($METADATAFORMATS as $key=>$val) { foreach($METADATAFORMATS as $key=>$val) {
addMetedataFormat($outputObj,$key, $val); addMetedataFormat($outputObj,$key, $val);
} }
} } else { // a very unlikely event
else { // a very unlikely event
$errors[] = oai_error('noMetadataFormats'); $errors[] = oai_error('noMetadataFormats');
oai_exit(); oai_exit();
} }
?>

View File

@ -54,8 +54,7 @@ if (!empty($errors)) {
} }
// Load the handler // Load the handler
if (is_array($METADATAFORMATS[$metadataPrefix]) if (is_array($METADATAFORMATS[$metadataPrefix]) && isset($METADATAFORMATS[$metadataPrefix]['myhandler'])) {
&& isset($METADATAFORMATS[$metadataPrefix]['myhandler'])) {
$inc_record = $METADATAFORMATS[$metadataPrefix]['myhandler']; $inc_record = $METADATAFORMATS[$metadataPrefix]['myhandler'];
include($inc_record); include($inc_record);
} else { } else {
@ -72,8 +71,8 @@ if (empty($errors)) {
$res = $db->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $res = $db->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$r = $res->execute(); $r = $res->execute();
if ($r===false) { if (($r===false) ) {
if (SHOW_QUERY_ERROR) { if ( (SHOW_QUERY_ERROR)) {
echo __FILE__.','.__LINE__."<br />"; echo __FILE__.','.__LINE__."<br />";
echo "Query: $query<br />\n"; echo "Query: $query<br />\n";
print_r($db->errorInfo()); print_r($db->errorInfo());
@ -88,7 +87,9 @@ if (empty($errors)) {
} }
$num_rows = rowCount($metadataPrefix, $extquery, $db); $num_rows = rowCount($metadataPrefix, $extquery, $db);
if ($num_rows==0) { if ($num_rows==0) {
if (SHOW_QUERY_ERROR) {
echo "Cannot find records: $query\n"; echo "Cannot find records: $query\n";
}
$errors[] = oai_error('noRecordsMatch'); $errors[] = oai_error('noRecordsMatch');
} }
} }
@ -144,12 +145,8 @@ while ($countrec++ < $maxrec) {
$setspec = $record[$SQL['set']]; $setspec = $record[$SQL['set']];
// debug_var_dump('record', $record); // debug_var_dump('record', $record);
if (isset($record[$SQL['deleted']]) && ($record[$SQL['deleted']] === true) && $status_deleted = (isset($record[$SQL['deleted']]) && ($record[$SQL['deleted']] === true) &&
($deletedRecord == 'transient' || $deletedRecord == 'persistent')) { ($deletedRecord == 'transient' || $deletedRecord == 'persistent'));
$status_deleted = TRUE;
} else {
$status_deleted = FALSE;
}
//debug_var_dump('status_deleted', $status_deleted); //debug_var_dump('status_deleted', $status_deleted);
if($args['verb']=='ListRecords') { if($args['verb']=='ListRecords') {
@ -179,4 +176,3 @@ if (isset($restoken)) {
// end ListRecords // end ListRecords
if (SHOW_QUERY_ERROR) {echo "Debug listrecord.php reached to the end.\n\n";} if (SHOW_QUERY_ERROR) {echo "Debug listrecord.php reached to the end.\n\n";}
?>

View File

@ -26,5 +26,3 @@ if (is_array($SETS)) {
$errors[] = oai_error('noSetHierarchy'); $errors[] = oai_error('noSetHierarchy');
oai_exit(); oai_exit();
} }
?>

View File

@ -152,7 +152,9 @@ if (isset($args['verb'])) {
$errors[] = oai_error('noVerb'); $errors[] = oai_error('noVerb');
} }
if (!empty($errors)) { oai_exit(); } if (!empty($errors)) {
oai_exit();
}
if ($compress) { if ($compress) {
ob_start('ob_gzhandler'); ob_start('ob_gzhandler');
@ -160,7 +162,7 @@ if ($compress) {
header(CONTENT_TYPE); header(CONTENT_TYPE);
if(isset($outputObj)) { if (isset($outputObj)) {
$outputObj->display(); $outputObj->display();
} else { } else {
exit("There is a bug in codes"); exit("There is a bug in codes");
@ -169,5 +171,3 @@ if(isset($outputObj)) {
if ($compress) { if ($compress) {
ob_end_flush(); ob_end_flush();
} }
?>

View File

@ -119,12 +119,12 @@ $deletedRecord = $identifyResponse["deletedRecord"]; // a shorthand for checking
//granularity is days //granularity is days
//$granularity = 'YYYY-MM-DD'; //$granularity = 'YYYY-MM-DD';
// granularity is seconds // granularity is seconds
$identifyResponse["granularity"] = 'YYYY-MM-DD'; $identifyResponse["granularity"] = 'YYYY-MM-DDThh:mm:ssZ';
// this is appended if your granularity is seconds. // this is appended if your granularity is seconds.
// do not change // do not change
if (strcmp($identifyResponse["granularity"],'YYYY-MM-DDThh:mm:ssZ')==0) { if (strcmp($identifyResponse["granularity"],'YYYY-MM-DDThh:mm:ssZ')==0) {
$identifyResponse["earliestDatestamp"] = $identifyResponse["earliestDatestamp"].'T00:00:00Z'; // $identifyResponse["earliestDatestamp"] = $identifyResponse["earliestDatestamp"].'T00:00:00Z';
} }
/** Compression methods supported. Optional (multiple). Default: null. /** Compression methods supported. Optional (multiple). Default: null.

View File

@ -39,8 +39,9 @@ function debug_print_r($var_name, $var) {
* \see SHOW_QUERY_ERROR in oaidp-config.php * \see SHOW_QUERY_ERROR in oaidp-config.php
*/ */
function debug_message($msg) { function debug_message($msg) {
if (!SHOW_QUERY_ERROR) return; if (SHOW_QUERY_ERROR) {
echo $msg,"\n"; echo $msg,"\n";
}
} }
/** Check if provided correct arguments for a request. /** Check if provided correct arguments for a request.
@ -53,9 +54,9 @@ function debug_message($msg) {
* is needed. * is needed.
*/ */
function checkArgs($args, $checkList) { function checkArgs($args, $checkList) {
// global $errors, $TOKEN_VALID, $METADATAFORMATS; // global $errors, $TOKEN_VALID, $METADATAFORMATS;
global $errors, $METADATAFORMATS; global $errors, $METADATAFORMATS;
// $verb = $args['verb']; // $verb = $args['verb'];
unset($args["verb"]); unset($args["verb"]);
debug_print_r('checkList',$checkList); debug_print_r('checkList',$checkList);
@ -117,8 +118,7 @@ function checkArgs($args, $checkList) {
* Used only by function <B>oai_error</B> code idDoesNotExist. * Used only by function <B>oai_error</B> code idDoesNotExist.
* \param $url Type: string * \param $url Type: string
*/ */
function is_valid_uri($url) function is_valid_uri($url) {
{
return((bool)preg_match('/^[-a-z\.0-9]+$/i', $url)); return((bool)preg_match('/^[-a-z\.0-9]+$/i', $url));
} }
@ -127,15 +127,14 @@ function is_valid_uri($url)
* Here there are few more match patterns than is_valid_uri(): ':_'. * Here there are few more match patterns than is_valid_uri(): ':_'.
* \param $attrb Type: string * \param $attrb Type: string
*/ */
function is_valid_attrb($attrb) { function is_valid_attrb($attrb) {
return preg_match("/^[_a-zA-Z0-9\-\:\.]+$/",$attrb); return preg_match("/^[_a-zA-Z0-9\-\:\.]+$/",$attrb);
} }
/** All datestamps used in this system are GMT even /** All datestamps used in this system are GMT even
* return value from database has no TZ information * return value from database has no TZ information
*/ */
function formatDatestamp($datestamp) function formatDatestamp($datestamp) {
{
return date("Y-m-d\TH:i:s\Z",strtotime($datestamp)); return date("Y-m-d\TH:i:s\Z",strtotime($datestamp));
} }
@ -156,7 +155,7 @@ function checkDateFormat($date) {
/** Retrieve all defined 'setSpec' from configuraiton of $SETS. /** Retrieve all defined 'setSpec' from configuraiton of $SETS.
* It is used by ANDS_TPA::create_obj_node(); * It is used by ANDS_TPA::create_obj_node();
*/ */
function prepare_set_names() { function prepare_set_names() {
global $SETS; global $SETS;
$n = count($SETS); $n = count($SETS);
@ -168,9 +167,9 @@ function prepare_set_names() {
} }
/** Finish a request when there is an error: send back errors. */ /** Finish a request when there is an error: send back errors. */
function oai_exit() function oai_exit() {
{
// global $CONTENT_TYPE; // global $CONTENT_TYPE;
header(CONTENT_TYPE); header(CONTENT_TYPE);
global $args,$errors,$compress; global $args,$errors,$compress;
$e = new ANDS_Error_XML($args,$errors); $e = new ANDS_Error_XML($args,$errors);
@ -183,14 +182,12 @@ function oai_exit()
if ($compress) { if ($compress) {
ob_end_flush(); ob_end_flush();
} }
exit(); exit();
} }
// ResumToken section // ResumToken section
/** Generate a string based on the current Unix timestamp in microseconds for creating resumToken file name. */ /** Generate a string based on the current Unix timestamp in microseconds for creating resumToken file name. */
function get_token() function get_token() {
{
list($usec, $sec) = explode(" ", microtime()); list($usec, $sec) = explode(" ", microtime());
return ((int)($usec*1000) + (int)($sec*1000)); return ((int)($usec*1000) + (int)($sec*1000));
} }
@ -235,8 +232,7 @@ function readResumToken($resumptionToken) {
* the useless condition id_column = id_column is just there to ease * the useless condition id_column = id_column is just there to ease
* further extensions to the query, please leave it as it is. * further extensions to the query, please leave it as it is.
*/ */
function selectallQuery ($metadPrefix = "rif", $id = '') function selectallQuery($metadPrefix = "rif", $id = ''){
{
global $SQL; global $SQL;
$query = "SELECT * FROM ".$SQL['table'] . " WHERE ".$SQL['metadataPrefix']." LIKE '%$metadPrefix%'"; $query = "SELECT * FROM ".$SQL['table'] . " WHERE ".$SQL['metadataPrefix']." LIKE '%$metadPrefix%'";
if ($id != '') { if ($id != '') {
@ -246,8 +242,7 @@ function selectallQuery ($metadPrefix = "rif", $id = '')
} }
/** this function will return metadataFormat of a record */ /** this function will return metadataFormat of a record */
function idFormatQuery($id) function idFormatQuery($id) {
{
global $SQL; global $SQL;
return 'select '.$SQL['metadataPrefix'].' FROM '.$SQL['table']. " WHERE ".$SQL['identifier']." = '".$id."'"; return 'select '.$SQL['metadataPrefix'].' FROM '.$SQL['table']. " WHERE ".$SQL['identifier']." = '".$id."'";
} }
@ -255,8 +250,7 @@ function idFormatQuery($id)
/** this function will return identifier and datestamp for all records /** this function will return identifier and datestamp for all records
* not very useful * not very useful
*/ */
function idQuery ($metadPrefix = "rif", $id = '') function idQuery($metadPrefix = "rif", $id = '') {
{
global $SQL; global $SQL;
if ($SQL['set'] != '') { if ($SQL['set'] != '') {
@ -273,24 +267,21 @@ function idQuery ($metadPrefix = "rif", $id = '')
} }
/** filter for until, appends to the end of SQL query */ /** filter for until, appends to the end of SQL query */
function untilQuery($until) function untilQuery($until) {
{
global $SQL; global $SQL;
return ' AND '.$SQL['datestamp']." <= '$until'"; return ' AND '.$SQL['datestamp']." <= '$until'";
} }
/** filter for from , appends to the end of SQL query */ /** filter for from , appends to the end of SQL query */
function fromQuery($from) function fromQuery($from) {
{
global $SQL; global $SQL;
return ' AND '.$SQL['datestamp']." >= '$from'"; return ' AND '.$SQL['datestamp']." >= '$from'";
} }
/** filter for sets, appends to the end of SQL query */ /** filter for sets, appends to the end of SQL query */
function setQuery($set) function setQuery($set) {
{
global $SQL; global $SQL;
// strip off "class:" which is not saved in database // strip off "class:" which is not saved in database
if(strstr($set,"class:")) $set = substr($set,6); if(strstr($set,"class:")) $set = substr($set,6);
@ -311,7 +302,7 @@ function rowCount($metadataPrefix, $extQuery, $db) {
/** A worker function for processing an error when a query was executed /** A worker function for processing an error when a query was executed
* \param $query string, original query * \param $query string, original query
* \param $e PDOException, the PDOException object * \param $e PDOException, the PDOException object
*/ */
function process_pdo_error($query, $e) { function process_pdo_error($query, $e) {
echo $query.' was failed\n'; echo $query.' was failed\n';
echo $e->getMessage(); echo $e->getMessage();
@ -322,11 +313,9 @@ function process_pdo_error($query, $e) {
* \param $query string * \param $query string
* \return $res PDOStatement * \return $res PDOStatement
*/ */
function exec_pdo_query($db, $query) function exec_pdo_query($db, $query) {
{
$res = $db->query($query); $res = $db->query($query);
if ($res===false) { if ($res===false) {
throw new Exception($query.":\nIt found nothing.\n"); throw new Exception($query.":\nIt found nothing.\n");
} else return $res; } else return $res;
} }
?>

View File

@ -60,29 +60,29 @@ function oai_error($code, $argument = '', $value = '')
{ {
switch ($code) { switch ($code) {
case 'badArgument' : case 'badArgument' :
$text = "The argument '$argument' (value='$value') included in the request is not valid."; $text = "Attribute '{$argument}' is not allowed to appear in element 'request'";
break; break;
case 'badGranularity' : case 'badGranularity' :
$text = "The value '$value' of the argument '$argument' is not valid."; $text = "The value '{$value}' of the argument '{$argument}' is not valid.";
$code = 'badArgument'; $code = 'badArgument';
break; break;
case 'badResumptionToken' : case 'badResumptionToken' :
$text = "The resumptionToken '$value' does not exist or has already expired."; $text = "The resumptionToken '{$value}' does not exist or has already expired.";
break; break;
case 'badRequestMethod' : case 'badRequestMethod' :
$text = "The request method '$argument' is unknown."; $text = "The request method '{$argument}' is unknown.";
$code = 'badVerb'; $code = 'badVerb';
break; break;
case 'badVerb' : case 'badVerb' :
$text = "The verb '$argument' provided in the request is illegal."; $text = "The verb '{$argument}' provided in the request is illegal.";
break; break;
case 'cannotDisseminateFormat' : case 'cannotDisseminateFormat' :
$text = "The metadata format '$value' given by $argument is not supported by this repository."; $text = "The metadata format '{$value}' given by {$argument} is not supported by this repository.";
break; break;
case 'exclusiveArgument' : case 'exclusiveArgument' :
@ -91,7 +91,7 @@ function oai_error($code, $argument = '', $value = '')
break; break;
case 'idDoesNotExist' : case 'idDoesNotExist' :
$text = "The value '$value' of the identifier does not exist in this repository."; $text = "The value '{$value}' of the identifier does not exist in this repository.";
if (!is_valid_uri($value)) { if (!is_valid_uri($value)) {
$code = 'badArgument'; $code = 'badArgument';
$text .= ' Invalidated URI has been detected.'; $text .= ' Invalidated URI has been detected.';
@ -99,7 +99,7 @@ function oai_error($code, $argument = '', $value = '')
break; break;
case 'missingArgument' : case 'missingArgument' :
$text = "The required argument '$argument' is missing in the request."; $text = "The required argument '{$argument}' is missing in the request.";
$code = 'badArgument'; $code = 'badArgument';
break; break;
@ -136,7 +136,7 @@ function oai_error($code, $argument = '', $value = '')
break; break;
default: default:
$text = "Unknown error: code: '$code', argument: '$argument', value: '$value'"; $text = "Unknown error: code: '{$code}', argument: '{$argument}', value: '{$value}'";
$code = 'badArgument'; $code = 'badArgument';
} }
return $code."|".$text; return $code."|".$text;