Skip to content

Commit c7c7584

Browse files
authored
Merge pull request #565 from catalyst/swift-client-test-connection-improvement
Swift client test connection impovement.
2 parents 40f466b + 99f379e commit c7c7584

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

classes/local/store/azure/client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public function test_permissions($testdelete) {
241241
// Write could have failed.
242242
if ($errorcode !== 'BlobNotFound') {
243243
$details = $this->get_exception_details($e);
244-
$permissions->messages[get_string('settings:readfailure', 'tool_objectfs') . $details] = 'notifyproblem';
244+
$permissions->messages[get_string('settings:permissionreadfailure', 'tool_objectfs') . $details] = 'notifyproblem';
245245
$permissions->success = false;
246246
}
247247
}

classes/local/store/s3/client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function test_permissions($testdelete) {
312312
// Write could have failed.
313313
if ($errorcode !== 'NoSuchKey') {
314314
$details = $this->get_exception_details($e);
315-
$permissions->messages[get_string('settings:readfailure', 'tool_objectfs') . $details] = 'notifyproblem';
315+
$permissions->messages[get_string('settings:permissionreadfailure', 'tool_objectfs') . $details] = 'notifyproblem';
316316
$permissions->success = false;
317317
}
318318
}

classes/local/store/swift/client.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,22 @@ public function test_connection() {
203203
}
204204

205205
try {
206-
$container->createObject(['name' => 'connection_check_file', 'content' => 'connection_check_file']);
206+
$container->getObject('connection_check_file')->download();
207207
} catch (\OpenStack\Common\Error\BadResponseError $e) {
208-
$connection->success = false;
209-
$connection->details = $this->get_exception_details($e);
210-
} catch (\Exception $e) {
211-
$connection->success = false;
208+
if ($e->getResponse()->getStatusCode() == 404) {
209+
try {
210+
$container->createObject(['name' => 'connection_check_file', 'content' => 'connection_check_file']);
211+
} catch (\OpenStack\Common\Error\BadResponseError $e) {
212+
$connection->success = false;
213+
$connection->details = $this->get_exception_details($e);
214+
} catch (\Exception $e) {
215+
$connection->success = false;
216+
}
217+
} else {
218+
$details = $this->get_exception_details($e);
219+
$connection->messages[get_string('settings:connectionreadfailure', 'tool_objectfs') . $details] = 'notifyproblem';
220+
$connection->success = false;
221+
}
212222
}
213223

214224
return $connection;
@@ -233,7 +243,7 @@ public function test_permissions($testdelete) {
233243
$result = $container->getObject('permissions_check_file')->download();
234244
} catch (\OpenStack\Common\Error\BadResponseError $e) {
235245
$details = $this->get_exception_details($e);
236-
$permissions->messages[get_string('settings:readfailure', 'tool_objectfs') . $details] = 'notifyproblem';
246+
$permissions->messages[get_string('settings:permissionreadfailure', 'tool_objectfs') . $details] = 'notifyproblem';
237247
$permissions->success = false;
238248

239249
}

lang/en/tool_objectfs.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@
173173
$string['settings:minimumage_help'] = 'Minimum age that a object must exist on the local filedir before it will be considered for transfer.';
174174
$string['settings:deleteexternal'] = 'Delete external objects';
175175
$string['settings:deleteexternal_help'] = 'Delete external objects when the file is deleted in Moodle. This is not recommended if you intend to share one object store between multiple environments, however this is a requirement for GDPR compliance.
176-
<br/>Delete external file on orphan clean-up - This will delete the external file when the delete orphaned metadata task task runs.
177-
<br/>Delete completely - will tell the external storage to delete the file immediately - (use with caution! - if the same file is being uploaded while being deleted issues could occur.)';
176+
<br/>Delete external file on orphan clean-up - This will delete the external file when the delete orphaned metadata task runs.
177+
<br/>Delete completely - will tell the external storage to delete the file immediately - (use with caution! - if the same file is being uploaded while being deleted, issues could occur.)';
178178
$string['settings:deletelocal'] = 'Delete local objects';
179179
$string['settings:deletelocal_help'] = 'Delete local objects once they are in external object storage after the consistency delay.';
180180
$string['settings:consistencydelay'] = 'Consistency delay';
@@ -249,14 +249,15 @@
249249
$string['presignedurl_testing:checkclientsettings'] = 'Check client settings at ';
250250
$string['presignedurl_testing:checkfssettings'] = 'Check filesystem settings at ';
251251

252-
$string['settings:connectionsuccess'] = 'Could establish connection to the external object storage.';
253-
$string['settings:connectionfailure'] = 'Could not establish connection to the external object storage. {$a}';
254-
$string['settings:writefailure'] = 'Could not write object to the external object storage. ';
255-
$string['settings:readfailure'] = 'Could not read object from the external object storage. ';
256-
$string['settings:deletesuccess'] = 'Could delete object from the external object storage - It is not recommended for the user to have delete permissions. ';
257-
$string['settings:deleteerror'] = 'Could not delete object from the external object storage. ';
252+
$string['settings:connectionsuccess'] = 'Could establish connection to object storage. ';
253+
$string['settings:connectionfailure'] = 'Could not establish connection to object storage. {$a}';
254+
$string['settings:writefailure'] = 'Could not write permissions check file from object storage. ';
255+
$string['settings:connectionreadfailure'] = 'Could not read connection check file from object storage. ';
256+
$string['settings:permissionreadfailure'] = 'Could not read permissions check file from object storage. ';
257+
$string['settings:deletesuccess'] = 'Could delete file from object storage - It is not recommended for the user to have delete permissions. ';
258+
$string['settings:deleteerror'] = 'Could not delete permissions check file from object storage. ';
258259
$string['settings:permissioncheckpassed'] = 'Permissions check passed.';
259-
$string['settings:handlernotset'] = '$CFG->alternative_file_system_class is not set, the file system will not be able to read from the external object storage. Background tasks can still function.';
260+
$string['settings:handlernotset'] = '$CFG->alternative_file_system_class is not set, the file system will not be able to read from object storage. Background tasks can still function.';
260261

261262
$string['settings:testingheader'] = 'Test Settings';
262263
$string['settings:testingdescr'] = 'This setting is mainly for testing purposes and introduces overhead to check the location.';

0 commit comments

Comments
 (0)