Skip to content

Commit

Permalink
Merge pull request #56 from AcclaroInc/release/1.5.1
Browse files Browse the repository at this point in the history
Release/1.5.1
  • Loading branch information
sidedwards authored Mar 10, 2020
2 parents 0d1500f + a724f55 commit 88ccffe
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 65 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": "Easily launch and manage multilingual Craft websites without having to copy/paste content or manually track updates.",
"pluginVersion": "1.5.0",
"pluginVersion": "1.5.1",
"pluginAuthorName": "Acclaro",
"pluginVendorName": "Acclaro",
"pluginAuthorUrl": "http://www.acclaro.com/",
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ 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/).

## 1.5.1 - 2020-03-10

### Added
- Support for all propagation method options in nested field settings
- Ability to add entries directly from the create order form
- Basic handling of Acclaro "In Review" orders

### Updated
- Switch to word count vs entry count for task processing
- Minor bug fixes & additional updates

## 1.5.0 - 2020-02-25

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Translations extends Plugin
/**
* @var string
*/
public $schemaVersion = '1.2.2';
public $schemaVersion = '1.2.3';

// Public Methods
// =========================================================================
Expand Down
51 changes: 44 additions & 7 deletions src/assetbundles/src/js/OrderDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,34 @@ Craft.Translations.OrderDetail = {

$('.duplicate-warning', '#global-container').infoicon();

$("#sourceSiteSelect").change(function (e) {
$(window).off('beforeunload.windowReload');
var site = $("#sourceSiteSelect").val();
var url = document.URL;
url = url.replace(/(sourceSite=).*?(&)/,'$1' + site + '$2');
if(url.indexOf('#step2') == -1) {
url += '#step2';
}
window.location.href = url;

});
var hash = window.location.hash;
if (hash == '#step2') {
$('#step1').toggleClass( "active" );
$('#step2').toggleClass( "active" );
$('#step_first').removeClass('disabled');
$('#step_first').addClass('prev');
$('#step_two').toggleClass('disabled');
}

$(".addEntries").on('click', function (e) {
elementIds = [];
elementIds = currentElementIds = [];

var sourceSites = [];
$("input:hidden.sourceSites").each(function() {
sourceSites.push($(this).val());
});

console.log(sourceSites);

this.assetSelectionModal = Craft.createElementSelectorModal('craft\\elements\\Entry', {
storageKey: null,
sources: null,
Expand All @@ -337,16 +355,35 @@ Craft.Translations.OrderDetail = {
onSelect: $.proxy(function(elements) {

$('#content').addClass('elements busy');

if (typeof $('#currentElementIds').val() !== 'undefined') {
currentElementIds = $('#currentElementIds').val().split(',');
}
if (elements.length) {
var elementUrl = '';
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
elementIds.push(element.id);
}
elementUrl += '&elements[]='+element.id;

addEntries();
if (Array.isArray(currentElementIds)) {
index = currentElementIds.indexOf(element.id.toString());
if (index > -1) {
currentElementIds.splice(index, 1);
}
}
}
for (var i = 0; i < currentElementIds.length; i++) {
if(currentElementIds[i]) {
elementUrl += '&elements[]='+currentElementIds[i];
}
}
if ($('#addNewEntries').val() == 1) {
window.location.href=Craft.getUrl('translations/orders/new')+'?sourceSite='+elementUrl;
} else {
addEntries();

setTimeout(function(){ $('#content').removeClass('elements busy') }, 5000);
setTimeout(function(){ $('#content').removeClass('elements busy') }, 5000);
}

}
}, this),
Expand Down
39 changes: 27 additions & 12 deletions src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BaseController extends Controller
*/
protected $pluginVersion;

protected static $sendToQueueLimit = 5;
const WORDCOUNT_LIMIT = 2000;

// Public Methods
// =========================================================================
Expand Down Expand Up @@ -454,7 +454,7 @@ public function actionOrderDetail(array $variables = array())
}

$variables['sourceSiteObject'] = Craft::$app->getSites()->getSiteById($variables['order']['sourceSite']);

if ($variables['order']->targetSites) {
$variables['orderTargetSitesObject'] = array();
foreach (json_decode($variables['order']->targetSites) as $key => $site) {
Expand Down Expand Up @@ -567,6 +567,16 @@ public function actionOrderDetail(array $variables = array())

$targetSites = Craft::$app->getSites()->getAllSiteIds();

$variables['sourceSites'] = array();

foreach ($targetSites as $key => $site) {
$site = Craft::$app->getSites()->getSiteById($site);
$variables['sourceSites'][] = array(
'value' => $site->id,
'label' => $site->name. '('. $site->language. ')'
);
}

// This removes same source as option
if (($key = array_search($variables['inputSourceSite'], $targetSites)) !== false) {
unset($targetSites[$key]);
Expand Down Expand Up @@ -663,9 +673,10 @@ public function actionApplyDrafts()
$elementIds = Craft::$app->getRequest()->getParam('elements');

$order = Translations::$plugin->orderRepository->getOrderById($orderId);
$totalElements = (count($elementIds) * count($order->getTargetSitesArray()));

if ($totalElements > self::$sendToQueueLimit ) {
$totalWordCount = ($order->wordCount * count($order->getTargetSitesArray()));

if ($totalWordCount > self::WORDCOUNT_LIMIT ) {

$job = Craft::$app->queue->push(new ApplyDrafts([
'description' => 'Applying translation drafts',
Expand Down Expand Up @@ -829,7 +840,7 @@ public function actionSaveOrder()
}

} else {
$sourceSite = Craft::$app->getRequest()->getParam('sourceSite');
$sourceSite = Craft::$app->getRequest()->getParam('sourceSiteSelect');

if ($sourceSite && !Translations::$plugin->siteRepository->isSiteSupported($sourceSite)) {
throw new HttpException(400, Translations::$plugin->translator->translate('app', 'Source site is not supported'));
Expand Down Expand Up @@ -988,9 +999,9 @@ public function actionSaveOrder()

$order->wordCount = array_sum($wordCounts);

$elements = ($order->getElements() instanceof Element) ? $order->getElements()->all() : (array) $order->getElements();
$totalElements = (count($elements) * count($order->getTargetSitesArray()));
if ($totalElements > self::$sendToQueueLimit) {
$totalWordCount = ($order->wordCount * count($order->getTargetSitesArray()));

if ($totalWordCount > self::WORDCOUNT_LIMIT) {
$job = Craft::$app->queue->push(new CreateDrafts([
'description' => 'Creating translation drafts',
'orderId' => $order->id,
Expand Down Expand Up @@ -1130,7 +1141,8 @@ public function actionSyncOrder()
}

if ($order) {
if (count($order->files) > self::$sendToQueueLimit) {
$totalWordCount = ($order->wordCount * count($order->getTargetSitesArray()));
if ($totalWordCount > self::WORDCOUNT_LIMIT) {
$job = Craft::$app->queue->push(new SyncOrder([
'description' => 'Syncing order '. $order->title,
'order' => $order
Expand Down Expand Up @@ -1166,11 +1178,12 @@ public function actionSyncOrders()
}

$orders = Translations::$plugin->orderRepository->getInProgressOrders();
$allFileCounts = 0;
$allFileCounts = $totalWordCount = 0;
foreach ($orders as $order) {
if ($order->translator->service === 'export_import') {
continue;
}
$totalWordCount += ($order->wordCount * count($order->getTargetSitesArray()));
$allFileCounts += count($order->files);
}

Expand All @@ -1182,7 +1195,7 @@ public function actionSyncOrders()
continue;
}

if ($allFileCounts > self::$sendToQueueLimit) {
if ($totalWordCount > self::WORDCOUNT_LIMIT) {
$job = Craft::$app->queue->push(new SyncOrder([
'description' => 'Syncing order '. $order->title,
'order' => $order
Expand Down Expand Up @@ -1271,7 +1284,9 @@ public function actionRegeneratePreviewUrls()

if ($order) {

if (count($order->files) > (self::$sendToQueueLimit * 5)) { // Multiply allowed queue limit due to fast processing times
$totalWordCount = ($order->wordCount * count($order->getTargetSitesArray()));

if ($totalWordCount > self::WORDCOUNT_LIMIT) {
$job = Craft::$app->queue->push(new RegeneratePreviewUrls([
'description' => 'Regenerating preview urls for '. $order->title,
'order' => $order
Expand Down
6 changes: 5 additions & 1 deletion src/elements/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected static function defineSources(string $context = null): array
'label' => Translations::$plugin->translator->translate('app', 'Orders in progress'),
'criteria' => [
'status' => [
'new', 'in progress', 'in preparation', 'getting quote', 'needs approval', 'complete'
'new', 'in progress', 'in review', 'in preparation', 'getting quote', 'needs approval', 'complete'
]
],
'defaultSort' => ['dateOrdered', 'desc']
Expand Down Expand Up @@ -247,6 +247,8 @@ public function getTableAttributeHtml(string $attribute): string
return '<span class="status"></span>'.Translations::$plugin->translator->translate('app', $this->statusLabel);
case 'In progress':
return '<span class="status orange"></span>'.Translations::$plugin->translator->translate('app', $this->statusLabel);
case 'In review':
return '<span class="status yellow"></span>'.Translations::$plugin->translator->translate('app', $this->statusLabel);
case 'Ready to apply':
return '<span class="status blue"></span>'.Translations::$plugin->translator->translate('app', $this->statusLabel);
case 'Cancelled':
Expand Down Expand Up @@ -424,6 +426,8 @@ public function getStatusLabel()
case 'in preparation':
case 'in progress':
return 'In progress';
case 'in review':
return 'In review';
case 'complete':
return 'Ready to apply';
case 'canceled':
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function createTables()
'ownerId' => $this->integer()->notNull(),
'sourceSite' => $this->integer()->notNull(),
'targetSites' => $this->string(1020)->notNull()->defaultValue(''),
'status' => $this->enum('status', ['new','getting quote','needs approval','in preparation','in progress','complete','canceled','published','failed'])->defaultValue('new'),
'status' => $this->enum('status', ['new','getting quote','needs approval','in preparation','in review','in progress','complete','canceled','published','failed'])->defaultValue('new'),
'requestedDueDate' => $this->dateTime(),
'comments' => $this->text(),
'activityLog' => $this->text(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace acclaro\translations\migrations;

use Craft;
use craft\db\Migration;

/**
* m200303_221033_add_review_status_in_orders_table migration.
*/
class m200303_221033_add_review_status_in_orders_table extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
echo "Altering translations_orders status column to include failed order status...\n";
// 'new','in progress','preview','complete','canceled','published'
$values = ['new','getting quote','needs approval','in preparation','in review','in progress','complete','canceled','published','failed'];
$this->alterColumn('{{%translations_orders}}', 'status', $this->enum('values', $values)->notNull()->defaultValue('new'));
echo "Done altering translations_orders status column...\n";

}

/**
* @inheritdoc
*/
public function safeDown()
{
echo "m200303_221033_add_review_status_in_orders_table cannot be reverted.\n";
return false;
}
}
10 changes: 7 additions & 3 deletions src/services/fieldtranslator/MatrixFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ public function toPostArray(ElementTranslator $elementTranslator, Element $eleme
$blocks = $element->getFieldValue($fieldHandle)->all();

if (!$blocks) {
return '';
return [];
}

$post = array(
$fieldHandle => array(),
);

$new = 0;
foreach ($blocks as $i => $block) {
$post[$fieldHandle]['new'.($i+1)] = array(
$blockId = $block->id ?? 'new' . ++$new;
$post[$fieldHandle][$blockId] = array(
'type' => $block->getType()->handle,
'enabled' => $block->enabled,
'fields' => $elementTranslator->toPostArray($block),
Expand All @@ -85,9 +87,11 @@ public function toPostArrayFromTranslationTarget(ElementTranslator $elementTrans

$fieldData = array_values($fieldData);

$new = 0;
foreach ($blocks as $i => $block) {
$blockId = $block->id ?? 'new' . ++$new;
$blockData = isset($fieldData[$i]) ? $fieldData[$i] : array();
$post[$fieldHandle]['new'.($i+1)] = array(
$post[$fieldHandle][$blockId] = array(
'type' => $block->getType()->handle,
'enabled' => $block->getAttributes()['enabled'],
'enabledForSite' => isset($block->getAttributes()['enabledForSite']) ? $block->getAttributes()['enabledForSite'] : null,
Expand Down
4 changes: 3 additions & 1 deletion src/services/fieldtranslator/NeoFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ public function toPostArrayFromTranslationTarget(ElementTranslator $elementTrans

$this->parseBlockData($allBlockData, $fieldData);

$new = 0;
foreach ($blocks as $i => $block) {
$blockId = $block->id ?? 'new' . ++$new;
$blockData = isset($allBlockData[$i]) ? $allBlockData[$i] : array();

$post[$fieldHandle]['new'.($i+1)] = array(
$post[$fieldHandle][$blockId] = array(
'modified' => '1',
'type' => $block->getType()->handle,
'enabled' => $block->enabled,
Expand Down
19 changes: 10 additions & 9 deletions src/services/fieldtranslator/SuperTableFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,35 +104,36 @@ public function toPostArrayFromTranslationTarget(ElementTranslator $elementTrans
$blockTypes = SuperTable::$plugin->service->getBlockTypesByFieldId($field->id);
$blockType = $blockTypes[0]; // There will only ever be one SuperTable_BlockType

$j = 0;
$new = 0;
foreach ($blocks as $i => $block) {
if (!$block instanceof ElementQuery) {
if (is_array($block)) {
$n = 0;
foreach ($block as $key => $elem) {
$blockData = isset($fieldData[$j]) ? $fieldData[$j] : array();
$post[$fieldHandle]['new'.($j+1)] = array(
$blockId = $elem->id ?? 'new' . ++$new;
$blockData = isset($fieldData[$n]) ? $fieldData[$n] : array();
$post[$fieldHandle][$blockId] = array(
'type' => $blockType->id,
'fields' => $elementTranslator->toPostArrayFromTranslationTarget($elem, $sourceLanguage, $targetLanguage, $blockData, true),
);
$j++;
}
} else {
$blockData = isset($fieldData[$j]) ? $fieldData[$j] : array();
$post[$fieldHandle]['new'.($j+1)] = array(
$blockData = isset($fieldData[$new]) ? $fieldData[$new] : array();
$blockId = $block->id ?? 'new' . ++$new;
$post[$fieldHandle][$blockId] = array(
'type' => $blockType->id,
'fields' => $elementTranslator->toPostArrayFromTranslationTarget($block, $sourceLanguage, $targetLanguage, $blockData, true),
);
$j++;
}
} else {
$blockElem = $element->getFieldValue($fieldHandle);
foreach ($blockElem as $key => $block) {
$blockId = $block->id ?? 'new' . ++$new;
$blockData = isset($fieldData[$key]) ? $fieldData[$key] : array();
$post[$fieldHandle]['new'.($j+1)] = array(
$post[$fieldHandle][$blockId] = array(
'type' => $blockType->id,
'fields' => $elementTranslator->toPostArrayFromTranslationTarget($block, $sourceLanguage, $targetLanguage, $blockData, true),
);
$j++;
}
}
}
Expand Down
Loading

0 comments on commit 88ccffe

Please sign in to comment.