#!/usr/bin/perl

use DBI;
use lib '/opt/oma/oma-bin';
use OMA;

$db = OMA::opendb();

sub updater {
	my $kind = shift;
	$st=$db->prepare("select * from ". $kind ."_page");
	$st->execute();
	while(@row=$st->fetchrow()) {
		@t = split(/\//,$row[14]);
		$sf = $t[$#t];
		$f = "/data/archive$row[4]$row[0]/$t[$#t]";
		if(-f $f) {
		
			$codec = `file $f`;
			$codec =~ s/$f:\ //;
			chop($codec);
			$st2=$db->prepare("update ". $kind ."_page set dc__identifier='$sf',dc__format__encoding='$codec' where id=$row[0]");
			$st2->execute();
		}
	}
	$st->finish();
}

updater("opa");
