Passed
Push — develop ( d617cb...49fd37 )
by Nikolay
05:15 queued 36s
created

DisableModule::main()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 15
rs 9.9
c 1
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2023 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\PBXCoreREST\Lib\Modules;
21
22
use MikoPBX\Common\Providers\PBXConfModulesProvider;
23
use MikoPBX\Modules\PbxExtensionState;
24
use MikoPBX\PBXCoreREST\Lib\PBXApiResult;
25
26
/**
27
 *  Class DisableModule
28
 *  Disables extension module.
29
 *
30
 * @package MikoPBX\PBXCoreREST\Lib\Modules
31
 */
32
class DisableModule extends \Phalcon\Di\Injectable
33
{
34
    /**
35
     * Disables extension module.
36
     *
37
     * @param string $moduleUniqueID
38
     * @param string $reason Store the reason why the module was disabled as a flag
39
     * @param string $reasonText Store the reason why the module was disabled in text mode, some logs
40
     * @return PBXApiResult An object containing the result of the API call.
41
     */
42
    public static function main(string $moduleUniqueID, string $reason='', string $reasonText=''): PBXApiResult
43
    {
44
        $res = new PBXApiResult();
45
        $res->processor = __METHOD__;
46
        $moduleStateProcessor = new PbxExtensionState($moduleUniqueID);
47
        if ($moduleStateProcessor->disableModule($reason, $reasonText) === false) {
48
            $res->success = false;
49
            $res->messages = $moduleStateProcessor->getMessages();
50
        } else {
51
            PBXConfModulesProvider::recreateModulesProvider();
52
            $res->data = $moduleStateProcessor->getMessages();
53
            $res->success = true;
54
        }
55
56
        return $res;
57
    }
58
}