Passed
Push — develop ( 502e4e...15fa01 )
by Портнов
04:01
created

ActionVoicemailEnd::execute()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 35
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 35
rs 9.2088
cc 5
nc 8
nop 2
1
<?php
2
3
4
namespace MikoPBX\Core\Workers\Libs\WorkerCallEvents;
5
6
7
use MikoPBX\Common\Models\CallDetailRecordsTmp;
8
use MikoPBX\Core\System\Processes;
9
use MikoPBX\Core\System\Storage;
10
use MikoPBX\Core\System\Util;
11
use MikoPBX\Core\Workers\WorkerCallEvents;
12
13
class ActionVoicemailEnd {
14
15
    public static function execute(WorkerCallEvents $worker, $data):void
16
    {
17
        $filename = Util::trimExtensionForFile($data['vm-recordingfile']) . '.wav';
18
        $recordingFile = '';
19
        if (file_exists($filename)) {
20
            // Переопределим путь к файлу записи разговора. Для конферецнии файл один.
21
            $monitor_dir = Storage::getMonitorDir();
22
            $sub_dir = date('Y/m/d/H/');
23
            $dirName = "{$monitor_dir}/{$sub_dir}";
24
            if(Util::mwMkdir($dirName)){
25
                $recordingFile = "{$dirName}{$data['UNIQUEID']}_".basename($filename);
26
                $cpPath = Util::which('cp');
27
                Processes::mwExec("{$cpPath} {$filename} {$recordingFile}");
28
                if(!file_exists($recordingFile)){
29
                    $recordingFile = '';
30
                }else{
31
                    $recordingFile = Util::trimExtensionForFile($recordingFile) . '.mp3';
32
                }
33
            }
34
        }
35
        $filter         = [
36
            'linkedid=:linkedid: AND UNIQUEID = :UNIQUEID:',
37
            'bind' => [
38
                'linkedid' => $data['linkedid'],
39
                'UNIQUEID' => $data['UNIQUEID'],
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('transfer', 0);
47
            $row->writeAttribute('endtime',       $data['end']);
48
            $row->writeAttribute('recordingfile', $recordingFile);
49
            $row->update();
50
        }
51
    }
52
53
}