Commit bf26c03b authored by Leigh Stoller's avatar Leigh Stoller

More changes to reservation history; since these are history tables,

need uid_idx and pid_idx. Also store the cancel date.

Fix bug; we were not storing a history entry for deleted reservations,
so we lost all those entries even though they were reservations that
were used.
parent 1dd11066
......@@ -451,14 +451,24 @@ sub Cancel($)
my $idx = $self->idx();
my $type = $self->type();
DBQueryWarn( "DELETE FROM future_reservations WHERE idx=$idx" )
or return -1;
if (defined($self->approved())) {
DBQueryFatal("INSERT INTO reservation_history ".
" (uuid, pid, pid_idx, nodes, type, deleted, canceled, " .
" created, start, end, uid, uid_idx, ".
" notes, admin_notes) " .
"SELECT uuid, pid, pid_idx, nodes, type, now(), ".
" cancel, created,".
" start, end, uid, uid_idx, notes, admin_notes ".
"FROM future_reservations WHERE idx='$idx'");
}
DBQueryWarn( "DELETE FROM future_reservation_attributes WHERE " .
"reservation_idx=$idx" )
or return -1;
DBQueryWarn( "DELETE FROM future_reservations WHERE idx=$idx" )
or return -1;
delete $cache{$type};
return 0;
......@@ -534,9 +544,11 @@ sub Tidy($)
"reservation_history WRITE, " .
"future_reservation_attributes AS a WRITE, " .
"future_reservations AS r READ" );
DBQueryFatal( "INSERT INTO reservation_history( uuid, pid, nodes, type, " .
"created, start, end, uid, notes, admin_notes ) " .
"SELECT uuid, pid, nodes, type, created, start, end, uid, " .
DBQueryFatal( "INSERT INTO reservation_history( uuid, pid, pid_idx, ".
"nodes, type, deleted, canceled, " .
"created, start, end, uid, uid_idx, notes, admin_notes ) " .
"SELECT uuid, pid, pid_idx, nodes, type, deleted, ".
"cancel, created, start, end, uid, uid_idx, " .
"notes, admin_notes FROM future_reservations WHERE " .
"end < '$stamp' and approved is not null" );
DBQueryFatal( "DELETE FROM future_reservations WHERE " .
......
......@@ -4624,13 +4624,16 @@ CREATE TABLE `reposition_status` (
DROP TABLE IF EXISTS `reservation_history`;
CREATE TABLE `reservation_history` (
`pid` varchar(48) NOT NULL DEFAULT '',
`pid_idx` mediumint(8) unsigned NOT NULL default '0',
`nodes` smallint(5) NOT NULL DEFAULT '0',
`type` varchar(30) NOT NULL DEFAULT '',
`created` datetime DEFAULT NULL,
`deleted` datetime DEFAULT NULL,
`canceled` datetime DEFAULT NULL,
`start` datetime DEFAULT NULL,
`end` datetime DEFAULT NULL,
`uid` varchar(8) NOT NULL DEFAULT '',
`uid_idx` mediumint(8) unsigned NOT NULL default '0',
`notes` mediumtext,
`admin_notes` mediumtext,
`uuid` varchar(40) NOT NULL default '',
......
use strict;
use libdb;
use emdb;
use Project;
use User;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBSlotExists("reservation_history", "pid_idx")) {
DBQueryFatal("alter table reservation_history add ".
" `pid_idx` mediumint(8) unsigned NOT NULL default '0' ".
" after pid");
}
if (!DBSlotExists("reservation_history", "uid_idx")) {
DBQueryFatal("alter table reservation_history add ".
" `uid_idx` mediumint(8) unsigned NOT NULL default '0' ".
" after uid");
}
if (!DBSlotExists("reservation_history", "canceled")) {
DBQueryFatal("alter table reservation_history add ".
" `canceled` datetime DEFAULT NULL ".
" after deleted");
}
my $query_result =
DBQueryFatal("select pid,start,end from reservation_history ".
"where pid_idx=0");
while (my ($pid,$start,$end) = $query_result->fetchrow_array()) {
my $project = Project->Lookup($pid);
if (!defined($project)) {
print STDERR "Oops, project $pid no longer exists!";
next;
}
my $pid_idx = $project->pid_idx();
DBQueryFatal("update reservation_history set ".
" pid_idx='$pid_idx' ".
"where pid='$pid' and start='$start' and end='$end'");
}
$query_result =
DBQueryFatal("select pid,uid,start,end from reservation_history ".
"where uid_idx=0");
while (my ($pid,$uid,$start,$end) = $query_result->fetchrow_array()) {
my $user = User->Lookup($uid);
if (!defined($user)) {
print STDERR "Oops, user $uid no longer exists!";
next;
}
my $uid_idx = $user->uid_idx();
DBQueryFatal("update reservation_history set ".
" uid_idx='$uid_idx' ".
"where pid='$pid' and start='$start' and end='$end'");
}
$query_result =
DBQueryFatal("select pid,start,end from reservation_history ".
"where uuid=''");
while (my ($pid,$start,$end) = $query_result->fetchrow_array()) {
DBQueryFatal("update reservation_history set ".
" uuid=uuid() ".
"where pid='$pid' and start='$start' and end='$end'");
sleep(1);
}
return 0;
}
# Local Variables:
# mode:perl
# End:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment