Passed
Push — master ( a93dc6...cd5951 )
by Nils
04:25
created

doLog()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 17
c 1
b 0
f 0
nc 3
nop 4
dl 0
loc 30
rs 9.7
1
<?php
2
/**
3
 * Teampass - a collaborative passwords manager.
4
 * ---
5
 * This library is distributed in the hope that it will be useful,
6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
 * ---
9
 *
10
 * @project   Teampass
11
 * @version   3.0.0.22
12
 * @file      background_tasks___functions.php
13
 * ---
14
 *
15
 * @author    Nils Laumaillé ([email protected])
16
 *
17
 * @copyright 2009-2023 Teampass.net
18
 *
19
 * @license   https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0
20
 * ---
21
 *
22
 * @see       https://www.teampass.net
23
 */
24
25
// Load config
26
require_once __DIR__.'/../includes/config/tp.config.php';
27
28
// Do checks
29
require_once __DIR__.'/../includes/config/include.php';
30
require_once __DIR__.'/../includes/config/settings.php';
31
header('Content-type: text/html; charset=utf-8');
32
header('Cache-Control: no-cache, must-revalidate');
33
34
35
/**
36
 * Permits to log task status
37
 *
38
 * @param string $status
39
 * @param string $job
40
 * @param integer $enable_tasks_log
41
 * @param integer|null $id
42
 * @return integer
43
 */
44
function doLog(string $status, string $job, int $enable_tasks_log = 0, int $id = null): int
45
{
46
    // is log enabled?
47
    if ((int) $enable_tasks_log === 1) {
48
        // is log start?
49
        if (is_null($id) === true) {
50
            DB::insert(
51
                prefixTable('processes_logs'),
52
                array(
53
                    'created_at' => time(),
54
                    'job' => $job,
55
                    'status' => $status,
56
                )
57
            );
58
            return DB::insertId();
59
        }
60
        
61
        // Case is an update
62
        DB::update(
63
            prefixTable('processes_logs'),
64
            array(
65
                'status' => $status,
66
                'finished_at' => time(),
67
            ),
68
            'increment_id = %i',
69
            $id
70
        );
71
    }
72
    
73
    return -1;
74
}