{"record":{"id":"4b3b1eddb3da17c5","repo":"moodle/moodle","slug":"couldnotmove","errorCode":"couldnotmove","errorMessage":"couldnotmove","messagePattern":"couldnotmove","errorType":"exception","errorClass":"repository_nextcloud\\request_exception","httpStatus":null,"severity":"error","filePath":"public/repository/nextcloud/lib.php","lineNumber":510,"sourceCode":"        // 2. Check whether user has folder for files otherwise create it.\n        $linkmanager->create_storage_folder($this->controlledlinkfoldername, $this->dav);\n\n        $userinfo = $this->client->get_userinfo();\n        $username = $userinfo['username'];\n\n        // Creates a share between the systemaccount and the user.\n        $responsecreateshare = $linkmanager->create_share_user_sysaccount($reference->link, $username, $maywrite);\n\n        $statuscode = $responsecreateshare['statuscode'];\n\n        if ($statuscode == 403) {\n            $shareid = $linkmanager->get_shares_from_path($reference->link, $username);\n        } else if ($statuscode == 100) {\n            $filetarget = $linkmanager->get_share_information_from_shareid($responsecreateshare['shareid'], $username);\n            $copyresult = $linkmanager->transfer_file_to_path($filetarget, $this->controlledlinkfoldername,\n                'move', $this->dav);\n            if (!($copyresult == 201 || $copyresult == 412)) {\n                throw new \\repository_nextcloud\\request_exception(array('instance' => $repositoryname,\n                    'errormessage' => get_string('couldnotmove', 'repository_nextcloud', $this->controlledlinkfoldername)));\n            }\n            $shareid = $responsecreateshare['shareid'];\n        } else if ($statuscode == 997) {\n            throw new \\repository_nextcloud\\request_exception(array('instance' => $repositoryname,\n                'errormessage' => get_string('notauthorized', 'repository_nextcloud')));\n        } else {\n            $details = get_string('filenotaccessed', 'repository_nextcloud');\n            throw new \\repository_nextcloud\\request_exception(array('instance' => $repositoryname, 'errormessage' => $details));\n        }\n        $filetarget = $linkmanager->get_share_information_from_shareid((int)$shareid, $username);\n\n        // Obtain the file from Nextcloud using a Bearer token authenticated connection because we cannot perform a redirect here.\n        // The reason is that Nextcloud uses samesite cookie validation, i.e. a redirected request would not be authenticated.\n        // (Also the browser might use the session of a Nextcloud user that is different from the one that is known to Moodle.)\n        $filename = basename($filetarget);\n        $tmppath = make_request_directory() . '/' . $filename;\n        $this->dav->open();","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/repository/nextcloud/lib.php#L492-L528","documentation":"repository_nextcloud's get_file() flow throws this request_exception when, after creating a share between the system account and the user (OCS status 100), the WebDAV MOVE of the shared file into the controlled link folder returns a status other than 201 (created) or 412 (precondition failed, meaning target already exists). The language string 'couldnotmove' is interpolated with the configured controlled-link folder name. It signals that the file could not be relocated into the Moodle-managed Nextcloud folder.","triggerScenarios":"OCS share creation succeeded (statuscode 100), but linkmanager->transfer_file_to_path(...,'move',$this->dav) returns e.g. 403/404/409/502 instead of 201 or 412: the WebDAV endpoint is wrong, the destination folder was deleted, quota is exhausted, or the WebDAV client lacks permission to move.","commonSituations":"Admin configured the issuer's webdav endpoint incorrectly; the controlled link folder (default ' Controlled Link Folder'-type name) was manually deleted in Nextcloud; system-account OAuth token lost write scope; Nextcloud version changed OCS/WebDAV behavior; disk quota exceeded for the system account.","solutions":["Verify the Nextcloud issuer's webdav endpoint URL in Site admin > OAuth 2 services points to the correct remote.php/webdav path","Log in to Nextcloud as the system account and confirm the controlled link folder exists and is writable, or delete/recreate it so create_storage_folder() rebuilds it","Check the system OAuth client scopes include write access (PROPFIND/MOVE) and that the system account is not over quota","Enable WebDAV/debug logging to capture the actual HTTP status from transfer_file_to_path and address that specific failure","If the folder exists but is stale, run a cron/repository cache purge so the repository re-inits the WebDAV session"],"exampleFix":"// before (diagnostic wrap around repository internals is not possible, but pre-check the folder)\n$copyresult = $linkmanager->transfer_file_to_path($filetarget, $this->controlledlinkfoldername, 'move', $this->dav);\n// after: ensure folder exists and refresh DAV session before moving\n$linkmanager->create_storage_folder($this->controlledlinkfoldername, $this->dav);\n$this->initiate_webdavclient();\n$copyresult = $linkmanager->transfer_file_to_path($filetarget, $this->controlledlinkfoldername, 'move', $this->dav);","handlingStrategy":"try-catch","validationCode":"// before calling get_file, verify the controlled folder exists via the repository\n// (no public pre-check API; do a lightweight PROPFIND through admin tools)\n// curl -u <systemuser>:<token> -X PROPFIND https://cloud.example.com/remote.php/webdav/<ControlledLinkFolder>/","typeGuard":null,"tryCatchPattern":"try {\n    $repo->get_file($reference, $filename, $contenthash, $pathname, $options);\n} catch (\\repository_nextcloud\\request_exception $e) {\n    // inspect $e->errorInfo['errormessage']; check DAV endpoint + folder, then retry once\n    debugging($e->getMessage());\n    throw $e;\n}","preventionTips":["Never delete or rename the controlled link folder in Nextcloud manually","Keep the OAuth2 issuer's webdav endpoint URL correct after Nextcloud upgrades","Monitor system-account quota and permission changes","Pin compatible Nextcloud/Moodle repository plugin versions"],"tags":["webdav","nextcloud","moodle","file-move"],"backgroundTag":"http-error-response","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}