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

Sam::commands::edt uses the ORM

parent dd708296
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -5,13 +5,15 @@ our @ISA = qw(Exporter);
our @EXPORT_OK = qw(exec);
use Regexp::Common qw(URI);
use Sam::Chan;
use Sam::Event;
our $dbh;
our $log;
our $irc;
sub exec {
my ($id, $command, $arg, $chan) = @_;
my ($id, $command, $arg, $chan_name) = @_;
my $saveCommit = $dbh->{AutoCommit};
my $saveError = $dbh->{RaiseError};
......@@ -23,23 +25,22 @@ sub exec {
die "Ce n'est pas une URL valide";
}
else {
eval {
$sth = $dbh->prepare_cached("UPDATE sam SET link = ? WHERE id = ?");
$sth->execute($arg, $id);
if ($sth->rows == 0) {
die "Aucune soirée trouvée avec cet identifiant";
}
$dbh->commit;
};
my $event = Sam::Event->new(id => $id);
unless ($event->load(speculative => 1)) {
die "aucune soirée trouvée avec cet identifiant";
}
if ($@) {
$log->error("$@");
$dbh->rollback;
my $chan = Sam::Chan->new(name => $chan_name);
unless ($chan->load(speculative => 1)) {
die "ce chan n'est pas encore configuré";
}
die $@;
unless ($event->calendar_id == $chan->calendar_id) {
die "cette soirée ne fait pas partie du calendrier associé à ce chan";
}
$event->link($arg);
$event->save();
}
}
else {
......
......@@ -85,7 +85,7 @@ sub exec {
my $arg = $3;
eval {
Sam::commands::edit::exec($id, $command, $arg, $chan);
Sam::commands::edit::exec($id, $command, $arg, $chan->[0]);
};
if ($@) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter