From fd34af6964857e8a2f9f49423d6bf1a109576ac6 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Wed, 14 Sep 2016 10:44:10 +0200 Subject: [PATCH] Use content array instead of just id Makes it easier when additional properties are needed. Also, don't try to translate PHP exception messages. h5p/h5p-moodle-plugin#112 --- h5p-default-storage.class.php | 16 ++++++++-------- h5p-file-storage.interface.php | 12 ++++++------ h5p.classes.php | 10 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index e019990..9055266 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -53,11 +53,11 @@ class H5PDefaultStorage implements \H5PFileStorage { * * @param string $source * Path on file system to content directory. - * @param int $id - * What makes this content unique. + * @param array $content + * Content properties */ - public function saveContent($source, $id) { - $dest = "{$this->path}/content/{$id}"; + public function saveContent($source, $content) { + $dest = "{$this->path}/content/{$content['id']}"; // Remove any old content \H5PCore::deleteFileTree($dest); @@ -68,11 +68,11 @@ class H5PDefaultStorage implements \H5PFileStorage { /** * Remove content folder. * - * @param int $id - * Content identifier + * @param array $content + * Content properties */ - public function deleteContent($id) { - \H5PCore::deleteFileTree("{$this->path}/content/{$id}"); + public function deleteContent($content) { + \H5PCore::deleteFileTree("{$this->path}/content/{$content['id']}"); } /** diff --git a/h5p-file-storage.interface.php b/h5p-file-storage.interface.php index a003256..abee27a 100644 --- a/h5p-file-storage.interface.php +++ b/h5p-file-storage.interface.php @@ -22,18 +22,18 @@ interface H5PFileStorage { * * @param string $source * Path on file system to content directory. - * @param int $id - * What makes this content unique. + * @param array $content + * Content properties */ - public function saveContent($source, $id); + public function saveContent($source, $content); /** * Remove content folder. * - * @param int $id - * Content identifier + * @param array $content + * Content properties */ - public function deleteContent($id); + public function deleteContent($content); /** * Creates a stored copy of the content folder. diff --git a/h5p.classes.php b/h5p.classes.php index 64c2ab5..103ec09 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1311,15 +1311,15 @@ class H5PStorage { if (isset($options['disable'])) { $content['disable'] = $options['disable']; } - $contentId = $this->h5pC->saveContent($content, $contentMainId); - $this->contentId = $contentId; + $content['id'] = $this->h5pC->saveContent($content, $contentMainId); + $this->contentId = $content['id']; try { // Save content folder contents - $this->h5pC->fs->saveContent($current_path, $contentId); + $this->h5pC->fs->saveContent($current_path, $content); } catch (Exception $e) { - $this->h5pF->setErrorMessage($this->h5pF->t($e->getMessage())); + $this->h5pF->setErrorMessage($e->getMessage()); } // Remove temp content folder @@ -1433,7 +1433,7 @@ class H5PStorage { * @param $content */ public function deletePackage($content) { - $this->h5pC->fs->deleteContent($content['id']); + $this->h5pC->fs->deleteContent($content); $this->h5pC->fs->deleteExport(($content['slug'] ? $content['slug'] . '-' : '') . $content['id'] . '.h5p'); $this->h5pF->deleteContentData($content['id']); }