diff --git a/repository/nextcloud/lib.php b/repository/nextcloud/lib.php index 5e4dce0418d..2fab1280e62 100644 --- a/repository/nextcloud/lib.php +++ b/repository/nextcloud/lib.php @@ -500,6 +500,21 @@ class repository_nextcloud extends repository { $statuscode = $responsecreateshare['statuscode']; +// In the file "repository/nextcloud/lib.php > public function send_file()", Nextcloud 25.0.3 returns a statuscode +// of 100 when the share was already created before calling create_share. Moodle expects a statuscode of 403. + +// I have found a way to fix the 100 statuscode of a create_share response when the share was already created before +// the create_share call. I use this workaround because the "filetarget" path contains the "controlledlinkfoldername" +// (by default, Moodlefiles folder) when the share was already created before calling create_share. + +// While this solution provides a quick fix for the error, it is possible that Nextcloud may change the response of the +// destination path in future revisions. The correct solution will be to find a way to check if a share has already been +// created before calling create_share using another Nextcloud call. + + if (strpos($responsecreateshare['filetarget'], '/' . $this->controlledlinkfoldername) === 0) { + $statuscode = 403; + } + if ($statuscode == 403) { $shareid = $linkmanager->get_shares_from_path($reference->link, $username); } else if ($statuscode == 100) {