Merge branch 'MDL-74424-master' of https://github.com/mihailges/moodle
This commit is contained in:
@@ -49,6 +49,9 @@ class file_node implements node {
|
||||
/** @var string The thumbnail of the file. */
|
||||
private $thumbnail;
|
||||
|
||||
/** @var string|null The type of the Google Doc file (document, presentation, etc.), null if it is a regular file. */
|
||||
private $googledoctype;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -72,6 +75,8 @@ class file_node implements node {
|
||||
// in displaying 16px file thumbnails in the repository. To avoid this, the link can be slightly modified in
|
||||
// order to get a larger version of the icon as there isn't an option to request this through the API call.
|
||||
$this->thumbnail = !empty($gdfile->iconLink) ? str_replace('/16/', '/64/', $gdfile->iconLink) : '';
|
||||
$this->googledoctype = !isset($gdfile->fileExtension) ?
|
||||
str_replace('application/vnd.google-apps.', '', $gdfile->mimeType) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,6 +102,7 @@ class file_node implements node {
|
||||
'name' => $this->name,
|
||||
'link' => $this->link,
|
||||
'exportformat' => $this->exportformat,
|
||||
'googledoctype' => $this->googledoctype,
|
||||
]
|
||||
),
|
||||
'date' => $this->modified,
|
||||
|
||||
@@ -528,8 +528,26 @@ class repository_googledocs extends repository {
|
||||
if ($checktype == 'application/rtf') {
|
||||
$checktype = 'text/rtf';
|
||||
}
|
||||
// Determine the relevant default import format config for the given file.
|
||||
switch ($source->googledoctype) {
|
||||
case 'document':
|
||||
$importformatconfig = get_config('googledocs', 'documentformat');
|
||||
break;
|
||||
case 'presentation':
|
||||
$importformatconfig = get_config('googledocs', 'presentationformat');
|
||||
break;
|
||||
case 'spreadsheet':
|
||||
$importformatconfig = get_config('googledocs', 'spreadsheetformat');
|
||||
break;
|
||||
case 'drawing':
|
||||
$importformatconfig = get_config('googledocs', 'drawingformat');
|
||||
break;
|
||||
default:
|
||||
$importformatconfig = null;
|
||||
}
|
||||
|
||||
foreach ($types as $extension => $info) {
|
||||
if ($info['type'] == $checktype) {
|
||||
if ($info['type'] == $checktype && $extension === $importformatconfig) {
|
||||
$newfilename = $source->name . '.' . $extension;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ class file_node_test extends \repository_googledocs_testcase {
|
||||
],
|
||||
$this->create_file_content_node_array('d85b21c0f86cb0', 'File', 'File.gdoc', '', '',
|
||||
'https://googleusercontent.com/type/application/vnd.google-apps.document', '',
|
||||
'application/rtf'),
|
||||
'application/rtf', 'document'),
|
||||
],
|
||||
'Google Drive file without an extension (Google presentation file; presentationformat config not set).' =>
|
||||
[
|
||||
|
||||
@@ -60,10 +60,12 @@ abstract class repository_googledocs_testcase extends \advanced_testcase {
|
||||
* @param string $thumbnail The thumbnail of the file
|
||||
* @param string|null $link The external link to the file
|
||||
* @param string|null $exportformat The export format of the file
|
||||
* @param string|null $googledoctype The type of the Google Doc file (if applicable)
|
||||
* @return array The repository file node array
|
||||
*/
|
||||
protected function create_file_content_node_array(string $id, string $name, string $title, ?string $size = null,
|
||||
string $modified = '', string $thumbnail = '' , string $link = '', string $exportformat = ''): array {
|
||||
string $modified = '', string $thumbnail = '' , string $link = '', string $exportformat = '',
|
||||
?string $googledoctype = null): array {
|
||||
|
||||
return [
|
||||
'id' => $id,
|
||||
@@ -72,7 +74,8 @@ abstract class repository_googledocs_testcase extends \advanced_testcase {
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
'link' => $link,
|
||||
'exportformat' => $exportformat
|
||||
'exportformat' => $exportformat,
|
||||
'googledoctype' => $googledoctype
|
||||
]),
|
||||
'date' => $modified,
|
||||
'size' => $size,
|
||||
|
||||
Reference in New Issue
Block a user