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', }; } diff --git a/src/controllers/AssetsController.php b/src/controllers/AssetsController.php index 75e125f..9bf355d 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.'); } @@ -348,9 +360,9 @@ 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 = Craft::$app->getElements()->saveElement($asset); + $saved = $this->saveAsset($asset); } if ($assets->hasEventHandlers($assets::EVENT_AFTER_REPLACE_ASSET)) { 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