westdc-zf1/tools/md-thumb-restore.php

46 lines
1.3 KiB
PHP
Raw Normal View History

#!/usr/bin/php
<?php
if ($_SERVER["argc"]<4)
{
print "Usage: md-thumb-restore.php CSV_FILE BACKUP_DIR GN_DATA_DIR\n";
print "\tCSV_FILE:\t the CSV format file which contain id and uuid column\n";
2011-09-20 10:15:55 +00:00
print "\tBACKUP_DIR:\t the destination directory to backup\n";
print "\tGN_DATA_DIR:\t the new Geonetwork data directory\n";
die();
}
$csv=$_SERVER["argv"][1];
$backup_dir=$_SERVER["argv"][2];
$data_dir=$_SERVER["argv"][3];
if (substr($data_dir,-1)!="/")
$data_dir.="/";
if (substr($backup_dir,-1)!="/")
$backup_dir.="/";
$fp=fopen($csv,'rb');
$dus=fread($fp,filesize($csv));
fclose($fp);
$duuids=explode("\n",$dus);
foreach($duuids as $duuid1)
{
$duuid2=explode(";",$duuid1);
if ($duuid2[0]>0)
{
$newdir=$data_dir.sprintf('%05d',floor(($duuid2[0]+0.1)/100)*100).'-'.sprintf('%05d',ceil(($duuid2[0]+0.1)/100)*100-1)."/".$duuid2[0];
print $dir."\n";
$dir=$backup_dir.trim($duuid2[1]);
2011-03-04 14:17:31 +00:00
@rrmdir($newdir);
rename($dir,$newdir);
}
}
2011-03-04 14:17:31 +00:00
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
?>