From 8a310479e81517fcf931b9ffdf76001443088a2a Mon Sep 17 00:00:00 2001 From: Bhupesh Pandey Date: Tue, 31 Dec 2024 13:07:59 +0530 Subject: [PATCH 1/3] fixed: headers already sent error --- src/controllers/BaseController.php | 47 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/controllers/BaseController.php b/src/controllers/BaseController.php index 700c6648..d4f94747 100644 --- a/src/controllers/BaseController.php +++ b/src/controllers/BaseController.php @@ -55,18 +55,18 @@ public function __construct( public function actionOrderCallback() { - $this->logIncomingRequest('orderCallback'); - Craft::$app->getResponse()->headers->set('Content-Type', 'text/plain'); + + $this->logIncomingRequest('orderCallback'); $key = sha1_file(Craft::$app->path->getConfigPath().'/license.key'); + $output = ''; if (Craft::$app->request->getRequiredQueryParam('key') !== $key) { - echo $key.PHP_EOL; - Craft::$app->end('Invalid key'); + $output .= $key.PHP_EOL.'Invalid key'; + Craft::$app->end($output); } else { - echo $key.PHP_EOL; - echo 'Valid key'.PHP_EOL; + $output .= "Valid key: $key".PHP_EOL; } $orderId = Craft::$app->request->getRequiredQueryParam('orderId'); @@ -80,7 +80,7 @@ public function actionOrderCallback() if (!$order) { Craft::$app->end('Invalid orderId'); } else { - echo 'Order found'.PHP_EOL; + $output .= 'Order found'.PHP_EOL; $order->logActivity('Order callback received.'); Craft::$app->getElements()->saveElement($order); } @@ -100,20 +100,20 @@ public function actionOrderCallback() if (!$translationService) { Craft::$app->end('Couldn’t find the translation service'); } else { - echo 'Translation service found'.PHP_EOL; + $output .= 'Translation service found'.PHP_EOL; } $translationService->updateOrder($order); - echo 'Updating order'.PHP_EOL; + $output .= 'Updating order'.PHP_EOL; $success = Craft::$app->getElements()->saveElement($order); if (!$success) { Craft::$app->end('Couldn’t save the order'); } else { - echo 'Order changes saved'.PHP_EOL; - echo 'Starting file sync' . PHP_EOL; + $output .= 'Order changes saved'.PHP_EOL; + $output .= 'Starting file sync' . PHP_EOL; foreach($order->getFiles() as $file) { // Only process the file is not already done @@ -123,24 +123,25 @@ public function actionOrderCallback() } } - echo 'File sync successful' . PHP_EOL; + $output .= 'File sync successful' . PHP_EOL; } - Craft::$app->end('OK'); + Craft::$app->end("$output OK"); } public function actionFileCallback() { - $this->logIncomingRequest('fileCallback'); - Craft::$app->getResponse()->headers->set('Content-Type', 'text/plain'); + $this->logIncomingRequest('fileCallback'); + $key = sha1_file(Craft::$app->path->getConfigPath().'/license.key'); + $output = ''; if (Craft::$app->request->getQueryParam('key') !== $key) { Craft::$app->end('Invalid key'); } else { - echo 'Valid key'.PHP_EOL; + $output .= 'Valid key'.PHP_EOL; } $fileId = Craft::$app->request->getRequiredQueryParam('fileId'); @@ -150,7 +151,7 @@ public function actionFileCallback() if (!$file) { Craft::$app->end('Couldn’t find the file'); } else { - echo 'Found file'.PHP_EOL; + $output .= 'Found file'.PHP_EOL; } // don't process published files @@ -168,7 +169,7 @@ public function actionFileCallback() if (!$order) { Craft::$app->end('Couldn’t find the order'); } else { - echo 'Found order'.PHP_EOL; + $output .= 'Found order'.PHP_EOL; $order->logActivity('File callback received.'); Craft::$app->getElements()->saveElement($order); } @@ -178,10 +179,10 @@ public function actionFileCallback() if (!$translationService) { Craft::$app->end('Couldn’t find the translation service'); } else { - echo 'Translation service found'.PHP_EOL; + $output .= 'Translation service found'.PHP_EOL; } - echo 'Updating file'.PHP_EOL; + $output .= 'Updating file'.PHP_EOL; // Skip if file already has target content if ($file->isNew() || $file->isInProgress()) { $translationService->updateFile($order, $file); @@ -191,13 +192,13 @@ public function actionFileCallback() if (!$success) { Craft::$app->end('Couldn’t save the file'); } else { - echo 'File saved'.PHP_EOL; + $output .= 'File saved'.PHP_EOL; } } else { - echo 'File skipped'.PHP_EOL; + $output .= 'File skipped'.PHP_EOL; } - Craft::$app->end('OK'); + Craft::$app->end("$output OK"); } public function actionAddElementsToOrder() From d49d806258ac8ef3e249a2af394ae637a80f9910 Mon Sep 17 00:00:00 2001 From: Bhupesh Pandey <72725957+bhupeshappfoster@users.noreply.github.com> Date: Tue, 31 Dec 2024 13:14:18 +0530 Subject: [PATCH 2/3] fixed: error adding entry to existing order (#545) --- src/services/repository/FileRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/repository/FileRepository.php b/src/services/repository/FileRepository.php index 31e889d1..a636cac9 100644 --- a/src/services/repository/FileRepository.php +++ b/src/services/repository/FileRepository.php @@ -351,7 +351,7 @@ public function createOrderFiles($order, $wordCounts) public function createOrderFile($order, $elementId, $targetSite) { - $element = Translations::$plugin->elementRepository->getElementById($elementId); + $element = Translations::$plugin->elementRepository->getElementById($elementId, $order->sourceSite); $wordCount = Translations::$plugin->elementTranslator->getWordCount($element) ?? 0; $file = $this->makeNewFile(); From f9ddf5ba9d1143a913e163e96223b078ab059253 Mon Sep 17 00:00:00 2001 From: Bhupesh Pandey Date: Tue, 31 Dec 2024 13:21:35 +0530 Subject: [PATCH 3/3] updated: change logs & version bumped --- .craftplugin | 2 +- CHANGELOG.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.craftplugin b/.craftplugin index 233acd93..a0630bc5 100644 --- a/.craftplugin +++ b/.craftplugin @@ -1,7 +1,7 @@ { "pluginName": "Translations for Craft", "pluginDescription": "Drive global growth with simplified translation workflows.", - "pluginVersion": "v4.0.4", + "pluginVersion": "v4.0.5", "pluginAuthorName": "Acclaro", "pluginVendorName": "Acclaro", "pluginAuthorUrl": "http://www.acclaro.com/", diff --git a/CHANGELOG.md b/CHANGELOG.md index a0204dc2..d425cba2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 4.0.5 - 2024-12-31 + +### Fixed +- Headers already sent error. ([AcclaroInc#573](https://github.com/AcclaroInc/pm-craft-translations/issues/573)) +- Error adding entry to existing order. ([AcclaroInc#538](https://github.com/AcclaroInc/craft-translations/issues/538)) + ## 4.0.4 - 2024-12-17 ### Fixed