Completed
Push — 2.0 ( b5ef61...2c7009 )
by Marco
12:59 queued 12s
created

Worklog::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php namespace Comodojo\Extender\Tasks;
2
3
use \Comodojo\Dispatcher\Components\Configuration;
4
use \Psr\Log\LoggerInterface;
5
use \Doctrine\DBAL\Connection;
6
7
/**
8
 * Task object
9
 *
10
 * @package     Comodojo extender
11
 * @author      Marco Giovinazzi <[email protected]>
12
 * @license     GPL-3.0+
13
 *
14
 * LICENSE:
15
 * 
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28
 */
29
30
class Worklog {
31
    
32
    private $dbh;
33
    
34
    private $table;
35
    
36
    public function __construct(Connection $dbh, $table) {
37
        
38
        $this->dbh = $dbh;
39
        
40
        $this->table = $table;
41
42
    }
43
    
44
    public function open($pid, $name, $jobid, $task, $start) {
45
        
46
        $this->dbh
47
            ->createQueryBuilder()
48
            ->insert($this->table)
49
            ->values(array (
50
                'status' => 'RUNNING',
51
                'pid' => '?',
52
                'name' => '?',
53
                'jobid' => '?',
54
                'task' => '?',
55
                'start' => '?'
56
            ))
57
            ->setParameter(0, $pid)
58
            ->setParameter(1, $name)
59
            ->setParameter(2, $jobid)
60
            ->setParameter(3, $task)
61
            ->setParameter(4, $start)
62
            ->getQuery()
63
            ->execute();
64
        
65
        return $this->dbh->lastInsertId();
66
        
67
    }
68
    
69
    public function close($wid, $success, $result, $end) {
70
        
71
        $this->dbh
72
            ->createQueryBuilder()
73
            ->update($this->table)
74
            ->where("id = $wid")
75
            ->values(array (
76
                'status' => 'FINISHED',
77
                'success' => '?',
78
                'result' => '?',
79
                'end' => '?'
80
            ))
81
            ->setParameter(0, $success)
82
            ->setParameter(1, $result)
83
            ->setParameter(2, $end)
84
            ->getQuery()
85
            ->execute();
86
        
87
    }
88
    
89
}