9use InvalidArgumentException;
43 if ( !$this->repo->isSplitMetadataEnabled()
44 || !$file->getHandler()
45 || !$file->getHandler()->useSplitMetadata()
49 $threshold = $this->repo->getSplitMetadataThreshold();
50 if ( !$threshold || strlen( $s ) <= $threshold ) {
53 $blobStore = $this->repo->getBlobStore();
61 foreach ( $envelope[
'data'] as $name => $value ) {
63 if ( strlen( $encoded ) > $threshold ) {
64 $blobAddresses[$name] = $blobStore->storeBlob(
71 $envelope[
'data'] = array_diff_key( $envelope[
'data'], $blobAddresses );
72 $envelope[
'blobs'] = $blobAddresses;
75 return [ $s, $blobAddresses ];
85 $s = json_encode( $data,
86 JSON_INVALID_UTF8_IGNORE |
87 JSON_UNESCAPED_SLASHES |
88 JSON_UNESCAPED_UNICODE );
90 throw new InvalidArgumentException( __METHOD__ .
': metadata is not JSON-serializable ' );
98 $blobStore = $this->repo->getBlobStore();
100 LoggerFactory::getInstance(
'LocalFile' )->warning(
101 "Unable to load metadata: repo has no blob store" );
104 $status = $blobStore->getBlobBatch( $addresses );
105 if ( !$status->isGood() ) {
106 $msg = Status::wrap( $status )->getWikiText(
107 false,
false,
'en' );
108 LoggerFactory::getInstance(
'LocalFile' )->warning(
109 "Error loading metadata from BlobStore: $msg" );
111 foreach ( $addresses as $itemName => $address ) {
112 $json = $status->getValue()[$address] ??
null;
113 if ( $json !==
null ) {
114 $value = $this->jsonDecode( $json );
115 $result[$itemName] = $value;
135 return @json_decode( $s,
true, 512, JSON_INVALID_UTF8_IGNORE );
141class_alias( MetadataStorageHelper::class,
'MetadataStorageHelper' );