Skip to content

Commit

Permalink
Merge pull request #311 from AcclaroInc/release/2.1.3
Browse files Browse the repository at this point in the history
Release/2.1.3
  • Loading branch information
sidedwards authored Feb 21, 2022
2 parents 36908f9 + 554c63c commit 263cb72
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 34 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": "2.1.2",
"pluginVersion": "2.1.3",
"pluginAuthorName": "Acclaro",
"pluginVendorName": "Acclaro",
"pluginAuthorUrl": "http://www.acclaro.com/",
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## Unreleased

## 2.1.3 - 2022-02-21

### Fixed

- Entry relation for disabled target reference ([AcclaroInc/#455](https://github.com/AcclaroInc/pm-craft-translations/issues/455))
- `$order->siteId` to `$order->sourceSite` (https://github.com/AcclaroInc/craft-translations/issues/305)
- Nested Supertable bug ([AcclaroInc/#451](https://github.com/AcclaroInc/pm-craft-translations/issues/451))
- Missing title on "Merge into draft" bug ([AcclaroInc/#437](https://github.com/AcclaroInc/pm-craft-translations/issues/437))

## 2.1.2 - 2022-01-21

### Updated
Expand Down
22 changes: 11 additions & 11 deletions src/Translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,23 +615,23 @@ private function _onApplyDraft(Event $event)

private function _onDeleteElement(Event $event)
{
if (!empty($event->element->draftId)) {
$response = Translations::$plugin->draftRepository->isTranslationDraft($event->element->draftId);
if ($response) {
if (!empty($event->element->draftId)) {
$response = self::$plugin->draftRepository->isTranslationDraft($event->element->draftId);
if ($response) {

$currentFile = self::$plugin->fileRepository->getFileByDraftId($event->element->draftId);
$currentFile = self::$plugin->fileRepository->getFileByDraftId($event->element->draftId);

if ($currentFile) {
$order = self::$plugin->orderRepository->getOrderById($currentFile->orderId);
if ($currentFile) {
$order = self::$plugin->orderRepository->getOrderById($currentFile->orderId);

if ($order) {
$order->logActivity(Translations::$plugin->translator->translate('app', 'Draft '. $event->element->draftId .' deleted.'));
Translations::$plugin->orderRepository->saveOrder($order);
}
$order->logActivity(Translations::$plugin->translator->translate('app', 'Draft ' . $event->element->draftId . ' deleted.'));
Translations::$plugin->orderRepository->saveOrder($order);
}

$currentFile->status = Constants::FILE_STATUS_CANCELED;
$currentFile->status = Constants::FILE_STATUS_CANCELED;

self::$plugin->fileRepository->saveFile($currentFile);
self::$plugin->fileRepository->saveFile($currentFile);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function actionAddElementsToOrder()
if (!in_array($elementId, $elementIds)) {
$elementIds[] = $elementId;

$element = Craft::$app->getElements()->getElementById($elementId, null, $order->siteId);
$element = Craft::$app->getElements()->getElementById($elementId, null, $order->sourceSite);

if ($element instanceof Entry) {
$sites = array();
Expand Down
4 changes: 1 addition & 3 deletions src/elements/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ class Order extends Element
public $wordCount;

public $elementIds;

public $siteId;


public $trackChanges;

public $asynchronousPublishing;
Expand Down
14 changes: 5 additions & 9 deletions src/services/fieldtranslator/EntriesFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,14 @@ public function toPostArrayFromTranslationTarget(ElementTranslator $elementTrans
{
$fieldHandle = $field->handle;

$blocks = $element->getFieldValue($fieldHandle)->all();

$post = [
$fieldHandle => [],
];

$fieldData = array_values($fieldData);

foreach ($blocks as $i => $block) {
$blockData = isset($fieldData[$i]) ? $fieldData[$i] : [];

$post[$fieldHandle][$block->id] = $block->id;
foreach ($fieldData as $data) {
if ($entryId = $data['id'] ?? null) {
$post[$fieldHandle][$entryId] = $entryId;
}
}

return $post;
Expand All @@ -89,4 +85,4 @@ public function toPostArrayFromTranslationTarget(ElementTranslator $elementTrans
public function getWordCount(ElementTranslator $elementTranslator, Element $element, Field $field)
{
}
}
}
12 changes: 6 additions & 6 deletions src/services/repository/DraftRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,18 @@ public function createOrderDrafts($orderId, $wordCounts, $publish, $fileIds, $qu
continue;
}

$element = Craft::$app->getElements()->getElementById($file->elementId, null, $order->siteId);
$element = Craft::$app->getElements()->getElementById($file->elementId, null, $order->sourceSite);
if ($queue) {
$createDrafts->updateProgress($queue, $currentElement++/$totalElements);
}

// Create draft only if not already exist
if (! $file->draftId) {
$isNewDraft = true;
$this->createDrafts($element, $order, $file->targetSite, $wordCounts, $file);
} else {
// Create draft only if not already exist
if ($file->draftId && $this->getDraftById($file->draftId, $file->targetSite)) {
$file->status = Constants::FILE_STATUS_COMPLETE;
Translations::$plugin->fileRepository->saveFile($file);
} else {
$isNewDraft = true;
$this->createDrafts($element, $order, $file->targetSite, $wordCounts, $file);
}

try {
Expand Down
4 changes: 2 additions & 2 deletions src/services/repository/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public function getNewStatus($order)
*/
public function getFileTitle($file) {

$element = Craft::$app->getElements()->getElementById($file->elementId);
$element = Craft::$app->getElements()->getElementById($file->elementId, null, $file->sourceSite);

if ($element instanceof GlobalSet) {
$draftElement = Translations::$plugin->globalSetDraftRepository->getDraftById($file->draftId);
Expand All @@ -502,7 +502,7 @@ public function getFileTitle($file) {
$draftElement = Translations::$plugin->draftRepository->getDraftById($file->draftId, $file->targetSite);
}

return $draftElement->title ?? '';
return $draftElement->title ?? $element->title;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function updateDraft($element, $draft, $translatedContent, $sourceSite, $
$draft->title = isset($targetData['title']) ? $targetData['title'] : $draft->title;
$draft->slug = isset($targetData['slug']) ? $targetData['slug'] : $draft->slug;

$post = Translations::$plugin->elementTranslator->toPostArrayFromTranslationTarget($draft, $sourceSite, $targetSite, $targetData);
$post = Translations::$plugin->elementTranslator->toPostArrayFromTranslationTarget($draft, $sourceSite, $targetSite, $targetData);
$draft->setFieldValues($post);
$draft->siteId = $targetSite;

Expand Down

0 comments on commit 263cb72

Please sign in to comment.