This is an old revision of the document!


Script to modify DC datastream dc:date

  • Main script:
#!/bin/bash
#
# 1 fedoraAdmin password
while read line; do
	lline=${#line}
	if [ $lline -gt 0 ]
	then
	  pid="${line%%,*}"
	  datepages="${line#*,}"
	  date="${datepages%%,*}"
	  pages="${datepages#*,}"
          echo "$pid $date $pages"
          ./modificaDSbookepage.sh $pid $date $pages $1
        fi
done < "elenco.txt"
exit
  • modificaDSbookepage.sh
#!/bin/bash
#
# 1 Book PID
# 2 New date
# 3 N pages
# 4 fedoraAdmin password
#
#es. ./modificaDSbookepage.sh fgramsci:TO024-00001 1984-01 52 password
#
PID=$1
NEWDATE=$2
PAGES=$3
./modificaDCdate.php $PID $NEWDATE
risultato=$(./fedora-modify.sh fc1.to.cnr.it:8080 fedoraAdmin $4 bmodify.xml ../logs/log http)
if [[ "$risultato" == *Valid* ]]
then 
   echo "Is Valid ..."	
   ./fedora-modify.sh fc1.to.cnr.it:8080 fedoraAdmin $4 bmodify.xml ../logs/log http YES
else 
   echo "ERROR XML: $risultato"
   exit
fi
for (( npage=1; npage<=$PAGES; npage++ ))
do
   snpage=$(printf "%04d" $npage)
   pagePID="$PID""-""$snpage"
   echo $pagePID
   ./modificaDCdate.php $pagePID $NEWDATE
   risultato=$(./fedora-modify.sh fc1.to.cnr.it:8080 fedoraAdmin $4 bmodify.xml ../logs/log http)
   if [[ "$risultato" == *Valid* ]]
   then 
      echo "Is Valid ..."	
      ./fedora-modify.sh fc1.to.cnr.it:8080 fedoraAdmin $4 bmodify.xml ../logs/log http YES
   else 
      echo "ERROR XML: $risultato"
      exit
   fi
done
exit
  • modificaDCdate.php
#!/usr/bin/php
<?php
if ($argc != 3 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
 
This is a command line PHP script with two options.
 
  Usage:
  <?php
    echo $argv[0]; ?> <option>
 
  <option> can be some word you would like
  to print out. With the --help, -help, -h,
  or -? options, you can get this help.
 
<?php
    exit;
} else {
    $PID = $argv[1];
    $Nuovadata = $argv[2];
}
$indoc = new DOMDocument();
$indoc->formatOutput = true;
$indoc->preserveWhiteSpace = false;
$indoc->load('http://fc1.to.cnr.it:8080/fedora/objects/' . $PID . '/datastreams/DC/content');
$innode = $indoc->getElementsByTagNameNS('http://www.openarchives.org/OAI/2.0/oai_dc/', 'dc')->item(0);
$dcdate = $innode->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', 'date')->item(0);
$olddcdate = $innode->removeChild($dcdate);
print_r($dcdate->nodeValue . " <- " . $Nuovadata . "\n");
$newdate = $indoc->createElement('dc:date', $Nuovadata);
$innode->appendChild($newdate);
$dom = new DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$element = $dom->createElement('fbm:batchModify');
$element->setAttribute('xmlns:fbm', 'http://www.fedora.info/definitions/');
$element->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$element->setAttribute('xsi:schemaLocation', 'http://www.fedora.info/definitions/ http://www.fedora-commons.org/definitions/1/0/api/batchModify-1.1.xsd');
$dom->appendChild($element);
$element1 = $dom->createElement('fbm:modifyDatastream');
$element1->setAttribute('pid', $PID);
$element1->setAttribute('dsID', 'DC');
$element1->setAttribute('dsControlGroupType', 'X');
$element1->setAttribute('logMessage', 'BatchModify - modifyDatastream');
$element->appendChild($element1);
$element2 = $dom->createElement('fbm:xmlData');
$element1->appendChild($element2);
$newnode = $dom->importNode($innode, true);
$element2->appendChild($newnode);
//	print $dom->saveXML()."\n";
//	print "======================"."\n";
print 'Wrote: ' . $dom->save("bmodify.xml") . ' bytes' . "\n";
?>
  • b
 
  • c
 
 
 
repo/dcdate.1342089076.txt.gz ยท Last modified: 2012/07/12 12:31 by giancarlo

Developers: CNR IRCrES IT Office and Library
Giancarlo Birello (giancarlo.birello _@_ ircres.cnr.it) and Anna Perin (anna.perin _@_ ircres.cnr.it)
DigiBess is licensed under: Creative Commons License
Recent changes RSS feed Creative Commons License Valid XHTML 1.0 Valid CSS Driven by DokuWiki
Drupal Garland Theme for Dokuwiki