Permalink
Browse files

fix(memcache): don't store a copy of $CONFIG in file objects

Since filestore objects keep a copy of $CONFIG as a property, this would
get serialized with the ElggFile. We add a __sleep method to filter out
this property when serializing, and __wakeup to reinitialize it.

Fixes #9081
  • Loading branch information...
mrclay committed Nov 5, 2015
1 parent 45688ef commit beb9089129a0a06b36200f3f8d214c7ed8f94f42
Showing with 26 additions and 0 deletions.
  1. +26 −0 engine/classes/ElggFile.php
@@ -446,4 +446,30 @@ public function save() {
return true;
}
+
+ /**
+ * Get property names to serialize.
+ *
+ * @return string[]
+ */
+ public function __sleep() {
+ return array_diff(array_keys(get_object_vars($this)), array(
+ // Don't persist filestore, which contains CONFIG
+ // https://github.com/Elgg/Elgg/issues/9081#issuecomment-152859856
+ 'filestore',
+
+ // a resource
+ 'handle',
+ ));
+ }
+
+ /**
+ * Reestablish filestore property
+ *
+ * @return void
+ * @throws ClassNotFoundException
+ */
+ public function __wakeup() {
+ $this->getFilestore();
+ }
}

0 comments on commit beb9089

Please sign in to comment.