Skip to content

Commit

Permalink
Merge pull request #546 from AcclaroInc/release/4.0.5
Browse files Browse the repository at this point in the history
Release/4.0.5
  • Loading branch information
bhupeshappfoster authored Dec 31, 2024
2 parents b0feeb0 + f9ddf5b commit db9c933
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 24 additions & 23 deletions src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
}
Expand All @@ -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
Expand All @@ -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');
Expand All @@ -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
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/services/repository/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit db9c933

Please sign in to comment.