77
88namespace DataMachineCode \Storage ;
99
10+ use DataMachineCode \Support \JsonCodec ;
11+
1012defined ('ABSPATH ' ) || exit;
1113
14+ if ( ! class_exists (JsonCodec::class) ) {
15+ require_once dirname (__DIR__ ) . '/Support/JsonCodec.php ' ;
16+ }
17+
1218class WorktreeInventoryRepository {
1319
1420
@@ -276,7 +282,7 @@ private function normalize_row( array $row ): array {
276282 'size_bytes ' => isset ($ row ['size_bytes ' ]) ? ( null === $ row ['size_bytes ' ] ? null : (int ) $ row ['size_bytes ' ] ) : null ,
277283 'cleanup_signal ' => $ this ->cleanup_signal ($ row , $ metadata ),
278284 'missing_path ' => ! empty ($ row ['missing_path ' ]) ? 1 : 0 ,
279- 'metadata ' => wp_json_encode ($ metadata ),
285+ 'metadata ' => JsonCodec:: encode_or_default ($ metadata ),
280286 'updated_at ' => current_time ('mysql ' , true ),
281287 );
282288 }
@@ -288,8 +294,7 @@ private function normalize_row( array $row ): array {
288294 * @return array<string,mixed>
289295 */
290296 private function decode_row ( array $ row ): array {
291- $ decoded = isset ($ row ['metadata ' ]) && is_string ($ row ['metadata ' ]) ? json_decode ($ row ['metadata ' ], true ) : null ;
292- $ row ['metadata ' ] = is_array ($ decoded ) ? $ decoded : null ;
297+ $ row ['metadata ' ] = isset ($ row ['metadata ' ]) && is_string ($ row ['metadata ' ]) ? JsonCodec::decode_array ($ row ['metadata ' ], null ) : null ;
293298 foreach ( array ( 'id ' , 'is_primary ' , 'dirty_count ' , 'unpushed_count ' , 'artifact_count ' , 'artifact_size_bytes ' , 'size_bytes ' , 'missing_path ' ) as $ key ) {
294299 if ( isset ($ row [ $ key ]) ) {
295300 $ row [ $ key ] = (int ) $ row [ $ key ];
0 commit comments