Skip to content

Commit 366d8f2

Browse files
committed
JI-1062 Add interface function for saving files from .h5p
Make it easier for plugins to override the unpacking of the package files.
1 parent d38b3b1 commit 366d8f2

3 files changed

+264
-121
lines changed

h5p-default-storage.class.php

+23-11
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,14 @@ public function cloneContentFile($file, $fromId, $toId) {
357357
* content from the current temporary upload folder to the editor path.
358358
*
359359
* @param string $source path to source directory
360-
* @param string $contentId Id of content
361-
*
362-
* @return object Object containing h5p json and content json data
360+
* @param string $contentId Id of contentarray
363361
*/
364362
public function moveContentDirectory($source, $contentId = NULL) {
365363
if ($source === NULL) {
366364
return NULL;
367365
}
368366

367+
// TODO: Remove $contentId and never copy temporary files into content folder. JI-366
369368
if ($contentId === NULL || $contentId == 0) {
370369
$target = $this->getEditorPath();
371370
}
@@ -385,14 +384,7 @@ public function moveContentDirectory($source, $contentId = NULL) {
385384
}
386385
}
387386

388-
// Successfully loaded content json of file into editor
389-
$h5pJson = $this->getContent($source . DIRECTORY_SEPARATOR . 'h5p.json');
390-
$contentJson = $this->getContent($contentSource . DIRECTORY_SEPARATOR . 'content.json');
391-
392-
return (object) array(
393-
'h5pJson' => $h5pJson,
394-
'contentJson' => $contentJson
395-
);
387+
// TODO: Return list of all files so that they can be marked as temporary. JI-366
396388
}
397389

398390
/**
@@ -476,6 +468,26 @@ public function getUpgradeScript($machineName, $majorVersion, $minorVersion) {
476468
}
477469
}
478470

471+
/**
472+
* Store the given stream into the given file.
473+
*
474+
* @param string $path
475+
* @param string $file
476+
* @param resource $stream
477+
* @return bool
478+
*/
479+
public function saveFileFromZip($path, $file, $stream) {
480+
$filePath = $path . '/' . $file;
481+
482+
// Make sure the directory exists first
483+
$matches = array();
484+
preg_match('/(.+)\/[^\/]*$/', $filePath, $matches);
485+
self::dirReady($matches[1]);
486+
487+
// Store in local storage folder
488+
return file_put_contents($filePath, $stream);
489+
}
490+
479491
/**
480492
* Recursive function for copying directories.
481493
*

h5p-file-storage.interface.php

+10
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,14 @@ public function hasPresave($libraryName, $developmentPath = null);
209209
* @return string Relative path
210210
*/
211211
public function getUpgradeScript($machineName, $majorVersion, $minorVersion);
212+
213+
/**
214+
* Store the given stream into the given file.
215+
*
216+
* @param string $path
217+
* @param string $file
218+
* @param resource $stream
219+
* @return bool
220+
*/
221+
public function saveFileFromZip($path, $file, $stream);
212222
}

0 commit comments

Comments
 (0)