Skip to content

Commit

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

## Unreleased

## 2.1.2 - 2022-01-21

### Updated
- Order activity log text format ([AcclaroInc/#371](https://github.com/AcclaroInc/pm-craft-translations/issues/371))
- Activity log status format ([craft-translations/#290](https://github.com/AcclaroInc/craft-translations/pull/290))

### Fixed
- ISO alias mapping bug ([craft-translations/#289](https://github.com/AcclaroInc/craft-translations/issues/289))
- Exclude non-localized Element titles ([craft-translations/#294](https://github.com/AcclaroInc/craft-translations/issues/294))
- Tag label bug ([craft-translations/#292](https://github.com/AcclaroInc/craft-translations/pull/292))
- Source site selection bug ([craft-translations/#297](https://github.com/AcclaroInc/craft-translations/pull/297))
- Preview URL generation bug ([craft-translations/#298](https://github.com/AcclaroInc/craft-translations/pull/298))

## 2.1.1 - 2022-01-07

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function actionCreateExportZip()

if ($order->status !== ($newStatus = Translations::$plugin->orderRepository->getNewStatus($order))) {
$order->status = $newStatus;
$order->logActivity(sprintf('Order status changed to %s', $order->getStatusLabel()));
$order->logActivity(sprintf('Order status changed to \'%s\'', $order->getStatusLabel()));
}
}

Expand Down
27 changes: 9 additions & 18 deletions src/controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ public function actionOrderDetail(array $variables = array())
}
}

$SourceSite = Craft::$app->getRequest()->getBodyParam('sourceSite');
$sourceSite = Craft::$app->getRequest()->getQueryParam('sourceSite') ?? Craft::$app->getRequest()->getBodyParam('sourceSite');

if ($SourceSite && !Translations::$plugin->siteRepository->isSiteSupported($SourceSite)
) {
if ($sourceSite && !Translations::$plugin->siteRepository->isSiteSupported($sourceSite)) {
Craft::$app->getSession()->setError(Translations::$plugin->translator->translate('app', 'Source site is not supported'));
return;
}
Expand All @@ -138,7 +137,7 @@ public function actionOrderDetail(array $variables = array())
throw new HttpException(404);
}
} else {
$order = $this->service->makeNewOrder($SourceSite);
$order = $this->service->makeNewOrder($sourceSite);

$orderElements= Craft::$app->getRequest()->getQueryParam('elements') ?? Craft::$app->getRequest()->getParam('elements');
$order->elementIds = json_encode($orderElements ?: []);
Expand All @@ -156,14 +155,6 @@ public function actionOrderDetail(array $variables = array())
$order->targetSites = json_encode($orderTargetSites);
}

if (! empty(json_decode($order->tags, true))) {
$variables['tags'] = [];

foreach (json_decode($order->tags, true) as $tagId) {
$variables['tags'][] = Craft::$app->getTags()->getTagById($tagId);
}
}

if ($orderTags= Craft::$app->getRequest()->getQueryParam('tags') ?? Craft::$app->getRequest()->getParam('tags')) {
if (! is_array($orderTags)) {
$orderTags = explode(',', $orderTags);
Expand Down Expand Up @@ -386,11 +377,11 @@ public function actionSaveOrder()
// This is for draft converting to order.
$order = $this->service->getOrderById($orderId);

$order->logActivity(Translations::$plugin->translator->translate('app', 'Order Created'));
$order->logActivity(Translations::$plugin->translator->translate('app', 'Order created'));
} else {
$order = $this->service->makeNewOrder($sourceSite);

$order->logActivity(Translations::$plugin->translator->translate('app', 'Order Created'));
$order->logActivity(Translations::$plugin->translator->translate('app', 'Order created'));
}

$job = '';
Expand Down Expand Up @@ -597,7 +588,7 @@ public function actionSaveOrder()
}

$order->logActivity(sprintf(
Translations::$plugin->translator->translate('app', 'Order Submitted to %s'),
Translations::$plugin->translator->translate('app', 'Order submitted to %s'),
$order->translator->getName()
));
}
Expand Down Expand Up @@ -1430,7 +1421,7 @@ public function actionUpdateOrderFilesSource()
if ($isDefaultTranslator && !$order->isModified()) {
$order->status = Constants::ORDER_STATUS_MODIFIED;
$order->logActivity(sprintf(
Translations::$plugin->translator->translate('app', 'Order status changed to %s'),
Translations::$plugin->translator->translate('app', 'Order status changed to \'%s\''),
$order->getStatusLabel()
));
}
Expand All @@ -1448,7 +1439,7 @@ public function actionUpdateOrderFilesSource()
$order->status = Translations::$plugin->orderRepository->getNewStatus($order);

$order->logActivity(sprintf(
Translations::$plugin->translator->translate('app', 'Order status changed to %s'),
Translations::$plugin->translator->translate('app', 'Order status changed to \'%s\''),
$order->getStatusLabel()
));

Expand All @@ -1468,7 +1459,7 @@ public function actionUpdateOrderFilesSource()
Craft::$app->getSession()->setNotice('Entries Updated.');
} catch (\Exception $e) {
$transaction->rollBack();
Craft::debug($e, 'bhu123');

return $this->asJson(['success' => false, 'message' => 'Error updating source. Error: ' . $e->getMessage()]);
}

Expand Down
5 changes: 5 additions & 0 deletions src/elements/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ public function getOwner()
return $owner;
}

public function getTags()
{
return Translations::$plugin->tagRepository->getOrderTags($this);
}

public function getTargetSitesArray()
{
return $this->targetSites ? json_decode($this->targetSites, true) : array();
Expand Down
19 changes: 9 additions & 10 deletions src/services/ElementTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ class ElementTranslator
public function toTranslationSource(Element $element, $sourceSite=null)
{
$source = array();

// if ($element instanceof Element || $element instanceof Tag || $element instanceof Category) {

if ($element instanceof Element) {
if ($element->title) {
if ($element->title && $element->getIsTitleTranslatable()) {
$source['title'] = $element->title;
}
if ($element->slug) {
Expand All @@ -43,7 +42,7 @@ public function toTranslationSource(Element $element, $sourceSite=null)

$source = array_merge($source, $fieldSource);
}

return $source;
}

Expand Down Expand Up @@ -72,14 +71,14 @@ public function getTargetData($content, $nonNested = false) {

while ($parts) {
$key = array_shift($parts);

if (!isset($container[$key])) {
$container[$key] = array();
}

$container =& $container[$key];
}

$container = $value;
} else {
$targetData[$name] = $value;
Expand All @@ -100,7 +99,7 @@ public function getTargetDataFromXml($xml, $nonNested = false)

$contents = $dom->getElementsByTagName('content');


foreach ($contents as $content) {
$name = (string) $content->getAttribute('resname');
$value = (string) $content->nodeValue;
Expand All @@ -109,7 +108,7 @@ public function getTargetDataFromXml($xml, $nonNested = false)
$targetData[$name] = $value;
continue;
}

if (strpos($name, '.') !== false) {
$parts = explode('.', $name);
$container =& $targetData;
Expand Down Expand Up @@ -140,7 +139,7 @@ public function toPostArrayFromTranslationTarget(Element $element, $sourceSite,
foreach($element->getFieldLayout()->getFields() as $key => $layoutField) {
$field = Craft::$app->fields->getFieldById($layoutField->id);
$fieldHandle = $field->handle;

$fieldType = $field;

$translator = Translations::$plugin->fieldTranslatorFactory->makeTranslator($fieldType);
Expand Down
10 changes: 7 additions & 3 deletions src/services/repository/DraftRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,14 @@ public function createOrderDrafts($orderId, $wordCounts, $publish, $fileIds, $qu
}
}

$order->status = Translations::$plugin->orderRepository->getNewStatus($order);

if ($isNewDraft)
$order->logActivity(Translations::$plugin->translator->translate('app', 'Drafts created'));
$order->logActivity(Translations::$plugin->translator->translate('app', 'Drafts created'));

$newStatus = Translations::$plugin->orderRepository->getNewStatus($order);
if ($order->status != $newStatus) {
$order->status = $newStatus;
$order->logActivity(sprintf('Order status changed to \'%s\'', $order->getStatusLabel()));
}

Translations::$plugin->orderRepository->saveOrder($order);
}
Expand Down
13 changes: 1 addition & 12 deletions src/services/repository/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function regeneratePreviewUrls($order, $previewUrls, $queue=null) {
$service = new RegeneratePreviewUrls();
foreach ($order->files as $file) {

if (! ($file->hasDraft() || $file->isComplete())) continue;
if (! $file->isComplete()) continue;

if ($queue) {
$service->updateProgress($queue, $currentElement++ / $totalElements);
Expand All @@ -239,18 +239,7 @@ public function regeneratePreviewUrls($order, $previewUrls, $queue=null) {
$draft = Translations::$plugin->draftRepository->getDraftById($file->draftId, $file->targetSite);

if ($draft) {
$element = Craft::$app->getElements()->getElementById($file->elementId, null, $file->sourceSite);
$file->previewUrl = $previewUrls[$file->id] ?? $draft->url;
$file->source = Translations::$plugin->elementToFileConverter->convert(
$element,
Constants::FILE_FORMAT_XML,
[
'sourceSite' => $file->sourceSite,
'targetSite' => $file->targetSite,
'previewUrl' => $file->previewUrl,
'orderId' => $file->orderId,
]
);
}

Translations::$plugin->fileRepository->saveFile($file);
Expand Down
10 changes: 4 additions & 6 deletions src/services/repository/SiteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use acclaro\translations\services\api\CraftApiClient;

class SiteRepository
{
{
protected $supportedSites = array();
protected $isoMapping;

Expand All @@ -27,9 +27,9 @@ public function getSiteLanguage($siteId)
}

$language = $site->language;

$language = $this->normalizeLanguage($site);

return $language;
}

Expand All @@ -53,8 +53,6 @@ public function getSiteLanguageDisplayName($siteId)

public function normalizeLanguage($language)
{
$language = mb_strtolower($language);

$language = str_replace('_', '-', $language);

if (! $this->isoMapping) {
Expand Down Expand Up @@ -90,7 +88,7 @@ public function getAllSitesHandle()
{
$allSitesHandle = [];
$allSites = Craft::$app->getSites()->getAllSites();

foreach($allSites as $site)
{
$allSitesHandle[$site->id] = $site->handle;
Expand Down
21 changes: 20 additions & 1 deletion src/services/repository/TagRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Craft;
use craft\elements\Tag;
use acclaro\translations\elements\Order;

class TagRepository
{
Expand All @@ -31,4 +32,22 @@ public function saveTag(Tag $tag)
Craft::error( '['. __METHOD__ .'] Couldn’t save the tag "'.$tag->title.'"', 'translations' );
}
}
}

/**
* Get Tags Object for an order
*
* @param Order $order
* @return array
*/
public function getOrderTags(Order $order)
{
$orderTags = [];
if ($order->tags) {
foreach (json_decode($order->tags, true) as $tagId) {
$orderTags[$tagId] = Craft::$app->getTags()->getTagById($tagId);
}
}

return $orderTags;
}
}
4 changes: 3 additions & 1 deletion src/services/translator/AcclaroTranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Craft;
use craft\elements\Asset;
use craft\elements\GlobalSet;
use craft\helpers\ElementHelper;

use acclaro\translations\Constants;
use acclaro\translations\Translations;
Expand Down Expand Up @@ -96,8 +97,9 @@ public function updateOrder(Order $order)
$orderStatus = Translations::$plugin->orderRepository->getNewStatus($order);

if ($order->status !== $orderStatus) {
$order->status = $orderStatus;
$order->logActivity(
sprintf(Translations::$plugin->translator->translate('app', 'Order status changed to %s'), $orderStatus)
sprintf(Translations::$plugin->translator->translate('app', 'Order status changed to \'%s\''), $order->getStatusLabel())
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/services/translator/Export_ImportTranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public function updateOrder(Order $order)
{
$newStatus = Translations::$plugin->orderRepository->getNewStatus($order);
if ($order->status !== $newStatus) {
$order->status = $newStatus;
$order->logActivity(
sprintf(Translations::$plugin->translator->translate('app', 'Order status changed to %s'), $newStatus)
sprintf(Translations::$plugin->translator->translate('app', 'Order status changed to \'%s\''), $order->getStatusLabel())
);

}
Expand Down Expand Up @@ -120,7 +121,7 @@ public function updateDraft($element, $draft, $translatedContent, $sourceSite, $
$errorMessage .= implode('; ', $r);
}
$order->logActivity(
Translations::$plugin->translator->translate('app', 'error saving drafts content. Error: '.$errorMessage)
Translations::$plugin->translator->translate('app', 'Error saving drafts content. Error: '.$errorMessage)
);
} else {
$order->logActivity(
Expand Down
4 changes: 2 additions & 2 deletions src/templates/_components/orders/settings-tab.twig
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@
<div class="input ltr">
<div id="fields-tags" class="elementselect tagselect">
<div id="elementTags" class="elements">
{% if tags is defined %}
{% for tag in tags %}
{% if not order.getTags is empty %}
{% for tag in order.getTags %}
<div class="element small removable" data-editable="1" data-id="{{ tag.id }}" data-label="{{ tag.title }}">
<input type="hidden" name="tags[]" value="{{ tag.id }}"/>
<a class="delete icon custom-tag" data-label="{{ tag.title }}" data-id="{{ tag.id }}" title="Remove"></a>
Expand Down

0 comments on commit 36908f9

Please sign in to comment.