@@ -13,25 +13,51 @@ public function __construct(private readonly Filesystem $filesystem)
1313 {
1414 }
1515
16- public function save (?int $ jobId , ?array $ exceptions ): void
16+ /** @inheritDoc */
17+ public function save (?int $ jobId , $ exceptions ): void
1718 {
18- if ($ jobId === null || empty ($ exceptions) ) {
19+ if ($ jobId === null || stream_get_contents ($ exceptions, 1 ) === false ) {
1920 return ;
2021 }
2122
22- $ this ->filesystem ->write (\sprintf ('dataflow-job-%s.log ' , $ jobId ), json_encode ($ exceptions ));
23+ $ path = \sprintf ('dataflow-job-%s.log ' , $ jobId );
24+ rewind ($ exceptions );
25+
26+ if ($ this ->filesystem ->fileExists ($ path )) {
27+ $ existingStream = $ this ->filesystem ->readStream ($ path );
28+
29+ $ combined = fopen ('php://temp ' , 'r+ ' );
30+
31+ stream_copy_to_stream ($ existingStream , $ combined );
32+ stream_copy_to_stream ($ exceptions , $ combined );
33+
34+ rewind ($ combined );
35+
36+ $ this ->filesystem ->delete ($ path );
37+ $ this ->filesystem ->writeStream ($ path , $ combined );
38+
39+ fclose ($ existingStream );
40+ fclose ($ combined );
41+
42+ return ;
43+ }
44+
45+ $ this ->filesystem ->writeStream ($ path , $ exceptions );
46+
47+ fclose ($ exceptions );
2348 }
2449
25- public function find (int $ jobId ): ?array
50+ /** @inheritDoc */
51+ public function find (int $ jobId )
2652 {
2753 try {
2854 if (!$ this ->filesystem ->fileExists (\sprintf ('dataflow-job-%s.log ' , $ jobId ))) {
29- return [] ;
55+ return null ;
3056 }
3157
32- return json_decode ( $ this ->filesystem ->read (\sprintf ('dataflow-job-%s.log ' , $ jobId )), true );
58+ return $ this ->filesystem ->readStream (\sprintf ('dataflow-job-%s.log ' , $ jobId ));
3359 } catch (FilesystemException ) {
34- return [] ;
60+ return null ;
3561 }
3662 }
3763
0 commit comments