Store library info and prepare for dependency check

namespaces
Svein-Tore Griff With 2012-11-28 15:31:55 +01:00
parent 6a21c3101b
commit 75661ada39
1 changed files with 15 additions and 8 deletions

View File

@ -67,7 +67,7 @@ class h5pValidator {
unlink($tmp_path); unlink($tmp_path);
// Process content and libraries // Process content and libraries
$contents = array(); $libraries = array();
$files = scandir($tmp_dir); $files = scandir($tmp_dir);
$json_exists = $image_exists = $content_exists = FALSE; $json_exists = $image_exists = $content_exists = FALSE;
@ -84,7 +84,6 @@ class h5pValidator {
$image_exists = TRUE; $image_exists = TRUE;
} }
elseif ($file == 'content') { elseif ($file == 'content') {
$content_exists = TRUE;
$json = file_get_contents($file_path . DIRECTORY_SEPARATOR . 'content.json'); $json = file_get_contents($file_path . DIRECTORY_SEPARATOR . 'content.json');
if (!$json) { if (!$json) {
$this->h5pF->setErrorMessage($this->t('Could not find content.json file')); $this->h5pF->setErrorMessage($this->t('Could not find content.json file'));
@ -97,6 +96,7 @@ class h5pValidator {
$valid = FALSE; $valid = FALSE;
continue; continue;
} }
$content_exists = TRUE;
// In the future we might let the librarys provide validation functions for content.json // In the future we might let the librarys provide validation functions for content.json
} }
@ -123,18 +123,25 @@ class h5pValidator {
$valid = FALSE; $valid = FALSE;
continue; continue;
} }
$valid = $this->isValidH5pData($h5pData, $file) && $valid; $validLibrary = $this->isValidH5pData($h5pData, $file) && $valid;
if (isset($h5pData->preloadedJs)) { 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)) { 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 if ($valid) {
// TODO: Load info about excisting libraries from database
// TODO: validate dependencies
} }
// TODO: Check dependencies // TODO: Handle invalid packages(delete them and communicate it to the framework)
} }
private function isExcistingFiles($files, $tmp_dir, $library) { private function isExcistingFiles($files, $tmp_dir, $library) {