Skip to content
Extraits de code Groupes Projets
Valider a1344b5c rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

Sam::commands::add uses the ORM

parent 49294d48
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -4,28 +4,34 @@ require Exporter; ...@@ -4,28 +4,34 @@ require Exporter;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT_OK = qw(exec); our @EXPORT_OK = qw(exec);
use Sam::Chan;
use Sam::Event;
use Time::Local; use Time::Local;
our $dbh; our $dbh;
our $log; our $log;
sub exec { sub exec {
my ($title, $day, $month, $year, $place, $desc) = @_; my ($chanName, $title, $day, $month, $year, $place, $desc) = @_;
my $timestamp = timelocal(0, 59, 23, $day, $month - 1, $year); my $timestamp = timelocal(0, 59, 23, $day, $month - 1, $year);
my $sth = $dbh->prepare_cached('INSERT INTO sam (title, date, place, description) my $chan = Sam::Chan->new(name => $chanName);
VALUES (?, ?, ?, ?)'); $chan->load();
unless (defined $sth) { my $event = Sam::Event->new(
$log->error("Couldn't prepare querie; aborting"); title => $title,
return; date => $timestamp,
} place => $place,
description => $desc,
calendar => $chan->calendar
);
print $chan->name, $chan->calendar_id, "\n";
$sth->execute($title, $timestamp, $place, $desc) # insert into db
or $log->error("Couldn't finish transaction: " . $dbh->errstr); $event->save();
my $id = $sth->{mysql_insertid}; return $event->id;
return $id;
} }
1; 1;
...@@ -66,7 +66,7 @@ sub exec { ...@@ -66,7 +66,7 @@ sub exec {
$place =~ s/ $//; $place =~ s/ $//;
my $id = Sam::commands::add::exec($title, $day, $month, $year, $place, $desc); my $id = Sam::commands::add::exec($chan->[0], $title, $day, $month, $year, $place, $desc);
if ($id) { if ($id) {
$lastID->{$chan->[0]} = $id; $lastID->{$chan->[0]} = $id;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter