Allow re-opening the last closed task
authorJoey Schulze <joey@infodrom.org>
Sat, 23 Apr 2016 18:09:37 +0000 (18:09 +0000)
committerJoey Schulze <joey@infodrom.org>
Sat, 23 Apr 2016 18:09:37 +0000 (18:09 +0000)
src/InfoCon/stempel/stempel

index b3abec9..06dc909 100755 (executable)
@@ -197,6 +197,19 @@ sub delete_task
     exit(0);
 }
 
+sub reopen_task
+{
+    my $sql = q{SELECT max(id) AS max_id FROM stempel};
+    my $sth = $dbh->prepare($sql);
+    if ($sth && $sth->execute > 0) {
+       my $row = $sth->fetchrow_hashref;
+       $sql = sprintf("UPDATE stempel SET stop = NULL, time = NULL WHERE id = %d", $row->{max_id});
+       $dbh->do($sql);
+    }
+
+    exit(0);
+}
+
 sub list_open
 {
     my $exit = shift;
@@ -332,6 +345,7 @@ stempel  Copyright (c) 2007,8  Martin Schulze <joey\@infodrom.org>
     --help         this text
     --end|-d       terminate task
     --delete       delete open task
+    --reopen       re-open last task
     --task         alter task content
 END
     exit;
@@ -346,6 +360,7 @@ my %options = ('list:s' => \$opt_list,
               'help' => \&help,
               'close=i' => \$opt_close,
               'delete' => \&delete_task,
+              'reopen' => \&reopen_task,
               'task|t' => \&alter_task,
               'terminate|end|d' => \&close_task,
               );