MDL-76004 core_h5p: Ensure the browser is serving updated file

This commit is contained in:
Amaia Anabitarte
2022-12-14 16:22:46 +01:00
parent 6b24f59302
commit 76ce30ca98
2 changed files with 19 additions and 10 deletions
+13 -4
View File
@@ -317,6 +317,7 @@ class player {
$systemcontext = \context_system::instance();
$slug = $this->content['slug'] ? $this->content['slug'] . '-' : '';
$filename = "{$slug}{$this->content['id']}.h5p";
// We have to build the right URL.
// Depending the request was made through webservice/pluginfile.php or pluginfile.php.
if (strpos($this->url, '/webservice/pluginfile.php')) {
@@ -326,7 +327,7 @@ class player {
\core_h5p\file_storage::EXPORT_FILEAREA,
'',
'',
"{$slug}{$this->content['id']}.h5p"
$filename
);
} else {
// If the request is made by tokenpluginfile.php we need to indicates to generate a token for current user.
@@ -340,12 +341,17 @@ class player {
\core_h5p\file_storage::EXPORT_FILEAREA,
'',
'',
"{$slug}{$this->content['id']}.h5p",
$filename,
false,
$includetoken
);
}
// Get the required info from the export file to be able to get the export file by third apps.
$file = helper::get_export_info($filename, $url);
if ($file) {
$url->param('modified', $file['timemodified']);
}
return $url;
}
@@ -514,13 +520,16 @@ class player {
/**
* Return the info export file for Mobile App.
*
* @return array
* @return array or null
*/
public function get_export_file(): array {
public function get_export_file(): ?array {
// Get the export url.
$exporturl = $this->get_export_settings(true);
// Get the filename of the export url.
$path = $exporturl->out_as_local_url();
// Check if the URL has parameters.
$parts = explode('?', $path);
$path = array_shift($parts);
$parts = explode('/', $path);
$filename = array_pop($parts);
// Get the required info from the export file to be able to get the export file by third apps.
+6 -6
View File
@@ -96,8 +96,8 @@ class external_test extends externallib_advanced_testcase {
$this->assertEquals($deployedfile['mimetype'], $result['files'][0]['mimetype']);
$this->assertEquals($deployedfile['filesize'], $result['files'][0]['filesize']);
$this->assertEquals($deployedfile['timemodified'], $result['files'][0]['timemodified']);
$this->assertEquals($deployedfile['filename'], $result['files'][0]['filename']);
$this->assertEquals($deployedfile['fileurl'], $result['files'][0]['fileurl']);
$this->assertStringContainsString($deployedfile['filename'], $result['files'][0]['filename']);
$this->assertStringContainsString($deployedfile['fileurl'], $result['files'][0]['fileurl']);
}
/**
@@ -196,8 +196,8 @@ class external_test extends externallib_advanced_testcase {
$this->assertEquals($deployedfile['mimetype'], $result['files'][0]['mimetype']);
$this->assertEquals($deployedfile['filesize'], $result['files'][0]['filesize']);
$this->assertEquals($deployedfile['timemodified'], $result['files'][0]['timemodified']);
$this->assertEquals($deployedfile['filename'], $result['files'][0]['filename']);
$this->assertEquals($deployedfile['fileurl'], $result['files'][0]['fileurl']);
$this->assertStringContainsString($deployedfile['filename'], $result['files'][0]['filename']);
$this->assertStringContainsString($deployedfile['fileurl'], $result['files'][0]['fileurl']);
}
/**
@@ -244,7 +244,7 @@ class external_test extends externallib_advanced_testcase {
$this->assertEquals($deployedfile['mimetype'], $result['files'][0]['mimetype']);
$this->assertEquals($deployedfile['filesize'], $result['files'][0]['filesize']);
$this->assertEquals($deployedfile['timemodified'], $result['files'][0]['timemodified']);
$this->assertEquals($deployedfile['filename'], $result['files'][0]['filename']);
$this->assertEquals($deployedfile['fileurl'], $result['files'][0]['fileurl']);
$this->assertStringContainsString($deployedfile['filename'], $result['files'][0]['filename']);
$this->assertStringContainsString($deployedfile['fileurl'], $result['files'][0]['fileurl']);
}
}