Skip to content

Commit 5ef8719

Browse files
committed
fix #80
1 parent 79b1fef commit 5ef8719

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Controller/AjaxController.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ public function workIntervals() {
9898
$tags = [];
9999
$wiToTags = $this->workIntervalToTagMapper->findAllForWorkInterval($wi->id);
100100
foreach($wiToTags as $wiToTag){
101-
$tags[] = $this->tagMapper->find($wiToTag->tagId);
101+
$t = $this->tagMapper->find($wiToTag->tagId);
102+
if ($t != null)
103+
$tags[] = $t;
102104
}
103105

104106
$wa = ['duration' => $wi->duration,
@@ -317,6 +319,14 @@ public function updateWorkInterval($id) {
317319
foreach($tags as $tag){
318320
if (empty($tag))
319321
continue;
322+
if(!is_numeric($tag)){
323+
$c = new Tag();
324+
$c->setName($tag);
325+
$c->setUserUid($this->userId);
326+
$c->setCreatedAt(time());
327+
$this->tagMapper->insert($c);
328+
$tag = $c->id;
329+
}
320330
$newWiToTag = new WorkIntervalToTag();
321331
$newWiToTag->setWorkIntervalId($id);
322332
$newWiToTag->setTagId($tag);

lib/Db/TagMapper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ public function findByNameUser($name, $userUid) {
3333
public function find($id) {
3434
$sql = 'SELECT * FROM `*PREFIX*timetracker_tag` ' .
3535
'WHERE `id` = ?';
36-
return $this->findEntity($sql, [$id]);
36+
try {
37+
$e = $this->findEntity($sql, [$id]);
38+
return $e;
39+
} catch (\OCP\AppFramework\Db\DoesNotExistException $e){
40+
return null;
41+
}
3742
}
3843

3944

0 commit comments

Comments
 (0)