#!/usr/bin/perl use PSync::PunchClock; use ColdSync; use DBI; use Time::ParseDate; use strict; use warnings; use vars qw( $PDB ); StartConduit("dump"); my $project = $PDB->{name}; $project =~ s/^PC_//; $project =~ s/-PClk$//; my $dbh = DBI->connect( 'dbi:mysql:punchclock', 'pc', 'pc' ) || die "Graaah!"; if ($project eq 'projectDB') { my $get = $dbh->prepare(" select ID from project where name = ? "); my $put = $dbh->prepare(" insert into project (name, category) values (?,?) "); # Create the projects database table foreach my $record ( @{$PDB->{records}} ) { my $id; my $name = $record->{data}; $name =~ s/^...//; $name =~ s/\0.PC_.*$//; # Is this already in the database? $get->execute($name); $get->bind_columns( undef, \( $id ) ); if ( $get->fetch ) { # Cool, nothing to do } else { $put->execute( $name , $record->{category} ); } } $put->finish; $get->finish; } else { # It is a project time file # Get the project ID # Note that you may need to sync twice for this to work, if you have not built # the project table yet. my ($id, $sth); $sth = $dbh->prepare("select ID from project where name='$project' "); $sth->execute; $sth->bind_columns(undef, \($id)); if ($sth->fetch) { $sth = $dbh->prepare("insert into timecard (projectID, startdate, total) values ($id, ?, ?)"); $dbh->do("delete from timecard where projectID=$id"); foreach my $record (@{$PDB->{"records"}}){ my $date = parsedate( $record->{StartDate} ); $sth->execute( $date, $record->{Total} ); } $sth->finish; } } $dbh->disconnect; EndConduit;