1
|
|
|
<?php namespace Comodojo\Installer\Actions; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Exception\InstallerException; |
4
|
|
|
use \Exception; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* |
8
|
|
|
* |
9
|
|
|
* @package Comodojo Framework |
10
|
|
|
* @author Marco Giovinazzi <[email protected]> |
11
|
|
|
* @author Marco Castiello <[email protected]> |
12
|
|
|
* @license GPL-3.0+ |
13
|
|
|
* |
14
|
|
|
* LICENSE: |
15
|
|
|
* |
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
19
|
|
|
* License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU Affero General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
class ExtenderTask extends AbstractAction { |
31
|
|
|
|
32
|
|
View Code Duplication |
public function install($package_name, $package_extra) { |
33
|
|
|
|
34
|
|
|
$io = $this->getIO(); |
35
|
|
|
|
36
|
|
|
$io->write("<info>>>> Installing (extender) tasks from package ".$package_name."</info>"); |
37
|
|
|
|
38
|
|
|
$this->processTask($io, 'install', $package_name, $package_extra); |
39
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function update($package_name, $initial_extra, $target_extra) { |
43
|
|
|
|
44
|
|
|
$io = $this->getIO(); |
45
|
|
|
|
46
|
|
|
$io->write("<info>>>> Updating (extender) tasks from package ".$package_name."</info>"); |
47
|
|
|
|
48
|
|
|
// $this->processTask($io, 'update', $package_name, $package_extra); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$this->processTask($io, 'uninstall', $package_name, $initial_extra); |
51
|
|
|
|
52
|
|
|
$this->processTask($io, 'install', $package_name, $target_extra); |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function uninstall($package_name, $package_extra) { |
57
|
|
|
|
58
|
|
|
$io = $this->getIO(); |
59
|
|
|
|
60
|
|
|
$io->write("<info>>>> Removing (extender) tasks from package ".$package_name."</info>"); |
61
|
|
|
|
62
|
|
|
$this->processTask($io, 'uninstall', $package_name, $package_extra); |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
private function processTask($io, $action, $package_name, $package_extra) { |
67
|
|
|
|
68
|
|
|
foreach ($package_extra as $name => $task) { |
69
|
|
|
|
70
|
|
|
try { |
71
|
|
|
|
72
|
|
|
if ( !self::validateTask($task) ) throw new InstallerException('Skipping invalid task in '.$package_name); |
73
|
|
|
|
74
|
|
|
$name = $task['name']; |
75
|
|
|
|
76
|
|
|
$class = $task['class']; |
77
|
|
|
|
78
|
|
|
$description = empty($task['description']) ? null : $task['description']; |
79
|
|
|
|
80
|
|
|
switch ($action) { |
81
|
|
|
|
82
|
|
|
case 'install': |
83
|
|
|
|
84
|
|
|
$this->getPackageInstaller()->tasks()->add($package_name, $name, $class, $description); |
85
|
|
|
|
86
|
|
|
$io->write(" <info>+</info> enabled task ".$name); |
87
|
|
|
|
88
|
|
|
break; |
89
|
|
|
|
90
|
|
|
case 'uninstall': |
91
|
|
|
|
92
|
|
|
$id = $this->getPackageInstaller()->tasks()->byName($name)->getId(); |
93
|
|
|
|
94
|
|
|
$this->getPackageInstaller()->tasks()->delete($id); |
95
|
|
|
|
96
|
|
|
$io->write(" <comment>-</comment> disabled task ".$name." (id ".$id.")"); |
97
|
|
|
|
98
|
|
|
break; |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
} catch (Exception $e) { |
103
|
|
|
|
104
|
|
|
$io->write('<error>Error processing task: '.$e->getMessage().'</error>'); |
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
private static function validateTask($task) { |
113
|
|
|
|
114
|
|
|
return !( empty($task["name"]) || empty($task["class"]) ); |
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.