From 40c46c8978341c4285c97027960568e3e081ef03 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Fri, 28 Jun 2024 16:24:33 -0400 Subject: [PATCH 1/5] Remove verbose logging --- src/runtime/event/SqsHandler.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/runtime/event/SqsHandler.php b/src/runtime/event/SqsHandler.php index b87267a..57119b8 100644 --- a/src/runtime/event/SqsHandler.php +++ b/src/runtime/event/SqsHandler.php @@ -18,10 +18,7 @@ public function handleSqs(SqsEvent $event, Context $context): void $this->context = $context; $records = Collection::make($event->getRecords()); - echo "Processing SQS event with {$records->count()} records."; - $records->each(function(SqsRecord $record) { - echo "Handling SQS message: #{$record->getMessageId()}"; $cliHandler = new CliHandler(); $body = json_decode( $record->getBody(), @@ -39,8 +36,6 @@ public function handleSqs(SqsEvent $event, Context $context): void 'command' => "cloud/queue/exec {$jobId}", ], $this->context, true); } catch (ProcessFailedException $e) { - echo "Job #$jobId failed and WILL NOT be retried:\n"; - echo "Message: #{$record->getMessageId()}\n"; echo $e->getMessage(); $this->failJob( @@ -50,17 +45,12 @@ public function handleSqs(SqsEvent $event, Context $context): void ); } catch (ProcessTimedOutException $e) { if ($cliHandler->shouldRetry()) { - echo "Job #$jobId timed out and WILL be retried via markAsFailed:\n"; - echo "Message: #{$record->getMessageId()}\n"; echo $e->getMessage(); $this->markAsFailed($record); return; } - echo "Job #$jobId timed out and WILL NOT be retried:\n"; - echo "Message: #{$record->getMessageId()}\n"; - echo "Running Time: {$cliHandler->getTotalRunningTime()} seconds\n"; echo $e->getMessage(); $this->failJob( @@ -69,12 +59,8 @@ public function handleSqs(SqsEvent $event, Context $context): void 'Job exceeded maximum running time: 15 minutes', ); } catch (\Throwable $e) { - echo "Job #$jobId threw and WILL be retried via markAsFailed:\n"; - echo "Message: #{$record->getMessageId()}\n"; echo $e->getMessage(); $this->markAsFailed($record); - } finally { - echo "Done processing job #$jobId (finally)."; } }); } @@ -86,7 +72,6 @@ protected function failJob(string $jobId, SqsRecord $record , string $message = 'command' => "cloud/queue/fail {$jobId} --message={$message}", ], $this->context, true); } catch (\Throwable $e) { - echo "Exception thrown running cloud/queue/fail:\n"; echo $e->getMessage(); // Attempt to retry the whole message From cf593341bad651a74de25c5147f6dfdf295973d6 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Fri, 28 Jun 2024 16:25:09 -0400 Subject: [PATCH 2/5] Default fit mode should always be crop --- src/ImageTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageTransformer.php b/src/ImageTransformer.php index 86404ce..c676a79 100644 --- a/src/ImageTransformer.php +++ b/src/ImageTransformer.php @@ -114,7 +114,7 @@ private function getFitValue(ImageTransform $imageTransform): string 'fit' => $imageTransform->upscale ? 'contain' : 'scale-down', 'stretch' => 'cover', 'letterbox' => 'pad', - default => $imageTransform->upscale ? 'cover' : 'crop', + default => 'crop', }; } From 0cd1c0e8ef01c6d64d1491573d3cddf9d0126e90 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Wed, 24 Jul 2024 16:32:09 -0400 Subject: [PATCH 3/5] Fix toast error on asset replace --- src/controllers/AssetsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/AssetsController.php b/src/controllers/AssetsController.php index 75e125f..a13b379 100644 --- a/src/controllers/AssetsController.php +++ b/src/controllers/AssetsController.php @@ -350,7 +350,7 @@ public function replaceAssetFile(Asset $asset, string $filename, string $targetF // Try again, in case the resulting filename has a tmp suffix from `avoidFilenameConflicts` if ($saved && $oldPath !== $asset->getPath()) { $asset->newFilename = $targetFilename; - $saved = Craft::$app->getElements()->saveElement($asset); + $saved = $this->saveAsset($asset); } if ($assets->hasEventHandlers($assets::EVENT_AFTER_REPLACE_ASSET)) { From 4b5299f793b5200b54adbd8657faa305f3e66148 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Wed, 24 Jul 2024 20:22:06 -0400 Subject: [PATCH 4/5] Update dimensions and updated on replace --- src/controllers/AssetsController.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/controllers/AssetsController.php b/src/controllers/AssetsController.php index a13b379..01d921e 100644 --- a/src/controllers/AssetsController.php +++ b/src/controllers/AssetsController.php @@ -235,6 +235,14 @@ public function actionReplaceFile(): Response $sourceAssetId = $this->request->getBodyParam('sourceAssetId'); $filename = $this->request->getBodyParam('filename'); $targetFilename = $this->request->getBodyParam('targetFilename'); + $size = $this->request->getBodyParam('size'); + $width = $this->request->getBodyParam('width'); + $height = $this->request->getBodyParam('height'); + $lastModifiedMs = (int) $this->request->getBodyParam('lastModified'); + $dateModified = $lastModifiedMs + ? DateTime::createFromFormat('U', (string) floor($lastModifiedMs / 1000)) + : new DateTime(); + $assets = Craft::$app->getAssets(); // Must have at least one existing asset (source or target). @@ -260,6 +268,10 @@ public function actionReplaceFile(): Response // Handle the Element Action if ($assetToReplace !== null && $filename) { + $assetToReplace->width = $width; + $assetToReplace->height = $height; + $assetToReplace->size = $size; + $assetToReplace->dateModified = $dateModified; if (!$this->replaceAssetFile($assetToReplace, $filename, $targetFilename)) { throw new Exception('Unable to replace asset.'); } From a7e02638676fdc23989b4905012c97f45d047307 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Wed, 24 Jul 2024 20:22:24 -0400 Subject: [PATCH 5/5] Fix logic when replacing asset with same name --- src/controllers/AssetsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/AssetsController.php b/src/controllers/AssetsController.php index 01d921e..9bf355d 100644 --- a/src/controllers/AssetsController.php +++ b/src/controllers/AssetsController.php @@ -360,7 +360,7 @@ public function replaceAssetFile(Asset $asset, string $filename, string $targetF $asset->getVolume()->deleteFile($oldPath); // Try again, in case the resulting filename has a tmp suffix from `avoidFilenameConflicts` - if ($saved && $oldPath !== $asset->getPath()) { + if ($saved && $targetFilename !== $asset->getFilename()) { $asset->newFilename = $targetFilename; $saved = $this->saveAsset($asset); }