diff --git a/.craftplugin b/.craftplugin index 07dd294f..121691a4 100644 --- a/.craftplugin +++ b/.craftplugin @@ -1,7 +1,7 @@ { "pluginName": "Translations for Craft", "pluginDescription": "Drive global growth with simplified translation workflows.", - "pluginVersion": "2.2.3", + "pluginVersion": "2.2.4", "pluginAuthorName": "Acclaro", "pluginVendorName": "Acclaro", "pluginAuthorUrl": "http://www.acclaro.com/", diff --git a/.github/workflows/discord-notify.yml b/.github/workflows/discord-notify.yml index c50e1744..5cb08a61 100644 --- a/.github/workflows/discord-notify.yml +++ b/.github/workflows/discord-notify.yml @@ -6,7 +6,7 @@ name: Discord Notification # events but only for the main branch on: push: - branches: [ master ] + branches: [ craft3 ] # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -15,8 +15,8 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - uses: fateyan/action-discord-notifier@v1.2.0 with: - message-title: New Deploy for Craft Translations + message-title: New Deploy for Craft(3) Translations webhook: ${{ secrets.DISCORD_WEBHOOK }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f571f35..fe028814 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ 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/). +## 2.2.4 - 2023-02-06 + +### Fixed +- An issue where order unable to create draft due to tag id mismatch. ([AcclaroInc#410](https://github.com/AcclaroInc/craft-translations/issues/410)) + +### Chore +- Code refactor (draft creation & publish) + ## 2.2.3 - 2022-08-01 ### Fixed diff --git a/src/controllers/OrderController.php b/src/controllers/OrderController.php index 0bd0bac4..6d99a6fb 100644 --- a/src/controllers/OrderController.php +++ b/src/controllers/OrderController.php @@ -1020,12 +1020,12 @@ public function actionSaveDraftAndPublish() } catch (Exception $e) { $actionName = $action == "publish" ? "publish" : "merge"; $order->logActivity(Translations::$plugin->translator->translate('app', "Could not $actionName draft Error: " . $e->getMessage())); - Translations::$plugin->logHelper->log( '['. __METHOD__ .'] Couldn’t save the draft. Error: '.$e->getMessage(), Constants::LOG_LEVEL_ERROR ); - $order->status = 'failed'; + Translations::$plugin->logHelper->log( '['. __METHOD__ .'] Couldn’t save the draft. Error: '.$e, Constants::LOG_LEVEL_ERROR ); Craft::$app->getElements()->saveElement($order); Craft::$app->getSession()->setNotice( Translations::$plugin->translator->translate('app', "Could not $actionName draft Error: " . $e->getMessage()) ); + return; } if ($job) { diff --git a/src/services/fieldtranslator/TagFieldTranslator.php b/src/services/fieldtranslator/TagFieldTranslator.php index cbe0a97e..bb991de2 100644 --- a/src/services/fieldtranslator/TagFieldTranslator.php +++ b/src/services/fieldtranslator/TagFieldTranslator.php @@ -20,15 +20,12 @@ class TagFieldTranslator extends TaxonomyFieldTranslator { public function translateRelated(ElementTranslator $elementTranslator, Element $element, Tag $existingTag, $sourceSite, $targetSite, $fieldData) { - $translatedTag = Translations::$plugin->tagRepository->find(array( - 'id' => $existingTag->id, - 'groupId' => $existingTag->groupId, - 'siteId' => $existingTag->siteId - )); + $translatedTag = Translations::$plugin->tagRepository->getTagById($existingTag->id, $targetSite); if ($translatedTag) { $tag = $translatedTag; } else { + // Doesn't feels this part runs as tags are propagated to all target locales if localised $tag = Translations::$plugin->elementCloner->cloneElement($existingTag); } diff --git a/src/services/repository/DraftRepository.php b/src/services/repository/DraftRepository.php index bb8e310c..4465d0fc 100644 --- a/src/services/repository/DraftRepository.php +++ b/src/services/repository/DraftRepository.php @@ -164,6 +164,7 @@ public function createOrderDrafts($orderId, $wordCounts, $publish, $fileIds, $qu $currentElement = 0; $createDrafts = new CreateDrafts(); + $transaction = Craft::$app->db->beginTransaction(); foreach ($order->getFiles() as $file) { if (! in_array($file->id, $fileIds)) { @@ -213,11 +214,12 @@ public function createOrderDrafts($orderId, $wordCounts, $publish, $fileIds, $qu if ($publish) { $this->applyDrafts($order->id, [$element->id], [$file->id], $queue); } - } catch(Exception $e) { - $order->logActivity(Translations::$plugin->translator->translate('app', 'Could not update draft Error: ' .$e->getMessage())); + $transaction->rollback(); + throw new \Exception($e->getMessage()); } } + $transaction->commit(); if ($isNewDraft) $order->logActivity(Translations::$plugin->translator->translate('app', 'Drafts created')); diff --git a/src/services/repository/TagRepository.php b/src/services/repository/TagRepository.php index d1fe808a..506d1e62 100644 --- a/src/services/repository/TagRepository.php +++ b/src/services/repository/TagRepository.php @@ -28,6 +28,19 @@ public function find($attributes = null) ->one(); } + /** + * Returns a tag by its ID. + * + * @param int $tagId + * @param int|null $siteId + * @return Tag|null + */ + public function getTagById(int $tagId, int $siteId = null) + { + /** @noinspection PhpIncompatibleReturnTypeInspection */ + return Craft::$app->getElements()->getElementById($tagId, Tag::class, $siteId); + } + public function saveTag(Tag $tag) { $success = Craft::$app->elements->saveElement($tag, true, false);