Merge branch 'master' of github.com:h5p/h5p-php-library

namespaces
Frode Petterson 2015-01-09 09:53:13 +01:00
commit 35a7f39a0b
2 changed files with 31 additions and 14 deletions

View File

@ -93,6 +93,7 @@ class H5PDevelopment {
// TODO: Should we remove libraries without files? Not really needed, but must be cleaned up some time, right? // TODO: Should we remove libraries without files? Not really needed, but must be cleaned up some time, right?
// Go trough libraries and insert dependencies. Missing deps. will just be ignored and not available. (I guess?!) // Go trough libraries and insert dependencies. Missing deps. will just be ignored and not available. (I guess?!)
$this->h5pF->lockDependencyStorage();
foreach ($this->libraries as $library) { foreach ($this->libraries as $library) {
$this->h5pF->deleteLibraryDependencies($library['libraryId']); $this->h5pF->deleteLibraryDependencies($library['libraryId']);
// This isn't optimal, but without it we would get duplicate warnings. // This isn't optimal, but without it we would get duplicate warnings.
@ -104,6 +105,7 @@ class H5PDevelopment {
} }
} }
} }
$this->h5pF->unlockDependencyStorage();
// TODO: Deps must be inserted into h5p_nodes_libraries as well... ? But only if they are used?! // TODO: Deps must be inserted into h5p_nodes_libraries as well... ? But only if they are used?!
} }

View File

@ -408,6 +408,17 @@ interface H5PFrameworkInterface {
*/ */
public function deleteLibraryDependencies($libraryId); public function deleteLibraryDependencies($libraryId);
/**
* Start an atomic operation against the dependency storage
*/
public function lockDependencyStorage();
/**
* Stops an atomic operation against the dependency storage
*/
public function unlockDependencyStorage();
/** /**
* Delete a library from database and file system * Delete a library from database and file system
* *
@ -1433,7 +1444,7 @@ Class H5PExport {
'title' => $content['title'], 'title' => $content['title'],
// TODO - stop using 'und', this is not the preferred way. // TODO - stop using 'und', this is not the preferred way.
// Either remove language from the json if not existing, or use "language": null // Either remove language from the json if not existing, or use "language": null
'language' => isset($content['language']) ? $content['language'] : 'und', 'language' => (isset($content['language']) && strlen(trim($content['language'])) !== 0) ? $content['language'] : 'und',
'mainLibrary' => $content['library']['name'], 'mainLibrary' => $content['library']['name'],
'embedTypes' => $embedTypes, 'embedTypes' => $embedTypes,
); );
@ -1465,7 +1476,7 @@ Class H5PExport {
// Create new zip instance. // Create new zip instance.
$zip = new ZipArchive(); $zip = new ZipArchive();
$zip->open($zipPath, ZIPARCHIVE::CREATE); $zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
// Get all files and folders in $tempPath // Get all files and folders in $tempPath
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempPath . DIRECTORY_SEPARATOR)); $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempPath . DIRECTORY_SEPARATOR));
@ -1648,19 +1659,23 @@ class H5PCore {
// Update content dependencies. // Update content dependencies.
$content['dependencies'] = $validator->getDependencies(); $content['dependencies'] = $validator->getDependencies();
$this->h5pF->deleteLibraryUsage($content['id']);
$this->h5pF->saveLibraryUsage($content['id'], $content['dependencies']);
if ($this->exportEnabled) { // Sometimes the parameters are filtered before content has been created
// Recreate export file if ($content['id']) {
$exporter = new H5PExport($this->h5pF, $this); $this->h5pF->deleteLibraryUsage($content['id']);
$exporter->createExportFile($content); $this->h5pF->saveLibraryUsage($content['id'], $content['dependencies']);
// TODO: Should we rather create the file once first accessed, like imagecache? if ($this->exportEnabled) {
// Recreate export file
$exporter = new H5PExport($this->h5pF, $this);
$exporter->createExportFile($content);
// TODO: Should we rather create the file once first accessed, like imagecache?
}
// Cache.
$this->h5pF->setFilteredParameters($content['id'], $params);
} }
// Cache.
$this->h5pF->setFilteredParameters($content['id'], $params);
return $params; return $params;
} }
@ -2184,7 +2199,7 @@ class H5PCore {
$platformInfo['uuid'] = $this->h5pF->getOption('h5p_site_uuid', ''); $platformInfo['uuid'] = $this->h5pF->getOption('h5p_site_uuid', '');
// Adding random string to GET to be sure nothing is cached // Adding random string to GET to be sure nothing is cached
$random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5); $random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5);
$json = $this->h5pF->fetchExternalData('http://h5p.lvh.me/h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random)); $json = $this->h5pF->fetchExternalData('http://h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random));
if ($json !== NULL) { if ($json !== NULL) {
$json = json_decode($json); $json = json_decode($json);
if (isset($json->libraries)) { if (isset($json->libraries)) {
@ -2316,7 +2331,7 @@ class H5PContentValidator {
*/ */
public function validateContentFiles($contentPath, $isLibrary = FALSE) { public function validateContentFiles($contentPath, $isLibrary = FALSE) {
if ($this->h5pC->disableFileCheck === TRUE) { if ($this->h5pC->disableFileCheck === TRUE) {
return TRUE; return TRUE;
} }
// Scan content directory for files, recurse into sub directories. // Scan content directory for files, recurse into sub directories.