Skip to content

Commit

Permalink
MDL-34290 Added timeout to googledocs request to download a file
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Aug 29, 2012
1 parent 42aa6e1 commit 7bb7bd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lib/googleapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,21 @@ public function send_file($file) {
*
* @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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion repository/googledocs/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function get_file($url, $file = '') {
$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() {
Expand Down

0 comments on commit 7bb7bd2

Please sign in to comment.