From aa861fc8ce278ce7f6036715644b4a75e0ae5a83 Mon Sep 17 00:00:00 2001 From: thomasmars Date: Thu, 23 Feb 2017 14:20:56 +0100 Subject: [PATCH] Make disable hub, into enable hub to match the checkbox state. Implemented write access check HFP-502 --- h5p-default-storage.class.php | 25 +++++++++++++++++++++++++ h5p-file-storage.interface.php | 8 ++++++++ h5p.classes.php | 19 +++++++++++++++---- js/settings/h5p-disable-hub.js | 2 +- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index 0c67341..19cb2fe 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -386,6 +386,31 @@ class H5PDefaultStorage implements \H5PFileStorage { } } + /** + * Check if server setup has write permission to + * the required folders + * + * @return bool True if server has the proper write access + */ + public function hasWriteAccess() { + $dirs = array( + '/content', + '/libraries', + '/cachedassets', + '/temp', + '/editor', + '/exports' + ); + + // Check that directories are writable + $has_write_access = TRUE; + foreach ($dirs as $dir) { + $has_write_access = $has_write_access && self::dirReady($this->path . $dir); + } + + return $has_write_access; + } + /** * Recursive function for copying directories. * diff --git a/h5p-file-storage.interface.php b/h5p-file-storage.interface.php index 3c621f7..93ca771 100644 --- a/h5p-file-storage.interface.php +++ b/h5p-file-storage.interface.php @@ -171,4 +171,12 @@ interface H5PFileStorage { * @param int $contentId */ public function removeContentFile($file, $contentId); + + /** + * Check if server setup has write permission to + * the required folders + * + * @return bool True if server has the proper write access + */ + public function hasWriteAccess(); } diff --git a/h5p.classes.php b/h5p.classes.php index b1898fe..c4ad467 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2783,19 +2783,30 @@ class H5PCore { $this->h5pF->t('Your PHP version is outdated. H5P requires version 5.2 to function properly. Version 5.6 or later is recommended.'); } - $max_upload_size = ini_get('upload_max_filesize'); - $max_post_size = ini_get('post_max_size'); + // Check write access + if (!$this->fs->hasWriteAccess()) { + $errors[] = + $this->h5pF->t('A problem with the server write access was detected. Please make sure that your server can write to your data folder.'); + } + + $max_upload_size = self::returnBytes(ini_get('upload_max_filesize')); + $max_post_size = self::returnBytes(ini_get('post_max_size')); $byte_threshold = 5000000; // 5MB - if (self::returnBytes($max_upload_size) < $byte_threshold) { + if ($max_upload_size < $byte_threshold) { $errors[] = $this->h5pF->t('Your PHP max upload size option is too small. You should consider to increase it to more than 5MB.'); } - if (self::returnBytes($max_post_size) < $byte_threshold) { + if ($max_post_size < $byte_threshold) { $errors[] = $this->h5pF->t('Your PHP max post size option is too small. You should consider to increase it to more than 5MB.'); } + if ($max_upload_size > $max_post_size) { + $errors[] = + $this->h5pF->t('Your PHP max upload size is bigger than your max post size. This is known to cause issues in some installations.'); + } + // Check SSL if (!extension_loaded('openssl')) { $errors[] = diff --git a/js/settings/h5p-disable-hub.js b/js/settings/h5p-disable-hub.js index e78970a..7864695 100644 --- a/js/settings/h5p-disable-hub.js +++ b/js/settings/h5p-disable-hub.js @@ -60,7 +60,7 @@ var disableButton = $(H5PDisableHubData.selector); disableButton.change(function () { - if (!$(this).is(':checked')) { + if ($(this).is(':checked')) { confirmationDialog.show(disableButton.offset().top); } });