Prevent copy of trees that does not exist.

namespaces
Frode Petterson 2013-12-20 13:31:08 +01:00
parent a41a8f82f9
commit 7a3888a367
1 changed files with 9 additions and 1 deletions

View File

@ -1109,7 +1109,9 @@ Class H5PExport {
@mkdir($tempPath); @mkdir($tempPath);
$exportData = $this->h5pF->getExportData($contentId); $exportData = $this->h5pF->getExportData($contentId);
// Create content folder // Create content folder
$this->h5pC->copyTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $contentId, $tempPath . DIRECTORY_SEPARATOR . 'content'); if ($this->h5pC->copyTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $contentId, $tempPath . DIRECTORY_SEPARATOR . 'content') === FALSE) {
return FALSE;
}
file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . 'content.json', $exportData['jsonContent']); file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . 'content.json', $exportData['jsonContent']);
// Make embedTypes into an array // Make embedTypes into an array
@ -1307,6 +1309,12 @@ class H5PCore {
*/ */
public function copyTree($source, $destination) { public function copyTree($source, $destination) {
$dir = opendir($source); $dir = opendir($source);
if ($dir === FALSE) {
$this->h5pF->setErrorMessage($this->h5pF->t('Unable to copy tree, no such directory: @dir', array('@dir' => $source)));
return FALSE;
}
@mkdir($destination); @mkdir($destination);
while (false !== ($file = readdir($dir))) { while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) { if (($file != '.') && ($file != '..')) {