Avoid getWithSetCallback() warnings on unversioned key migration
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 8 Jun 2016 17:25:25 +0000 (10:25 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 8 Jun 2016 17:25:25 +0000 (10:25 -0700)
If an unversioned key is present, this generated a warning
previously.

Bug: T137244
Change-Id: I92df9b9fe0436348b5b27e684d239238d57c9b5f

includes/libs/objectcache/WANObjectCache.php

index f12cb4c..45713cc 100644 (file)
@@ -800,7 +800,15 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                                        $key,
                                        $ttl,
                                        function ( $oldValue, &$ttl, &$setOpts ) use ( $callback, $version ) {
-                                               $oldData = $oldValue ? $oldValue[self::VFLD_DATA] : false;
+                                               if ( is_array( $oldValue )
+                                                       && array_key_exists( self::VFLD_DATA, $oldValue )
+                                               ) {
+                                                       $oldData = $oldValue[self::VFLD_DATA];
+                                               } else {
+                                                       // VFLD_DATA is not set if an old, unversioned, key is present
+                                                       $oldData = false;
+                                               }
+
                                                return [
                                                        self::VFLD_DATA => $callback( $oldData, $ttl, $setOpts ),
                                                        self::VFLD_VERSION => $version