|
27 | 27 | namespace tool_opencast\local;
|
28 | 28 |
|
29 | 29 | use local_chunkupload\local\chunkupload_file;
|
| 30 | +use Matrix\Exception; |
30 | 31 | use tool_opencast\empty_configuration_exception;
|
31 | 32 |
|
32 | 33 | defined('MOODLE_INTERNAL') || die;
|
@@ -130,54 +131,81 @@ public static function get_courses_series_title($courseid) {
|
130 | 131 | /**
|
131 | 132 | * Returns the real api or test api depending on the environment.
|
132 | 133 | *
|
133 |
| - * @param null $instanceid Opencast instance id |
| 134 | + * @param int|null $instanceid |
| 135 | + * Opencast instance id. |
| 136 | + * |
134 | 137 | * @param array $settings
|
135 | 138 | * @param array $customconfigs
|
| 139 | + * |
136 | 140 | * @return api|api_testable
|
| 141 | + * |
137 | 142 | * @throws \dml_exception
|
138 | 143 | * @throws \moodle_exception
|
139 | 144 | */
|
140 |
| - public static function get_instance($instanceid = null, $settings = array(), $customconfigs = array()) { |
141 |
| - if (defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING && get_config('tool_opencast', 'apiurl') == 'http://testapi:8080') { |
142 |
| - return new api_testable(); |
| 145 | + public static function get_instance($instanceid = null, |
| 146 | + $settings = array(), |
| 147 | + $customconfigs = array()) { |
| 148 | + if (defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING) { |
| 149 | + $defaultocinstance = settings_api::get_default_ocinstance(); |
| 150 | + if ($defaultocinstance === null) { |
| 151 | + throw new \dml_exception('dmlreadexception', null, |
| 152 | + 'No default Opencast instance is defined.'); |
| 153 | + } |
| 154 | + |
| 155 | + $defaultocinstanceapiurl = settings_api::get_apiurl($defaultocinstance->id); |
| 156 | + if ($defaultocinstanceapiurl === false) { |
| 157 | + throw new \dml_exception('dmlreadexception', null, |
| 158 | + 'No api url for the default Opencast instance is defined.'); |
| 159 | + } |
| 160 | + |
| 161 | + if ($defaultocinstanceapiurl === 'http://testapi:8080') { |
| 162 | + return new api_testable(); |
| 163 | + } |
143 | 164 | }
|
| 165 | + |
144 | 166 | return new api($instanceid, $settings, $customconfigs);
|
145 | 167 | }
|
146 | 168 |
|
147 | 169 | /**
|
148 | 170 | * Constructor of the Opencast API.
|
149 |
| - * @param int $instanceid Opencast instance id |
150 |
| - * @param array $settings additional curl settings. |
151 |
| - * @param array $customconfigs custom api config. |
| 171 | + * |
| 172 | + * @param int|null $instanceid |
| 173 | + * Opencast instance id. |
| 174 | + * |
| 175 | + * @param array $settings |
| 176 | + * Additional curl settings. |
| 177 | + * |
| 178 | + * @param array $customconfigs |
| 179 | + * Custom api config. |
| 180 | + * |
152 | 181 | * @throws \dml_exception
|
153 | 182 | * @throws \moodle_exception
|
154 | 183 | */
|
155 |
| - public function __construct($instanceid = null, $settings = array(), $customconfigs = array()) { |
| 184 | + public function __construct($instanceid = null, |
| 185 | + $settings = array(), |
| 186 | + $customconfigs = array()) { |
156 | 187 | // Allow access to local ips.
|
157 | 188 | $settings['ignoresecurity'] = true;
|
158 | 189 | parent::__construct($settings);
|
159 | 190 |
|
160 | 191 | $instanceid = intval($instanceid);
|
161 | 192 |
|
162 |
| - $ocinstances = settings_api::get_ocinstances(); |
163 |
| - $key = array_search(true, array_column($ocinstances, 'isdefault')); |
164 |
| - |
165 | 193 | // If there is no custom configs to set, we go for the stored configs.
|
166 | 194 | if (empty($customconfigs)) {
|
167 |
| - if (!$instanceid || $ocinstances[$key]->id === $instanceid) { |
168 |
| - $this->username = get_config('tool_opencast', 'apiusername'); |
169 |
| - $this->password = get_config('tool_opencast', 'apipassword');; |
170 |
| - $this->timeout = get_config('tool_opencast', 'apitimeout');; |
171 |
| - $this->connecttimeout = get_config('tool_opencast', 'apiconnecttimeout');; |
172 |
| - $this->baseurl = get_config('tool_opencast', 'apiurl'); |
173 |
| - } else { |
174 |
| - $this->username = get_config('tool_opencast', 'apiusername_' . $instanceid); |
175 |
| - $this->password = get_config('tool_opencast', 'apipassword_' . $instanceid); |
176 |
| - $this->timeout = get_config('tool_opencast', 'apitimeout_' . $instanceid); |
177 |
| - $this->connecttimeout = get_config('tool_opencast', 'apiconnecttimeout_' . $instanceid); |
178 |
| - $this->baseurl = get_config('tool_opencast', 'apiurl_' . $instanceid); |
| 195 | + $defaultocinstance = settings_api::get_default_ocinstance(); |
| 196 | + if ($defaultocinstance === null) { |
| 197 | + throw new \dml_exception('dmlreadexception', null, |
| 198 | + 'No default Opencast instance is defined.'); |
179 | 199 | }
|
180 | 200 |
|
| 201 | + $storedconfigocinstanceid = !$instanceid ? $defaultocinstance->id : $instanceid; |
| 202 | + |
| 203 | + $this->username = settings_api::get_apiusername($storedconfigocinstanceid); |
| 204 | + $this->password = settings_api::get_apipassword($storedconfigocinstanceid); |
| 205 | + $this->timeout = settings_api::get_apitimeout($storedconfigocinstanceid); |
| 206 | + $this->connecttimeout = settings_api::get_apiconnecttimeout($storedconfigocinstanceid); |
| 207 | + $this->baseurl = settings_api::get_apiurl($storedconfigocinstanceid); |
| 208 | + |
181 | 209 | if (empty($this->username)) {
|
182 | 210 | throw new empty_configuration_exception('apiusernameempty', 'tool_opencast');
|
183 | 211 | }
|
|
0 commit comments