Completed
Pull Request — master (#6)
by Laurent
01:49
created

BbcMonthlyFlightsBillCron   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A run() 0 17 2
1
<?php
2
3
require_once __DIR__ . '/../../command/CreateMonthBillCommandHandler.php';
4
require_once __DIR__ . '/../../command/CreateMonthBillCommand.php';
5
6
/**
7
 * @author Laurent De Coninck <[email protected]>
8
 */
9
class BbcMonthlyFlightsBillCron
10
{
11
12
    /**
13
     * @var DoliDB
14
     */
15
    private $db;
16
17
    /**
18
     * @var stdClass
19
     */
20
    private $conf;
21
22
    private $langs;
23
24
    private $user;
25
26
    /**
27
     * @var CreateMonthBillCommandHandler
28
     */
29
    private $handler;
30
31
    /**
32
     * @param DoliDB $db
33
     */
34
    public function __construct($db)
35
    {
36
        global $conf, $langs, $user;
37
38
        $this->db = $db;
39
        $this->conf = $conf->global;
40
        $this->langs = $langs;
41
        $this->user = $user;
42
        $this->handler = new CreateMonthBillCommandHandler($this->db, $this->conf, $this->user, $this->langs);
43
    }
44
45
    /**
46
     * Run the cron job.
47
     *
48
     * @return int <0 if error
49
     */
50
    public function run()
51
    {
52
        dol_syslog('Monthly bill generation : Start');
53
54
        try {
55
            $command = new CreateMonthBillCommand(0, '', '', date('Y'), (date('m') - 1));
56
            $this->handler->handle($command);
57
58
            dol_syslog('Monthly bill generation : OK');
59
            return 0;
60
61
        } catch (Exception $e) {
62
            dol_syslog($e->getMessage(), LOG_ERR);
63
            dol_syslog('Monthly bill generation : NOK');
64
            return -1;
65
        }
66
    }
67
68
}