Passed
Push — develop ( 9d129a...447c71 )
by Nikolay
05:05 queued 13s
created

UpdateConfigsUpToVer2021124::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 1
b 0
f 0
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\Core\System\Upgrade\UpgradeSystemConfigInterface;
23
use MikoPBX\Core\System\Util;
24
use Phalcon\Di\Injectable;
25
use MikoPBX\Core\System\MikoPBXConfig;
26
use Phalcon\Config as ConfigAlias;
27
28
class UpdateConfigsUpToVer2021124 extends Injectable implements UpgradeSystemConfigInterface
29
{
30
  	public const PBX_VERSION = '2021.1.24';
31
32
	private ConfigAlias $config;
33
    private MikoPBXConfig $mikoPBXConfig;
34
    private bool $isLiveCD;
35
36
	/**
37
     * Class constructor.
38
     */
39
    public function __construct()
40
    {
41
        $this->config = $this->getDI()->getShared('config');
42
        $this->mikoPBXConfig = new MikoPBXConfig();
43
        $this->isLiveCD      = file_exists('/offload/livecd');
44
    }
45
46
	/**
47
     * Main function
48
     */
49
    public function processUpdate():void
50
    {
51
  		if ($this->isLiveCD) {
52
            return;
53
        }
54
        $this->deleteOldCacheFolders();
55
    }
56
57
    /**
58
     * Deletes all not actual cache folders
59
     */
60
    private function deleteOldCacheFolders()
61
    {
62
        $oldCacheFolders = [
63
            '/storage/usbdisk1/mikopbx/tmp/models_cache',
64
            '/storage/usbdisk1/mikopbx/tmp/managed_cache',
65
            '/storage/usbdisk1/mikopbx/tmp/www_cache',
66
        ];
67
        foreach ($oldCacheFolders as $cacheDir){
68
            if (is_dir($cacheDir)){
69
                Util::rRmDir($cacheDir);
70
            }
71
        }
72
    }
73
}