Fix Status serialization with cleanupCallback as Closure
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 3 Oct 2014 15:57:31 +0000 (11:57 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Fri, 3 Oct 2014 16:02:20 +0000 (12:02 -0400)
We already have Status objects throw away the cleanupCallback in
__wakeup. Why not also implement __sleep to not save it in the first
place?

The immediate motivation here is that cleanupCallback could be a
Closure, which causes an exception when serialization is attempted (e.g.
when trying to save the Status if an AssembleUploadChunks job fails
verification).

Note this leaves __wakeup intact, in case of old objects where
cleanupCallback is still present in the serialized representation.

Change-Id: I3aa756cd4eb5553ce0b95e7088b929b2f529abfe

includes/Status.php

index 2a9d173..0a8062c 100644 (file)
@@ -159,6 +159,15 @@ class Status {
                $this->ok = false;
        }
 
+       /**
+        * Don't save the callback when serializing, because Closures can't be
+        * serialized and we're going to clear it in __wakeup anyway.
+        */
+       public function __sleep() {
+               $keys = array_keys( get_object_vars( $this ) );
+               return array_diff( $keys, array( 'cleanCallback' ) );
+       }
+
        /**
         * Sanitize the callback parameter on wakeup, to avoid arbitrary execution.
         */