Passed
Push — develop ( 32a9b8...9e09c9 )
by Nikolay
05:17 queued 13s
created

deleteOutdatedTables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright (C) 2017-2020 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\System\Upgrade\Releases;
21
22
use MikoPBX\Common\Models\Iax;
23
use MikoPBX\Common\Models\Sip;
24
use MikoPBX\Common\Models\SipHosts;
25
use MikoPBX\Common\Providers\MainDatabaseProvider;
26
use MikoPBX\Core\System\Upgrade\UpgradeSystemConfigInterface;
27
use Phalcon\Di;
28
use Phalcon\Di\Injectable;
29
30
class UpdateConfigsUpToVer20213130 extends Injectable implements UpgradeSystemConfigInterface
31
{
32
  	public const PBX_VERSION = '2021.3.130';
33
34
    private bool $isLiveCD;
35
36
	/**
37
     * Class constructor.
38
     */
39
    public function __construct()
40
    {
41
        $this->isLiveCD      = file_exists('/offload/livecd');
42
    }
43
44
	/**
45
     * Main function
46
     */
47
    public function processUpdate():void
48
    {
49
  		if ($this->isLiveCD) {
50
            return;
51
        }
52
53
        $this->deleteOutdatedTables();
54
55
    }
56
57
    /**
58
     * Delete unused data tables from DB
59
     */
60
    public function deleteOutdatedTables()
61
    {
62
        $di = Di::getDefault();
63
        $connectionService = $di->getShared(MainDatabaseProvider::SERVICE_NAME);
64
        $connectionService->dropTable('m_SipCodecs');
65
        $connectionService->dropTable('m_IaxCodecs');
66
        $connectionService->dropTable('m_BackupRules');
67
    }
68
69
    /**
70
     * Deletes all not actual db data
71
     * https://github.com/mikopbx/Core/issues/144
72
     */
73
    private function deleteOrphanDBRecords()
0 ignored issues
show
Unused Code introduced by
The method deleteOrphanDBRecords() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
74
    {
75
        $sipRecords      = Sip::find();
76
        /** @var Sip $sipRecord */
77
        foreach ($sipRecords as $sipRecord){
78
            if ($sipRecord->Providers === null && $sipRecord->Extensions === null){
79
                $sipRecord->delete();
80
            }
81
        }
82
83
        $iaxRecords      = Iax::find();
84
        /** @var Iax $iaxRecord */
85
        foreach ($iaxRecords as $iaxRecord){
86
            if ($iaxRecord->Providers === null){
87
                $iaxRecord->delete();
88
            }
89
        }
90
    }
91
92
}