Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 0707372b0332634478578083a2721d827693f82c 1 parent 3dce698
Marina Glancy marinaglancy authored

Showing 2 changed files with 14 additions and 5 deletions. Show diff stats Hide diff stats

  1. +13 4 lib/googleapi.php
  2. +1 1  repository/googledocs/lib.php
17 lib/googleapi.php
@@ -185,12 +185,21 @@ public function send_file($file) {
185 185 *
186 186 * @param string $url url of file
187 187 * @param string $path path to save file to
  188 + * @param int $timeout request timeout, default 0 which means no timeout
188 189 * @return array stucture for repository download_file
189 190 */
190   - public function download_file($url, $path) {
191   - $content = $this->googleoauth->get($url);
192   - file_put_contents($path, $content);
193   - return array('path'=>$path, 'url'=>$url);
  191 + public function download_file($url, $path, $timeout = 0) {
  192 + $result = $this->googleoauth->download_one($url, null, array('filepath' => $path, 'timeout' => $timeout));
  193 + if ($result === true) {
  194 + $info = $this->googleoauth->get_info();
  195 + if (isset($info['http_code']) && $info['http_code'] == 200) {
  196 + return array('path'=>$path, 'url'=>$url);
  197 + } else {
  198 + throw new moodle_exception('cannotdownload', 'repository');
  199 + }
  200 + } else {
  201 + throw new moodle_exception('errorwhiledownload', 'repository', '', $result);
  202 + }
194 203 }
195 204 }
196 205
2  repository/googledocs/lib.php
@@ -95,7 +95,7 @@ public function get_file($url, $file = '') {
95 95 $gdocs = new google_docs($this->googleoauth);
96 96
97 97 $path = $this->prepare_file($file);
98   - return $gdocs->download_file($url, $path);
  98 + return $gdocs->download_file($url, $path, self::GETFILE_TIMEOUT);
99 99 }
100 100
101 101 public function supported_filetypes() {

0 comments on commit 0707372

Please sign in to comment.
Something went wrong with that request. Please try again.