From 75661ada393c514a11faf480b4dbf20c7819f374 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Wed, 28 Nov 2012 15:31:55 +0100 Subject: [PATCH] Store library info and prepare for dependency check --- h5p.classes.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 234daa7..8df06fc 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -67,7 +67,7 @@ class h5pValidator { unlink($tmp_path); // Process content and libraries - $contents = array(); + $libraries = array(); $files = scandir($tmp_dir); $json_exists = $image_exists = $content_exists = FALSE; @@ -84,7 +84,6 @@ class h5pValidator { $image_exists = TRUE; } elseif ($file == 'content') { - $content_exists = TRUE; $json = file_get_contents($file_path . DIRECTORY_SEPARATOR . 'content.json'); if (!$json) { $this->h5pF->setErrorMessage($this->t('Could not find content.json file')); @@ -97,6 +96,7 @@ class h5pValidator { $valid = FALSE; continue; } + $content_exists = TRUE; // In the future we might let the librarys provide validation functions for content.json } @@ -123,18 +123,25 @@ class h5pValidator { $valid = FALSE; continue; } - $valid = $this->isValidH5pData($h5pData, $file) && $valid; - + $validLibrary = $this->isValidH5pData($h5pData, $file) && $valid; + if (isset($h5pData->preloadedJs)) { - $valid = $this->isExcistingFiles($h5pData->preloadedJs, $tmp_dir, $file) && $valid; + $validLibrary = $this->isExcistingFiles($h5pData->preloadedJs, $tmp_dir, $file) && $validLibrary; } if (isset($h5pData->preloadedCss)) { - $valid = $this->isExcistingFiles($h5pData->preloadedCss, $tmp_dir, $file) && $valid; + $validLibrary = $this->isExcistingFiles($h5pData->preloadedCss, $tmp_dir, $file) && $validLibrary; } + if ($validLibrary) { + $libraries[$file][$h5pData['mainVersion']] = TRUE; + } + $valid = $validLibrary && $valid; } - // TODO: Store library info in array } - // TODO: Check dependencies + if ($valid) { + // TODO: Load info about excisting libraries from database + // TODO: validate dependencies + } + // TODO: Handle invalid packages(delete them and communicate it to the framework) } private function isExcistingFiles($files, $tmp_dir, $library) {