Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 80 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
tao_install_services_InstallService | |
0.00% |
0 / 80 |
|
0.00% |
0 / 4 |
1980 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 40 |
|
0.00% |
0 / 1 |
42 | |||
onError | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
checkData | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
1190 |
1 | <?php |
2 | |
3 | /* |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
19 | * (under the project TAO & TAO2); |
20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
21 | * (under the project TAO-TRANSFER); |
22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
24 | * |
25 | */ |
26 | |
27 | /** |
28 | * A Service implementation aiming at installing the software. |
29 | * |
30 | * Please refer to tao/install/api.php for more information about how to call this service. |
31 | * |
32 | * @access public |
33 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
34 | * @package tao |
35 | |
36 | */ |
37 | class tao_install_services_InstallService extends tao_install_services_Service |
38 | { |
39 | /** |
40 | * Creates a new instance of the service. |
41 | * @param tao_install_services_Data $data The input data to be handled by the service. |
42 | * @throws InvalidArgumentException If the input data structured is malformed or is missing data. |
43 | */ |
44 | public function __construct(tao_install_services_Data $data) |
45 | { |
46 | parent::__construct($data); |
47 | } |
48 | |
49 | /** |
50 | * Executes the main logic of the service. |
51 | * @return tao_install_services_Data The result of the service execution. |
52 | */ |
53 | public function execute() |
54 | { |
55 | $content = json_decode($this->getData()->getContent(), true); |
56 | |
57 | //instantiate the installator |
58 | try { |
59 | set_error_handler([get_class($this), 'onError']); |
60 | |
61 | $container = new \Pimple\Container( |
62 | [ |
63 | \oat\oatbox\log\LoggerService::SERVICE_ID => new \oat\oatbox\log\LoggerService(), |
64 | tao_install_Installator::CONTAINER_INDEX => [ |
65 | 'root_path' => TAO_INSTALL_PATH, |
66 | 'install_path' => dirname(__FILE__) . '/../../install', |
67 | ] |
68 | ] |
69 | ); |
70 | |
71 | $installer = new tao_install_Installator($container); |
72 | |
73 | // For the moment, we force English as default language. |
74 | $content['value']['module_lang'] = 'en-US'; |
75 | // fallback until ui is ready |
76 | if (!isset($content['value']['file_path'])) { |
77 | $content['value']['file_path'] = TAO_INSTALL_PATH . 'data' . DIRECTORY_SEPARATOR; |
78 | } |
79 | $installer->install($content['value']); |
80 | |
81 | $installationLog = $installer->getLog(); |
82 | $message = (isset($installationLog['e']) || isset($installationLog['f']) || isset($installationLog['w'])) ? |
83 | 'Installation complete (warnings occurred)' : 'Installation successful.'; |
84 | |
85 | $report = [ |
86 | 'type' => 'InstallReport', |
87 | 'value' => [ |
88 | 'status' => 'valid', |
89 | 'message' => $message, |
90 | 'log' => $installationLog |
91 | ] |
92 | ]; |
93 | $this->setResult(new tao_install_services_Data(json_encode($report))); |
94 | |
95 | restore_error_handler(); |
96 | } catch (Exception $e) { |
97 | $report = [ |
98 | 'type' => 'InstallReport', |
99 | 'value' => [ |
100 | 'status' => 'invalid', |
101 | 'message' => $e->getMessage() . ' in ' . $e->getFile() . ' at line ' . $e->getLine(), |
102 | 'log' => $installer->getLog() |
103 | ] |
104 | ]; |
105 | $this->setResult(new tao_install_services_Data(json_encode($report))); |
106 | |
107 | restore_error_handler(); |
108 | } |
109 | } |
110 | |
111 | public static function onError($errno, $errstr, $errfile, $errline) |
112 | { |
113 | common_Logger::w($errfile . ':' . $errline . ' - ' . $errstr); |
114 | switch ($errno) { |
115 | case E_ERROR: |
116 | throw new tao_install_utils_Exception($errfile . ':' . $errline . ' - ' . $errstr); |
117 | break; |
118 | default: |
119 | return true; |
120 | } |
121 | } |
122 | |
123 | protected function checkData() |
124 | { |
125 | $content = json_decode($this->getData()->getContent(), true); |
126 | if (!isset($content['type']) || empty($content['type']) || $content['type'] != 'Install') { |
127 | throw new InvalidArgumentException("Unexpected type: 'type' must be equal to 'Install'."); |
128 | } elseif (!isset($content['value']) || empty($content['value'])) { |
129 | throw new InvalidArgumentException("Missing data: 'value' must be provided."); |
130 | } elseif (!isset($content['value']['db_host']) || empty($content['value']['db_host'])) { |
131 | throw new InvalidArgumentException("Missing data: 'db_host' must be provided."); |
132 | } elseif (!isset($content['value']['db_user']) || empty($content['value']['db_user'])) { |
133 | throw new InvalidArgumentException("Missing data: 'db_user' must be provided."); |
134 | } elseif (!isset($content['value']['db_host']) || empty($content['value']['db_host'])) { |
135 | throw new InvalidArgumentException("Missing data: 'db_host' must be provided."); |
136 | } elseif (!isset($content['value']['db_pass'])) { |
137 | throw new InvalidArgumentException("Missing data: 'db_pass' must be provided."); |
138 | } elseif (!isset($content['value']['db_driver']) || empty($content['value']['db_driver'])) { |
139 | throw new InvalidArgumentException("Missing data: 'db_driver' must be provided."); |
140 | } elseif (!isset($content['value']['db_name']) || empty($content['value']['db_name'])) { |
141 | throw new InvalidArgumentException("Missing data: 'db_name' must be provided."); |
142 | } elseif (!isset($content['value']['module_namespace']) || empty($content['value']['module_namespace'])) { |
143 | throw new InvalidArgumentException("Missing data: 'module_namespace' must be provided."); |
144 | } elseif (!isset($content['value']['module_url']) || empty($content['value']['module_url'])) { |
145 | throw new InvalidArgumentException("Missing data: 'module_url' must be provided."); |
146 | } elseif (!isset($content['value']['module_lang']) || empty($content['value']['module_lang'])) { |
147 | throw new InvalidArgumentException("Missing data: 'module_lang' must be provided."); |
148 | } elseif (!isset($content['value']['module_mode']) || empty($content['value']['module_mode'])) { |
149 | throw new InvalidArgumentException("Missing data: 'module_mode' must be provided."); |
150 | } elseif ( |
151 | !isset($content['value']['import_local']) |
152 | || ($content['value']['import_local'] !== false && $content['value']['import_local'] !== true) |
153 | ) { |
154 | throw new InvalidArgumentException("Missing data: 'import_local' must be provided."); |
155 | } elseif (!isset($content['value']['user_login']) || empty($content['value']['user_login'])) { |
156 | throw new InvalidArgumentException("Missing data: 'user_login' must be provided."); |
157 | } elseif (!isset($content['value']['user_pass1']) || empty($content['value']['user_pass1'])) { |
158 | throw new InvalidArgumentException("Missing data: 'user_pass1' must be provided."); |
159 | } elseif (!isset($content['value']['instance_name']) || empty($content['value']['instance_name'])) { |
160 | throw new InvalidArgumentException("Missing data: 'instance_name' must provided."); |
161 | } |
162 | } |
163 | } |