23use InvalidArgumentException;
57 if ( !$this->repo->isSplitMetadataEnabled()
58 || !$file->getHandler()
59 || !$file->getHandler()->useSplitMetadata()
63 $threshold = $this->repo->getSplitMetadataThreshold();
64 if ( !$threshold || strlen( $s ) <= $threshold ) {
67 $blobStore = $this->repo->getBlobStore();
75 foreach ( $envelope[
'data'] as $name => $value ) {
77 if ( strlen( $encoded ) > $threshold ) {
78 $blobAddresses[$name] = $blobStore->storeBlob(
85 $envelope[
'data'] = array_diff_key( $envelope[
'data'], $blobAddresses );
86 $envelope[
'blobs'] = $blobAddresses;
89 return [ $s, $blobAddresses ];
99 $s = json_encode( $data,
100 JSON_INVALID_UTF8_IGNORE |
101 JSON_UNESCAPED_SLASHES |
102 JSON_UNESCAPED_UNICODE );
103 if ( $s ===
false ) {
104 throw new InvalidArgumentException( __METHOD__ .
': metadata is not JSON-serializable ' );
112 $blobStore = $this->repo->getBlobStore();
114 LoggerFactory::getInstance(
'LocalFile' )->warning(
115 "Unable to load metadata: repo has no blob store" );
118 $status = $blobStore->getBlobBatch( $addresses );
119 if ( !$status->isGood() ) {
120 $msg = Status::wrap( $status )->getWikiText(
121 false,
false,
'en' );
122 LoggerFactory::getInstance(
'LocalFile' )->warning(
123 "Error loading metadata from BlobStore: $msg" );
125 foreach ( $addresses as $itemName => $address ) {
126 $json = $status->getValue()[$address] ??
null;
127 if ( $json !==
null ) {
128 $value = $this->jsonDecode( $json );
129 $result[$itemName] = $value;
149 return @json_decode( $s,
true, 512, JSON_INVALID_UTF8_IGNORE );
155class_alias( MetadataStorageHelper::class,
'MetadataStorageHelper' );