1 | <?php |
||
27 | class AppManager { |
||
28 | |||
29 | /** |
||
30 | * @var OccRunner $occRunner |
||
31 | */ |
||
32 | protected $occRunner; |
||
33 | |||
34 | /** |
||
35 | * @var array $disabledApps |
||
36 | */ |
||
37 | protected $disabledApps = []; |
||
38 | |||
39 | /** |
||
40 | * |
||
41 | * @param OccRunner $occRunner |
||
42 | */ |
||
43 | 5 | public function __construct(OccRunner $occRunner){ |
|
46 | |||
47 | 1 | public function disableApp($appId){ |
|
48 | try{ |
||
49 | 1 | $this->occRunner->run('app:disable', ['app-id' => $appId]); |
|
50 | } catch (\Exception $e){ |
||
51 | return false; |
||
52 | } |
||
53 | 1 | return true; |
|
54 | } |
||
55 | |||
56 | 1 | public function enableApp($appId){ |
|
57 | try{ |
||
58 | 1 | $this->occRunner->run('app:enable', ['app-id' => $appId]); |
|
59 | 1 | array_unshift($this->disabledApps, $appId); |
|
60 | } catch (\Exception $e){ |
||
61 | return false; |
||
62 | } |
||
63 | 1 | return true; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * @param OutputInterface|null $output |
||
68 | */ |
||
69 | public function disableNotShippedApps(OutputInterface $output = null){ |
||
70 | $notShippedApps = $this->occRunner->runJson('app:list', ['--shipped' => 'false']); |
||
71 | $appsToDisable = array_keys($notShippedApps['enabled']); |
||
72 | foreach ($appsToDisable as $appId){ |
||
73 | $result = $this->disableApp($appId); |
||
74 | $status = $result ? '<info>success</info>' : '<error>failed</error>'; |
||
75 | if ($result){ |
||
76 | $this->disabledApps[] = $appId; |
||
77 | } |
||
78 | if (!is_null($output)){ |
||
79 | $message = sprintf('Disable app %s: [%s]', $appId, $status); |
||
80 | $output->writeln($message); |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | |||
85 | public function reenableNotShippedApps(OutputInterface $output = null){ |
||
86 | foreach ($this->disabledApps as $appId){ |
||
87 | $result = $this->enableApp($appId); |
||
88 | $status = $result ? '<info>success</info>' : '<error>failed</error>'; |
||
89 | if (!is_null($output)){ |
||
90 | $message = sprintf('Enable app %s: [%s]', $appId, $status); |
||
91 | $output->writeln($message); |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | |||
96 | public function getAllApps(){ |
||
101 | |||
102 | public function getNotShippedApps(){ |
||
107 | |||
108 | 2 | public function getShippedApps(){ |
|
113 | |||
114 | 1 | public function getAppPath($appId){ |
|
115 | try { |
||
116 | 1 | $response = $this->occRunner->run('app:getpath', ['app-id' => $appId]); |
|
117 | } catch (\Exception $e) { |
||
122 | |||
123 | } |
||
124 |