@@ -62,6 +62,8 @@ abstract public function supports(MigrationContextInterface $migrationContext):
6262 */
6363 public function process (MigrationContextInterface $ migrationContext , Context $ context , array $ workload ): array
6464 {
65+ $ connection = $ migrationContext ->getConnection ();
66+
6567 // Map workload with uuids as keys
6668 $ mappedWorkload = [];
6769 foreach ($ workload as $ work ) {
@@ -76,15 +78,16 @@ public function process(MigrationContextInterface $migrationContext, Context $co
7678 if ($ client === null ) {
7779 $ this ->loggingService ->addLogEntry (new ExceptionRunLog (
7880 $ migrationContext ->getRunUuid (),
79- $ this ->getMediaEntity (),
81+ $ connection ->getProfileName (),
82+ $ connection ->getGatewayName (),
8083 new \Exception ('Http download client can not be constructed. ' )
8184 ));
8285 $ this ->loggingService ->saveLogging ($ context );
8386
8487 return $ workload ;
8588 }
8689 // Do download requests and store the promises
87- $ promises = $ this ->doMediaDownloadRequests ($ media , $ mappedWorkload , $ client );
90+ $ promises = $ this ->doMediaDownloadRequests ($ migrationContext , $ media , $ mappedWorkload , $ client );
8891
8992 // Wait for the requests to complete, even if some of them fail
9093 /** @var array<string, array{'state': string, 'value': ResponseInterface, 'reason': ?RequestException}> $results */
@@ -119,8 +122,8 @@ function (MediaProcessWorkloadStruct $work) use ($uuid) {
119122 $ work ->setState (MediaProcessWorkloadStruct::ERROR_STATE );
120123 $ this ->loggingService ->addLogEntry (new CannotGetFileRunLog (
121124 $ work ->getRunId (),
122- $ this -> getMediaEntity (),
123- $ work -> getMediaId (),
125+ $ connection -> getProfileName (),
126+ $ connection -> getGatewayName (),
124127 $ work ->getAdditionalData ()['uri ' ],
125128 $ result ['reason ' ] ?? null
126129 ));
@@ -140,8 +143,8 @@ function (MediaProcessWorkloadStruct $work) use ($uuid) {
140143 $ work ->setState (MediaProcessWorkloadStruct::ERROR_STATE );
141144 $ this ->loggingService ->addLogEntry (new TemporaryFileErrorLog (
142145 $ work ->getRunId (),
143- $ this -> getMediaEntity (),
144- $ uuid
146+ $ connection -> getProfileName (),
147+ $ connection -> getGatewayName (),
145148 ));
146149
147150 continue ;
@@ -181,9 +184,9 @@ function (MediaProcessWorkloadStruct $work) use ($uuid) {
181184 $ work ->setState (MediaProcessWorkloadStruct::ERROR_STATE );
182185 $ this ->loggingService ->addLogEntry (new ExceptionRunLog (
183186 $ work ->getRunId (),
184- $ this ->getMediaEntity (),
187+ $ connection ->getProfileName (),
188+ $ connection ->getGatewayName (),
185189 $ e ,
186- $ uuid
187190 ));
188191 } finally {
189192 // clear up temp data
@@ -246,7 +249,7 @@ final protected function getDataSetEntity(MigrationContextInterface $migrationCo
246249 *
247250 * @return array<string, PromiseInterface>
248251 */
249- private function doMediaDownloadRequests (array $ media , array &$ mappedWorkload , HttpClientInterface $ client ): array
252+ private function doMediaDownloadRequests (MigrationContextInterface $ migrationContext , array $ media , array &$ mappedWorkload , HttpClientInterface $ client ): array
250253 {
251254 $ promises = [];
252255 foreach ($ media as $ mediaFile ) {
@@ -256,7 +259,7 @@ private function doMediaDownloadRequests(array $media, array &$mappedWorkload, H
256259 $ additionalData ['uri ' ] = $ mediaFile ['uri ' ];
257260 $ mappedWorkload [$ uuid ]->setAdditionalData ($ additionalData );
258261
259- $ promise = $ this ->doNormalDownloadRequest ($ mappedWorkload [$ uuid ], $ client );
262+ $ promise = $ this ->doNormalDownloadRequest ($ migrationContext , $ mappedWorkload [$ uuid ], $ client );
260263
261264 if ($ promise !== null ) {
262265 $ promises [$ uuid ] = $ promise ;
@@ -266,7 +269,7 @@ private function doMediaDownloadRequests(array $media, array &$mappedWorkload, H
266269 return $ promises ;
267270 }
268271
269- private function doNormalDownloadRequest (MediaProcessWorkloadStruct $ workload , HttpClientInterface $ client ): ?PromiseInterface
272+ private function doNormalDownloadRequest (MigrationContextInterface $ migrationContext , MediaProcessWorkloadStruct $ workload , HttpClientInterface $ client ): ?PromiseInterface
270273 {
271274 $ additionalData = $ workload ->getAdditionalData ();
272275
@@ -276,12 +279,14 @@ private function doNormalDownloadRequest(MediaProcessWorkloadStruct $workload, H
276279 $ workload ->setCurrentOffset ((int ) $ additionalData ['file_size ' ]);
277280 $ workload ->setState (MediaProcessWorkloadStruct::FINISH_STATE );
278281 } catch (\Throwable $ exception ) {
282+ $ connection = $ migrationContext ->getConnection ();
283+
279284 // this should never happen because of Promises, but just in case something is wrong with request construction
280285 $ this ->loggingService ->addLogEntry (new ExceptionRunLog (
281286 $ workload ->getRunId (),
282- $ this ->getMediaEntity (),
287+ $ connection ->getProfileName (),
288+ $ connection ->getGatewayName (),
283289 $ exception ,
284- $ workload ->getMediaId ()
285290 ));
286291
287292 $ promise = null ;
@@ -296,16 +301,20 @@ private function persistFileToMedia(string $filePath, string $uuid, string $name
296301 // determine correct info about the temporary file, except for the $fileExtension (which can be overridden)
297302 $ fileSize = \filesize ($ filePath );
298303 $ mimeType = \mime_content_type ($ filePath );
304+
299305 if ($ fileSize === false || $ fileSize === 0 || $ mimeType === false ) {
306+ $ connection = $ migrationContext ->getConnection ();
307+
300308 $ this ->loggingService ->addLogEntry (new ExceptionRunLog (
301309 $ migrationContext ->getRunUuid (),
302- $ this ->getMediaEntity (),
310+ $ connection ->getProfileName (),
311+ $ connection ->getGatewayName (),
303312 new \Exception ('Downloaded file is empty or could not determine mime type. ' ),
304- $ uuid
305313 ));
306314
307315 return ;
308316 }
317+
309318 $ fileHash = \hash_file ('md5 ' , $ filePath );
310319 $ mediaFile = new MediaFile (
311320 $ filePath ,
@@ -331,11 +340,13 @@ private function persistFileToMedia(string $filePath, string $uuid, string $name
331340 } elseif (\in_array ($ mediaException ->getErrorCode (), [MediaException::MEDIA_ILLEGAL_FILE_NAME , MediaException::MEDIA_EMPTY_FILE_NAME ], true )) {
332341 $ this ->fileSaver ->persistFileToMedia ($ mediaFile , Uuid::randomHex (), $ uuid , $ context );
333342 } else {
343+ $ connection = $ migrationContext ->getConnection ();
344+
334345 $ this ->loggingService ->addLogEntry (new ExceptionRunLog (
335346 $ migrationContext ->getRunUuid (),
336- $ this ->getMediaEntity (),
347+ $ connection ->getProfileName (),
348+ $ connection ->getGatewayName (),
337349 $ mediaException ,
338- $ uuid
339350 ));
340351 }
341352 }
0 commit comments