@@ -119,13 +119,16 @@ public function clear(/*string $prefix = ''*/)
119
119
}
120
120
}
121
121
$ namespaceToClear = $ this ->namespace .$ namespaceVersionToClear ;
122
- $ namespaceVersion = strtr ( substr_replace ( base64_encode ( pack ( ' V ' , mt_rand ())), static :: NS_SEPARATOR , 5 ), ' / ' , ' _ ' );
122
+ $ namespaceVersion = self :: formatNamespaceVersion ( mt_rand ());
123
123
try {
124
- $ cleared = $ this ->doSave ([static ::NS_SEPARATOR .$ this ->namespace => $ namespaceVersion ], 0 );
124
+ $ e = $ this ->doSave ([static ::NS_SEPARATOR .$ this ->namespace => $ namespaceVersion ], 0 );
125
125
} catch (\Exception $ e ) {
126
- $ cleared = false ;
127
126
}
128
- if ($ cleared = true === $ cleared || [] === $ cleared ) {
127
+ if (true !== $ e && [] !== $ e ){
128
+ $ cleared = false ;
129
+ $ message = 'Failed to save the new namespace ' .($ e instanceof \Exception ? ': ' .$ e ->getMessage () : '. ' );
130
+ CacheItem::log ($ this ->logger , $ message , ['exception ' => $ e instanceof \Exception ? $ e : null ]);
131
+ } else {
129
132
$ this ->namespaceVersion = $ namespaceVersion ;
130
133
$ this ->ids = [];
131
134
}
@@ -267,12 +270,17 @@ private function getId($key): string
267
270
foreach ($ this ->doFetch ([static ::NS_SEPARATOR .$ this ->namespace ]) as $ v ) {
268
271
$ this ->namespaceVersion = $ v ;
269
272
}
273
+ $ e = true ;
270
274
if ('1 ' .static ::NS_SEPARATOR === $ this ->namespaceVersion ) {
271
- $ this ->namespaceVersion = strtr ( substr_replace ( base64_encode ( pack ( ' V ' , time ())), static :: NS_SEPARATOR , 5 ), ' / ' , ' _ ' );
272
- $ this ->doSave ([static ::NS_SEPARATOR .$ this ->namespace => $ this ->namespaceVersion ], 0 );
275
+ $ this ->namespaceVersion = self :: formatNamespaceVersion ( time ());
276
+ $ e = $ this ->doSave ([static ::NS_SEPARATOR .$ this ->namespace => $ this ->namespaceVersion ], 0 );
273
277
}
274
278
} catch (\Exception $ e ) {
275
279
}
280
+ if (true !== $ e && [] !== $ e ){
281
+ $ message = 'Failed to save the new namespace ' .($ e instanceof \Exception ? ': ' .$ e ->getMessage () : '. ' );
282
+ CacheItem::log ($ this ->logger , $ message , ['exception ' => $ e instanceof \Exception ? $ e : null ]);
283
+ }
276
284
}
277
285
278
286
if (\is_string ($ key ) && isset ($ this ->ids [$ key ])) {
@@ -304,4 +312,9 @@ public static function handleUnserializeCallback($class)
304
312
{
305
313
throw new \DomainException ('Class not found: ' .$ class );
306
314
}
315
+
316
+ private static function formatNamespaceVersion ($ value )
317
+ {
318
+ return strtr (substr_replace (base64_encode (pack ('V ' , $ value )), static ::NS_SEPARATOR , 5 ), '/ ' , '_ ' );
319
+ }
307
320
}
0 commit comments