Skip to content

Commit

Permalink
MDL-71970 h5plib_v124: Add namespace to H5P core library
Browse files Browse the repository at this point in the history
The joubel/core is a third-party library. A namespace has been added to
avoid collision with other plugins using it (such as mod_hvp).
That way, they will be able to have a different version without
side effects.
  • Loading branch information
sarjona committed Sep 27, 2021
1 parent 1a63bcc commit 88c5228
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 11 deletions.
15 changes: 8 additions & 7 deletions h5p/h5plib/v124/joubel/core/h5p-default-storage.class.php
@@ -1,5 +1,6 @@
<?php

namespace Moodle;
/**
* File info?
*/
Expand All @@ -9,13 +10,13 @@
* operations using PHP's standard file operation functions.
*
* Some implementations of H5P that doesn't use the standard file system will
* want to create their own implementation of the \H5P\FileStorage interface.
* want to create their own implementation of the H5PFileStorage interface.
*
* @package H5P
* @copyright 2016 Joubel AS
* @license MIT
*/
class H5PDefaultStorage implements \H5PFileStorage {
class H5PDefaultStorage implements H5PFileStorage {
private $path, $alteditorpath;

/**
Expand All @@ -39,10 +40,10 @@ function __construct($path, $alteditorpath = NULL) {
* Library properties
*/
public function saveLibrary($library) {
$dest = $this->path . '/libraries/' . \H5PCore::libraryToString($library, TRUE);
$dest = $this->path . '/libraries/' . H5PCore::libraryToString($library, TRUE);

// Make sure destination dir doesn't exist
\H5PCore::deleteFileTree($dest);
H5PCore::deleteFileTree($dest);

// Move library folder
self::copyFileTree($library['uploadDirectory'], $dest);
Expand All @@ -60,7 +61,7 @@ public function saveContent($source, $content) {
$dest = "{$this->path}/content/{$content['id']}";

// Remove any old content
\H5PCore::deleteFileTree($dest);
H5PCore::deleteFileTree($dest);

self::copyFileTree($source, $dest);
}
Expand All @@ -72,7 +73,7 @@ public function saveContent($source, $content) {
* Content properties
*/
public function deleteContent($content) {
\H5PCore::deleteFileTree("{$this->path}/content/{$content['id']}");
H5PCore::deleteFileTree("{$this->path}/content/{$content['id']}");
}

/**
Expand Down Expand Up @@ -133,7 +134,7 @@ public function exportContent($id, $target) {
* Folder that library resides in
*/
public function exportLibrary($library, $target, $developmentPath=NULL) {
$folder = \H5PCore::libraryToString($library, TRUE);
$folder = H5PCore::libraryToString($library, TRUE);
$srcPath = ($developmentPath === NULL ? "/libraries/{$folder}" : $developmentPath);
self::copyFileTree("{$this->path}{$srcPath}", "{$target}/{$folder}");
}
Expand Down
2 changes: 2 additions & 0 deletions h5p/h5plib/v124/joubel/core/h5p-development.class.php
@@ -1,5 +1,7 @@
<?php

namespace Moodle;

/**
* This is a data layer which uses the file system so it isn't specific to any framework.
*/
Expand Down
2 changes: 2 additions & 0 deletions h5p/h5plib/v124/joubel/core/h5p-event-base.class.php
@@ -1,5 +1,7 @@
<?php

namespace Moodle;

/**
* The base class for H5P events. Extend to track H5P events in your system.
*
Expand Down
2 changes: 2 additions & 0 deletions h5p/h5plib/v124/joubel/core/h5p-file-storage.interface.php
@@ -1,5 +1,7 @@
<?php

namespace Moodle;

/**
* File info?
*/
Expand Down
3 changes: 3 additions & 0 deletions h5p/h5plib/v124/joubel/core/h5p-metadata.class.php
@@ -1,4 +1,7 @@
<?php

namespace Moodle;

/**
* Utility class for handling metadata
*/
Expand Down
9 changes: 7 additions & 2 deletions h5p/h5plib/v124/joubel/core/h5p.classes.php
@@ -1,4 +1,9 @@
<?php

namespace Moodle;

use ZipArchive;

/**
* Interface defining functions the h5p library needs the framework to implement
*/
Expand Down Expand Up @@ -2057,15 +2062,15 @@ class H5PCore {
*
* @param H5PFrameworkInterface $H5PFramework
* The frameworks implementation of the H5PFrameworkInterface
* @param string|\H5PFileStorage $path H5P file storage directory or class.
* @param string|H5PFileStorage $path H5P file storage directory or class.
* @param string $url To file storage directory.
* @param string $language code. Defaults to english.
* @param boolean $export enabled?
*/
public function __construct(H5PFrameworkInterface $H5PFramework, $path, $url, $language = 'en', $export = FALSE) {
$this->h5pF = $H5PFramework;

$this->fs = ($path instanceof \H5PFileStorage ? $path : new \H5PDefaultStorage($path));
$this->fs = ($path instanceof H5PFileStorage ? $path : new H5PDefaultStorage($path));

$this->url = $url;
$this->exportEnabled = $export;
Expand Down
12 changes: 10 additions & 2 deletions h5p/h5plib/v124/joubel/core/readme_moodle.txt
Expand Up @@ -19,13 +19,13 @@ Downloaded version: 1.24.2 release
Changes:
1. In order to allow the dependency path to be overridden by child H5PCore classes, a couple of minor changes have been added to the
h5p.classes.php file:
- Into the getDependenciesFiles method, the line 2435:
- Into the getDependenciesFiles method, the line 2440:
$dependency['path'] = 'libraries/' . H5PCore::libraryToString($dependency, TRUE);

has been changed to:
$dependency['path'] = $this->getDependencyPath($dependency);

- The method getDependencyPath has been added (line 2455). It might be rewritten by child classes.
- The method getDependencyPath has been added (line 2466). It might be rewritten by child classes.
A PR has been sent to the H5P library with these changes:
https://github.com/h5p/h5p-php-library/compare/master...andrewnicols:libraryPathSubclass
Hopefully, when upgrading, these patch won't be needed because it will be included in the H5P library by default.
Expand Down Expand Up @@ -74,3 +74,11 @@ with the previous patched and minified JQuery version.
*
* @member
*/


4. Add namespace to this library to avoid collision. It means:

- Add the "namespace Moodle;" line at the top of all the h5p*.php files in the root folder.
- Replace \H5Pxxx uses to H5Pxxx (for instance, in h5p-default-storage.class.php there are several references to \H5PCore that
must be replaced with H5PCore).
- Add "use ZipArchive;" in h5p.classes.h5p (check that it's still used before replacing it when upgrading the library).

0 comments on commit 88c5228

Please sign in to comment.