Passed
Push — develop ( cfa396...74c300 )
by Nikolay
06:43 queued 11s
created

UpdateConfigsUpToVer62110   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 21
c 1
b 0
f 0
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B processUpdate() 0 32 9
1
<?php
2
/*
3
 * Copyright (C) MIKO LLC - All Rights Reserved
4
 * Unauthorized copying of this file, via any medium is strictly prohibited
5
 * Proprietary and confidential
6
 * Written by Nikolay Beketov, 10 2020
7
 *
8
 */
9
10
namespace MikoPBX\Core\System\Upgrade\Releases;
11
12
use MikoPBX\Common\Models\Codecs;
13
use MikoPBX\Common\Models\IvrMenu;
14
use MikoPBX\Common\Models\PbxExtensionModules;
15
use MikoPBX\Core\System\Upgrade\UpgradeSystemConfigInterface;
16
use Phalcon\Di\Injectable;
17
18
/**
19
 * Upgrade from * to 6.2.110
20
 *
21
 * @package MikoPBX\Core\System\Upgrade\Releases
22
 */
23
class UpdateConfigsUpToVer62110 extends Injectable implements UpgradeSystemConfigInterface
24
{
25
  	public const PBX_VERSION = '6.2.110';
26
27
    public function processUpdate():void
28
    {
29
        /** @var \MikoPBX\Common\Models\Codecs $codec_g722 */
30
        $codec_g722 = Codecs::findFirst('name="g722"');
31
        if ($codec_g722 === null) {
32
            $codec_g722              = new Codecs();
33
            $codec_g722->name        = 'g722';
34
            $codec_g722->type        = 'audio';
35
            $codec_g722->description = 'G.722';
36
            $codec_g722->save();
37
        }
38
39
        /** @var \MikoPBX\Common\Models\IvrMenu $ivrs */
40
        /** @var \MikoPBX\Common\Models\IvrMenu $ivr */
41
        $ivrs = IvrMenu::find();
42
        foreach ($ivrs as $ivr) {
43
            if (empty($ivr->number_of_repeat)) {
44
                $ivr->number_of_repeat = 5;
45
                $ivr->save();
46
            }
47
            if (empty($ivr->timeout)) {
48
                $ivr->timeout = 7;
49
                $ivr->save();
50
            }
51
        }
52
53
        // Чистим мусор.
54
        /** @var \MikoPBX\Common\Models\PbxExtensionModules $modules */
55
        $modules = PbxExtensionModules::find();
56
        foreach ($modules as $module) {
57
            if ($module->version === '1.0' && empty($module->support_email) && 'МИКО' === $module->developer) {
58
                $module->delete();
59
            }
60
        }
61
    }
62
}