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

ActionTransferDialAnswer::execute()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 23
rs 9.7666
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 ActionTransferDialAnswer {
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: OR UNIQUEID=:UNIQUEID_CHAN:) AND answer = "" AND endtime = ""',
38
            'bind' => [
39
                'UNIQUEID'      => $data['transfer_UNIQUEID'],
40
                'UNIQUEID_CHAN' => $data['transfer_UNIQUEID'] . '_' . $data['agi_channel'],
41
            ],
42
        ];
43
44
        /** @var CallDetailRecordsTmp $m_data */
45
        /** @var CallDetailRecordsTmp $row */
46
        $m_data = CallDetailRecordsTmp::find($filter);
47
        foreach ($m_data as $row) {
48
            $row->writeAttribute('answer', $data['answer']);
49
            $recFile = $data['recordingfile']??'';
50
            if(!empty($recFile)){
51
                $worker->mixMonitorChannels[$data['agi_channel']] = $recFile;
52
                $row->writeAttribute('recordingfile', $recFile);
53
            }
54
            $res = $row->save();
55
            if ( !$res) {
56
                Util::sysLogMsg('Action_transfer_dial_answer', implode(' ', $row->getMessages()), LOG_DEBUG);
57
            }
58
        }
59
    }
60
}