From 71763222e25e69df2aa52d189c20f3a2090eed19 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Sun, 24 Feb 2013 00:12:57 +0100 Subject: [PATCH 1/4] Save dependencies by library id instead of by machine_name and version --- h5p.classes.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 7b941dc..58282da 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -675,6 +675,18 @@ class H5PStorage { $this->h5pC->delTree($destination_path); rename($current_path, $destination_path); } + foreach ($this->h5pC->librariesJsonData as $key => &$library) { + // All libraries have been saved, we now save all the dependencies + if (isset($library['preloadedDependencies'])) { + $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['preloadedDependencies'], 'preloaded'); + } + if (isset($library['dynamicDependencies'])) { + $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['dynamicDependencies'], 'dynamic'); + } + if (isset($library['editorDependencies'])) { + $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['editorDependencies'], 'editor'); + } + } $current_path = $this->h5pF->getUploadedH5pFolderPath() . DIRECTORY_SEPARATOR . 'content'; $destination_path = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . $contentId; rename($current_path, $destination_path); From 45386f78254375328fa107626cf270771de391ca Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Wed, 6 Mar 2013 15:59:02 +0100 Subject: [PATCH 2/4] Adding full versioning support --- js/h5p.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/js/h5p.js b/js/h5p.js index 0cd835c..ec21e24 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -58,6 +58,27 @@ H5P.Coords = function(x, y, w, h) { return this; }; +/** + *@param {string} library + * library in the format machineName majorVersion.minorVersion + * @returns + * library as an object with machineName, majorVersion and minorVersion properties + * return false if the library parameter is invalid + */ +H5P.libraryFromString = function (library) { + var regExp = /(.+)\s(\d)+\.(\d)$/g; + var res = regExp.exec(library); + if (res !== null) { + return { + 'machineName': res[1], + 'majorVersion': res[2], + 'minorVersion': res[3] + }; + } + else { + return false; + } +}; // Play a video. $target is jQuery object to attach video to. (Appended). // Params are video-params from content. cp is content path. onEnded is // function to call when finished. From c996a7b5ea71423c922e92fe6488987eb2072572 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Thu, 7 Mar 2013 04:12:59 +0100 Subject: [PATCH 3/4] Adding versioning support --- h5p.classes.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index ac0ecb8..949c8c2 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -102,7 +102,7 @@ interface H5PFrameworkInterface { * @param int $contentMainId * Any contentMainId defined by the framework, for instance to support revisioning */ - public function saveContentData($contentId, $contentJson, $mainJsonData, $contentMainId = NULL); + public function saveContentData($contentId, $contentJson, $mainJsonData, $mainLibraryId, $contentMainId = NULL); /** * Copies content data @@ -164,7 +164,6 @@ class H5PValidator { 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', 'majorVersion' => '/^[0-9]{1,5}$/', 'minorVersion' => '/^[0-9]{1,5}$/', - 'defaultStyles' => 'boolean', ), 'mainLibrary' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i', 'embedTypes' => array('iframe', 'div'), @@ -179,7 +178,6 @@ class H5PValidator { 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', 'majorVersion' => '/^[0-9]{1,5}$/', 'minorVersion' => '/^[0-9]{1,5}$/', - 'defaultStyles' => 'boolean', ), 'externalResources' => array( 'machineName' => '/^[\w0-9\-\.]{1,255}$/i', @@ -700,14 +698,15 @@ class H5PStorage { $current_path = $this->h5pF->getUploadedH5pFolderPath() . DIRECTORY_SEPARATOR . 'content'; $destination_path = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . $contentId; rename($current_path, $destination_path); - - $contentJson = file_get_contents($destination_path . DIRECTORY_SEPARATOR . 'content.json'); - $this->h5pF->saveContentData($contentId, $contentJson, $this->h5pC->mainJsonData, $contentMainId); $librariesInUse = array(); $this->getLibraryUsage($librariesInUse, $this->h5pC->mainJsonData); $this->h5pF->saveLibraryUsage($contentId, $librariesInUse); $this->h5pC->delTree($this->h5pF->getUploadedH5pFolderPath()); + + $contentJson = file_get_contents($destination_path . DIRECTORY_SEPARATOR . 'content.json'); + $mainLibraryId = $librariesInUse[$this->h5pC->mainJsonData['mainLibrary']]['library']['libraryId']; + $this->h5pF->saveContentData($contentId, $contentJson, $this->h5pC->mainJsonData, $mainLibraryId, $contentMainId); } public function deletePackage($contentId) { @@ -735,7 +734,6 @@ class H5PStorage { $librariesInUse[$preloadedDependency['machineName']] = array( 'library' => $library, 'preloaded' => $dynamic ? 0 : 1, - 'default_styles' => isset($preloadedDependency['defaultStyles']) && $preloadedDependency['defaultStyles'] ? 1 : 0, ); $this->getLibraryUsage($librariesInUse, $library, $dynamic); } From 678f62d10a8c10e4526d07aafff7ec15a3fbbc70 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Thu, 7 Mar 2013 05:31:30 +0100 Subject: [PATCH 4/4] Fix problem with h5peditor changes not beeing saved when a node is beeing revisioned --- h5p.classes.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index c2efea0..f8c6e3e 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -105,7 +105,7 @@ interface H5PFrameworkInterface { public function saveContentData($contentId, $contentJson, $mainJsonData, $mainLibraryId, $contentMainId = NULL); /** - * Copies content data + * Copies library usage * * @param int $contentId * Framework specific id identifying the content @@ -116,7 +116,7 @@ interface H5PFrameworkInterface { * That supports versioning. (In this case the content id will typically be * the version id, and the contentMainId will be the frameworks content id */ - public function copyContentData($contentId, $copyFromId, $contentMainId = NULL); + public function copyLibraryUsage($contentId, $copyFromId, $contentMainId = NULL); /** * Deletes content data @@ -727,7 +727,7 @@ class H5PStorage { $destination_path = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . $contentId; $this->h5pC->copyTree($source_path, $destination_path); - $this->h5pF->copyContentData($contentId, $copyFromId, $contentMainId); + $this->h5pF->copyLibraryUsage($contentId, $copyFromId, $contentMainId); } public function getLibraryUsage(&$librariesInUse, $jsonData, $dynamic = FALSE) {