MDL-34290 Added timeout to googledocs request to download a file

This commit is contained in:
Marina Glancy
2012-08-29 11:56:18 +08:00
parent 42aa6e15bb
commit 7bb7bd2e79
2 changed files with 14 additions and 5 deletions
+13 -4
View File
@@ -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);
}
}
}
+1 -1
View File
@@ -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() {