Passed
Push — develop ( d5179e...bede24 )
by Портнов
05:56 queued 11s
created

ActionQueueEnd::execute()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 20
rs 9.8333
cc 4
nc 5
nop 2
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2021 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
namespace MikoPBX\Core\Workers\Libs\WorkerCallEvents;
21
22
23
use MikoPBX\Common\Models\CallDetailRecordsTmp;
24
use MikoPBX\Core\System\Util;
25
use MikoPBX\Core\Workers\WorkerCallEvents;
26
27
class ActionQueueEnd
28
{
29
    /**
30
     * Завершение работы очереди.
31
     * @param $worker
32
     * @param $data
33
     */
34
    public static function execute(WorkerCallEvents $worker, $data):void
35
    {
36
        $filter = [
37
            "UNIQUEID=:UNIQUEID:",
38
            'bind' => [
39
                'UNIQUEID' => $data['id'],
40
            ],
41
        ];
42
        /** @var CallDetailRecordsTmp $m_data */
43
        /** @var CallDetailRecordsTmp $row */
44
        $m_data = CallDetailRecordsTmp::find($filter);
45
        foreach ($m_data as $row) {
46
            $row->writeAttribute('endtime', $data['end']);
47
            $row->writeAttribute('is_app', 1);
48
            if ($data['dialstatus'] !== '') {
49
                $row->writeAttribute('dialstatus', $data['dialstatus']);
50
            }
51
            $res = $row->save();
52
            if ( ! $res) {
53
                Util::sysLogMsg('Action_queue_end', implode(' ', $row->getMessages()), LOG_DEBUG);
54
            }
55
        }
56
    }
57
58
}