Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release v4.0.0-beta.2 #519

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "4.0.0",
"pluginVersion": "v4.0.0-beta.2",
"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.0-beta.2 - 2024-09-11

### Fixed
- Order search in order index page. ([AcclaroInc#517](https://github.com/AcclaroInc/craft-translations/pull/517))
- Error when applying draft of entry with neo fields. ([AcclaroInc#518](https://github.com/AcclaroInc/craft-translations/issues/518))

## 4.0.0-beta.1 - 2024-09-02

### Updated
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function actionCreateExportZip()
return $this->asFailure($this->getErrorMessage(implode('\n', $errors)));
}

Craft::$app->getElements()->saveElement($order, true, true, true);
Craft::$app->getElements()->saveElement($order);
$transaction->commit();

return $this->asSuccess(null, ['translatedFiles' => $zipDest]);
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public function actionSaveOrder()
$order->wordCount = array_sum($wordCounts);

// Manual Translation will make orders 'in progress' status after creation
$success = Craft::$app->getElements()->saveElement($order, true, true, true);
$success = Craft::$app->getElements()->saveElement($order);

if (!$success) {
Translations::$plugin->logHelper->log('[' . __METHOD__ . '] Couldn’t save the order', Constants::LOG_LEVEL_ERROR);
Expand Down Expand Up @@ -617,7 +617,7 @@ public function actionSaveOrder()
$order->status = Constants::ORDER_STATUS_NEW;
$order->dateOrdered = new DateTime();

$success = Craft::$app->getElements()->saveElement($order, true, true, true);
$success = Craft::$app->getElements()->saveElement($order);

if (! $success) {
Translations::$plugin->logHelper->log('[' . __METHOD__ . '] Couldn’t save the order', Constants::LOG_LEVEL_ERROR);
Expand Down Expand Up @@ -1185,7 +1185,7 @@ public function actionUpdateOrderFilesSource()
}
}

Craft::$app->getElements()->saveElement($order, true, true, false);
Craft::$app->getElements()->saveElement($order);
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollBack();
Expand Down Expand Up @@ -1229,7 +1229,7 @@ public function actionAcceptQuote()

$order->status = Constants::ORDER_STATUS_NEW;
$order->logActivity("Order quote accepted");
Craft::$app->getElements()->saveElement($order, true, true, false);
Craft::$app->getElements()->saveElement($order);

return $this->asSuccess($this->getSuccessMessage("Quote approve request sent"));
}
Expand Down Expand Up @@ -1266,7 +1266,7 @@ public function actionDeclineQuote()

$order->status = Constants::ORDER_STATUS_GETTING_QUOTE;
$order->logActivity("Order quote declined");
Craft::$app->getElements()->saveElement($order, true, true, false);
Craft::$app->getElements()->saveElement($order);

return $this->asSuccess($this->getSuccessMessage("Quote decline request sent"));
}
Expand Down
41 changes: 41 additions & 0 deletions src/migrations/m240829_054957_drop_commerce_draft_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace acclaro\translations\migrations;

use Craft;
use craft\db\Migration;
use acclaro\translations\elements\Order;

/**
* m240829_054957_drop_commerce_draft_table migration.
Expand All @@ -20,6 +22,45 @@ public function safeUp(): bool

echo "Done dropping translations_commercedrafts table...\n";

echo "Re-indexing all existing orders...\n";

$batchSize = 100;
$offset = 0;
$totalProcessed = 0;

while (true) {
$orders = Order::find()
->limit($batchSize)
->offset($offset)
->all();

if (empty($orders)) {
break;
}

foreach ($orders as $order) {
try {
$order = Craft::$app->getElements()->getElementById($order->id, null, $order->sourceSite);
if ($order) {
$order->resaving = true;
if (!Craft::$app->getElements()->saveElement($order)) {
Craft::error('Failed to save order ID: ' . $order->id, __METHOD__);
}
}
} catch (\Throwable $e) {
Craft::error('Error re-saving order ID: ' . $order->id . '. Error: ' . $e->getMessage(), __METHOD__);
throw $e;
}
}

$totalProcessed += count($orders);
$offset += $batchSize;

echo "Processed $totalProcessed orders so far...\n";
}

echo "Done re-indexing all orders.\n";

return true;
}

Expand Down
11 changes: 10 additions & 1 deletion src/services/fieldtranslator/AssetsFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Exception;
use craft\base\Field;
use craft\base\Element;
use acclaro\translations\Constants;
use acclaro\translations\Translations;
use acclaro\translations\services\ElementTranslator;

Expand All @@ -23,7 +24,15 @@ public function toTranslationSource(ElementTranslator $elementTranslator, Elemen
{
$source = array();

$blocks = $element->getFieldValue($field->handle)->siteId($sourceSite)->all();
try {
$blocks = $element->getFieldValue($field->handle)->siteId($sourceSite)->all();
} catch (\Exception $e) {
Translations::$plugin->logHelper->log(
`[' . __METHOD__ . '] $field->handle not found.`,
Constants::LOG_LEVEL_ERROR
);
return $source;
}

if ($blocks)
{
Expand Down
11 changes: 10 additions & 1 deletion src/services/fieldtranslator/HyperLinkFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use craft\base\Field;
use craft\base\Element;
use acclaro\translations\Constants;
use acclaro\translations\Translations;
use acclaro\translations\services\ElementTranslator;

Expand All @@ -26,7 +27,15 @@ public function toTranslationSource(ElementTranslator $elementTranslator, Elemen

$fieldHandle = $field->handle;

$fieldData = $element->getFieldValue($fieldHandle);
try {
$fieldData = $element->getFieldValue($fieldHandle);
} catch (\Exception $e) {
Translations::$plugin->logHelper->log(
`[' . __METHOD__ . '] $fieldHandle not found.`,
Constants::LOG_LEVEL_ERROR
);
return $source;
}

if($fieldData){
foreach($fieldData as $key => $value)
Expand Down
12 changes: 11 additions & 1 deletion src/services/fieldtranslator/MatrixFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

namespace acclaro\translations\services\fieldtranslator;

use acclaro\translations\Constants;
use craft\base\Field;
use craft\base\Element;
use acclaro\translations\services\ElementTranslator;
use acclaro\translations\Translations;

class MatrixFieldTranslator extends GenericFieldTranslator
{
Expand All @@ -23,7 +25,15 @@ public function toTranslationSource(ElementTranslator $elementTranslator, Elemen
{
$source = array();

$blocks = $element->getFieldValue($field->handle)->all();
try {
$blocks = $element->getFieldValue($field->handle)->all();
} catch (\Exception $e) {
Translations::$plugin->logHelper->log(
`[' . __METHOD__ . '] $field->handle not found.`,
Constants::LOG_LEVEL_ERROR
);
return $source;
}

if ($blocks) {

Expand Down
1 change: 0 additions & 1 deletion src/services/fieldtranslator/NavigationFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function toTranslationSource(ElementTranslator $elementTranslator, Elemen
$fieldData = \verbb\navigation\elements\Node::find()
->handle($handlenav)
->all();


if ($fieldData) {
foreach ($fieldData as $key => $value) {
Expand Down
14 changes: 11 additions & 3 deletions src/services/fieldtranslator/NeoFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use craft\base\Field;
use craft\base\Element;
use benf\neo\elements\Block;
use acclaro\translations\Constants;
use acclaro\translations\Translations;
use acclaro\translations\services\ElementTranslator;

class NeoFieldTranslator extends GenericFieldTranslator
Expand All @@ -24,7 +26,15 @@ public function toTranslationSource(ElementTranslator $elementTranslator, Elemen
{
$source = array();

$blocks = $element->getFieldValue($field->handle)->all();
try {
$blocks = $element->getFieldValue($field->handle)->all();
} catch (\Exception $e) {
Translations::$plugin->logHelper->log(
`[' . __METHOD__ . '] $field->handle not found.`,
Constants::LOG_LEVEL_ERROR
);
return $source;
}

if ($blocks) {
$new = 0;
Expand Down Expand Up @@ -103,10 +113,8 @@ public function toPostArrayFromTranslationTarget(ElementTranslator $elementTrans

$blockId = $field->getIsTranslatable($element) ? $i : $block->id;
$blockData = $allBlockData[$i] ?? array();
$titleDiff = !is_null($fieldData[$i]['title']) && ($block->title !== $fieldData[$i]['title']) ? $fieldData[$i]['title'] : $block->title;

$post[$fieldHandle][$blockId] = array(
'title' => $titleDiff,
'modified' => '1',
'type' => $block->getType()->handle,
'enabled' => $block->enabled,
Expand Down
11 changes: 10 additions & 1 deletion src/services/fieldtranslator/VizyFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use craft\base\Field;
use craft\base\Element;
use acclaro\translations\Constants;
use acclaro\translations\Translations;
use acclaro\translations\services\ElementTranslator;

class VizyFieldTranslator extends GenericFieldTranslator
Expand All @@ -27,7 +28,15 @@ public function toTranslationSource(ElementTranslator $elementTranslator, Elemen
{
$source = [];

$blocks = $element->getFieldValue($field->handle)->all();
try {
$blocks = $element->getFieldValue($field->handle)->all();
} catch (\Exception $e) {
Translations::$plugin->logHelper->log(
`[' . __METHOD__ . '] $field->handle not found.`,
Constants::LOG_LEVEL_ERROR
);
return $source;
}

if ($blocks) {
foreach ($blocks as $index => $block) {
Expand Down
4 changes: 1 addition & 3 deletions src/services/repository/DraftRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ public function applyTranslationDraft($fileId, $file='', $draft='')
}

try {
$canonical = $draft->getCanonical();
$draft->setFieldValues($canonical->getFieldValues());
// Let's try saving the element prior to applying draft
if (!Craft::$app->getElements()->saveElement($draft, true, true, true)) {
if (!Craft::$app->getElements()->saveElement($draft)) {
throw new InvalidElementException($draft);
}

Expand Down