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;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(exec);
use Sam::Chan;
use Sam::Event;
use Time::Local;
our $dbh;
our $log;
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 $sth = $dbh->prepare_cached('INSERT INTO sam (title, date, place, description)
VALUES (?, ?, ?, ?)');
my $chan = Sam::Chan->new(name => $chanName);
$chan->load();
unless (defined $sth) {
$log->error("Couldn't prepare querie; aborting");
return;
}
my $event = Sam::Event->new(
title => $title,
date => $timestamp,
place => $place,
description => $desc,
calendar => $chan->calendar
);
print $chan->name, $chan->calendar_id, "\n";
$sth->execute($title, $timestamp, $place, $desc)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
# insert into db
$event->save();
my $id = $sth->{mysql_insertid};
return $id;
return $event->id;
}
1;
......@@ -66,7 +66,7 @@ sub exec {
$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) {
$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