mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-67296 core_h5p: minor changes
core.php-Avoid to use the factory for each content type h5p_get_content_types_task-new method to simplify test execution framework.php-returns error if you get a 404 response after requesting a file
This commit is contained in:
parent
fd126006b0
commit
d8fe1eddf9
@ -27,6 +27,7 @@ namespace core_h5p;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
|
||||
use H5PCore;
|
||||
use H5PFrameworkInterface;
|
||||
use stdClass;
|
||||
@ -170,6 +171,9 @@ class core extends \H5PCore {
|
||||
|
||||
$typesinstalled = [];
|
||||
|
||||
$factory = new factory();
|
||||
$framework = $factory->get_framework();
|
||||
|
||||
foreach ($contenttypes->contentTypes as $type) {
|
||||
// Don't fetch content types that require a higher H5P core API version.
|
||||
if (!$this->is_required_core_api($type->coreApiVersionNeeded)) {
|
||||
@ -183,9 +187,6 @@ class core extends \H5PCore {
|
||||
'patchVersion' => $type->version->patch
|
||||
];
|
||||
|
||||
$factory = new \core_h5p\factory();
|
||||
$framework = $factory->get_framework();
|
||||
|
||||
$shoulddownload = true;
|
||||
if ($framework->getLibraryId($type->id, $type->version->major, $type->version->minor)) {
|
||||
if (!$framework->isPatchedLibrary($library)) {
|
||||
@ -216,7 +217,7 @@ class core extends \H5PCore {
|
||||
* @return int|null Returns the id of the content type library installed, null otherwise.
|
||||
*/
|
||||
public function fetch_content_type(array $library): ?int {
|
||||
$factory = new \core_h5p\factory();
|
||||
$factory = new factory();
|
||||
|
||||
// Get a temp path to download the content type.
|
||||
$temppath = make_request_directory();
|
||||
@ -247,7 +248,9 @@ class core extends \H5PCore {
|
||||
$file->delete();
|
||||
|
||||
$librarykey = static::libraryToString($library);
|
||||
return $factory->get_storage()->h5pC->librariesJsonData[$librarykey]["libraryId"];
|
||||
$libraryid = $factory->get_storage()->h5pC->librariesJsonData[$librarykey]["libraryId"];
|
||||
|
||||
return $libraryid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +100,7 @@ class framework implements \H5PFrameworkInterface {
|
||||
$response = download_file_content($url, null, $data, true, 300, 20,
|
||||
false, $stream);
|
||||
|
||||
if (empty($response->error)) {
|
||||
if (empty($response->error) && ($response->status != '404')) {
|
||||
return $response->results;
|
||||
} else {
|
||||
$this->setErrorMessage($response->error, 'failed-fetching-external-data');
|
||||
|
@ -44,13 +44,23 @@ class h5p_get_content_types_task extends scheduled_task {
|
||||
return get_string('h5pgetcontenttypestask', 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an \core_h5p\core instance.
|
||||
*
|
||||
* @return \core_h5p\core
|
||||
*/
|
||||
public function get_core() {
|
||||
$factory = new factory();
|
||||
$core = $factory->get_core();
|
||||
return $core;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the task.
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
$factory = new factory();
|
||||
$core = $factory->get_core();
|
||||
$core = $this->get_core();
|
||||
|
||||
$result = $core->fetch_latest_content_types();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user