Skip to content

Commit

Permalink
MDL-35034 Repository: Google Docs does not fail when download is rest…
Browse files Browse the repository at this point in the history
…ricted
  • Loading branch information
Frederic Massart committed Sep 3, 2012
1 parent 569f1ad commit ec7e998
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 11 additions & 13 deletions lib/googleapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,21 @@ public function get_file_list($search = '') {
$source = 'https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key='.$docid.'&exportFormat=xls';
break;
case 'pdf':
$title = (string)$gdoc->title;
$source = (string)$gdoc->content[0]->attributes()->src;
break;
case 'file':
$title = (string)$gdoc->title;
$source = (string)$gdoc->content[0]->attributes()->src;
$title = (string)$gdoc->title;
// Some files don't have a content probably because the download has been restricted.
if (isset($gdoc->content)) {
$source = (string)$gdoc->content[0]->attributes()->src;
}
break;
}

if (!empty($source)) {
$files[] = array( 'title' => $title,
'url' => "{$gdoc->link[0]->attributes()->href}",
'source' => $source,
'date' => usertime(strtotime($gdoc->updated)),
'thumbnail' => (string) $OUTPUT->pix_url(file_extension_icon($title, 32))
);
}
$files[] = array( 'title' => $title,
'url' => "{$gdoc->link[0]->attributes()->href}",
'source' => $source,
'date' => usertime(strtotime($gdoc->updated)),
'thumbnail' => (string) $OUTPUT->pix_url(file_extension_icon($title, 32))
);
}

return $files;
Expand Down
4 changes: 3 additions & 1 deletion repository/googledocs/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ public function logout() {
}

public function get_file($url, $file = '') {
if (empty($url)) {
throw new repository_exception('cannotdownload', 'repository');
}
$gdocs = new google_docs($this->googleoauth);

$path = $this->prepare_file($file);
return $gdocs->download_file($url, $path, self::GETFILE_TIMEOUT);
}
Expand Down

0 comments on commit ec7e998

Please sign in to comment.