Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'wip-MDL-39456-m25' of git://github.com/samhemelryk/mood…

…le into MOODLE_25_STABLE
  • Loading branch information...
commit 4f0d6118ffc39f3eca143ef2c3665da2d8b40781 2 parents 8b77e81 + e5184ca
@stronk7 stronk7 authored
Showing with 34 additions and 0 deletions.
  1. +34 −0 cache/stores/file/lib.php
View
34 cache/stores/file/lib.php
@@ -102,6 +102,19 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i
protected $definition;
/**
+ * A reference to the global $CFG object.
+ *
+ * You may be asking yourself why on earth this is here, but there is a good reason.
+ * By holding onto a reference of the $CFG object we can be absolutely sure that it won't be destroyed before
+ * we are done with it.
+ * This makes it possible to use a cache within a destructor method for the purposes of
+ * delayed writes. Like how the session mechanisms work.
+ *
+ * @var stdClass
+ */
+ private $cfg = null;
+
+ /**
* Constructs the store instance.
*
* Noting that this function is not an initialisation. It is used to prepare the store for use.
@@ -111,6 +124,13 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i
* @param array $configuration
*/
public function __construct($name, array $configuration = array()) {
+ global $CFG;
+
+ if (isset($CFG)) {
+ // Hold onto a reference of the global $CFG object.
+ $this->cfg = $CFG;
+ }
+
$this->name = $name;
if (array_key_exists('path', $configuration) && $configuration['path'] !== '') {
$this->custompath = true;
@@ -605,13 +625,27 @@ public static function config_set_edit_form_data(moodleform $editform, array $co
* @throws coding_exception
*/
protected function ensure_path_exists() {
+ global $CFG;
if (!is_writable($this->path)) {
if ($this->custompath && !$this->autocreate) {
throw new coding_exception('File store path does not exist. It must exist and be writable by the web server.');
}
+ $createdcfg = false;
+ if (!isset($CFG)) {
+ // This can only happen during destruction of objects.
+ // A cache is being used within a destructor, php is ending a request and $CFG has
+ // already being cleaned up.
+ // Rebuild $CFG with directory permissions just to complete this write.
+ $CFG = $this->cfg;
+ $createdcfg = true;
+ }
if (!make_writable_directory($this->path, false)) {
throw new coding_exception('File store path does not exist and can not be created.');
}
+ if ($createdcfg) {
+ // We re-created it so we'll clean it up.
+ unset($CFG);
+ }
}
return true;
}
Please sign in to comment.
Something went wrong with that request. Please try again.