From d4ea0a1255cd33f303d26d2744d29d8bb304f14e Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Mon, 22 Jun 2015 11:22:49 +0200 Subject: [PATCH] Use warnings to tell the admin what is wrong. Removed duplicate message --- h5p.classes.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 5cb2f07..bf4320f 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1500,11 +1500,11 @@ Class H5PExport { // Create content folder if ($this->h5pC->copyFileTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $content['id'], $tempPath . DIRECTORY_SEPARATOR . 'content') === FALSE) { - $this->h5pF->setErrorMessage($this->h5pF->t('Unable to write to the temporary directory.')); return FALSE; } file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . 'content.json', $content['params']); + // Make embedTypes into an array $embedTypes = explode(', ', $content['embedType']); // Won't content always be embedded in one way? @@ -2098,11 +2098,16 @@ class H5PCore { */ public function copyFileTree($source, $destination) { if (!H5PCore::dirReady($destination)) { - $this->h5pF->setErrorMessage($this->h5pF->t('Unable to copy tree, no such directory: @dir', array('@dir' => $source))); + $this->h5pF->setErrorMessage($this->h5pF->t('Unable to copy file tree.')); return FALSE; } $dir = opendir($source); + if ($dir === FALSE) { + $this->h5pF->setErrorMessage($this->h5pF->t('Unable to copy file tree.')); + return FALSE; + } + while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..') && $file != '.git' && $file != '.gitignore') { if (is_dir($source . DIRECTORY_SEPARATOR . $file)) { @@ -2501,17 +2506,20 @@ class H5PCore { return FALSE; } - if (!is_writable($parent)) { - return FALSE; - } - mkdir($path, 0777, true); } + if (!is_dir($path)) { + trigger_error('Path is not a directory ' . $path, E_USER_WARNING); return FALSE; } - return is_writable($path); + if (!is_writable($path)) { + trigger_error('Unable to write to ' . $path . ' – check directory permissions –', E_USER_WARNING); + return FALSE; + } + + return TRUE; } }