MDL-34290 Added timeout to googledocs request to download a file
This commit is contained in:
+13
-4
@@ -185,12 +185,21 @@ class google_docs {
|
||||
*
|
||||
* @param string $url url of file
|
||||
* @param string $path path to save file to
|
||||
* @param int $timeout request timeout, default 0 which means no timeout
|
||||
* @return array stucture for repository download_file
|
||||
*/
|
||||
public function download_file($url, $path) {
|
||||
$content = $this->googleoauth->get($url);
|
||||
file_put_contents($path, $content);
|
||||
return array('path'=>$path, 'url'=>$url);
|
||||
public function download_file($url, $path, $timeout = 0) {
|
||||
$result = $this->googleoauth->download_one($url, null, array('filepath' => $path, 'timeout' => $timeout));
|
||||
if ($result === true) {
|
||||
$info = $this->googleoauth->get_info();
|
||||
if (isset($info['http_code']) && $info['http_code'] == 200) {
|
||||
return array('path'=>$path, 'url'=>$url);
|
||||
} else {
|
||||
throw new moodle_exception('cannotdownload', 'repository');
|
||||
}
|
||||
} else {
|
||||
throw new moodle_exception('errorwhiledownload', 'repository', '', $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class repository_googledocs extends repository {
|
||||
$gdocs = new google_docs($this->googleoauth);
|
||||
|
||||
$path = $this->prepare_file($file);
|
||||
return $gdocs->download_file($url, $path);
|
||||
return $gdocs->download_file($url, $path, self::GETFILE_TIMEOUT);
|
||||
}
|
||||
|
||||
public function supported_filetypes() {
|
||||
|
||||
Reference in New Issue
Block a user