diff --git a/.craftplugin b/.craftplugin index 6970abd7..cc9c842d 100644 --- a/.craftplugin +++ b/.craftplugin @@ -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/", diff --git a/CHANGELOG.md b/CHANGELOG.md index 985118b6..a227b3cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/controllers/FilesController.php b/src/controllers/FilesController.php index 34ef7da7..22b014ea 100644 --- a/src/controllers/FilesController.php +++ b/src/controllers/FilesController.php @@ -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]); diff --git a/src/controllers/OrderController.php b/src/controllers/OrderController.php index e4073096..98e8c380 100644 --- a/src/controllers/OrderController.php +++ b/src/controllers/OrderController.php @@ -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); @@ -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); @@ -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(); @@ -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")); } @@ -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")); } diff --git a/src/migrations/m240829_054957_drop_commerce_draft_table.php b/src/migrations/m240829_054957_drop_commerce_draft_table.php index e5f1eacb..fe494d7f 100644 --- a/src/migrations/m240829_054957_drop_commerce_draft_table.php +++ b/src/migrations/m240829_054957_drop_commerce_draft_table.php @@ -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. @@ -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; } diff --git a/src/services/fieldtranslator/AssetsFieldTranslator.php b/src/services/fieldtranslator/AssetsFieldTranslator.php index 90ed3052..962c9153 100644 --- a/src/services/fieldtranslator/AssetsFieldTranslator.php +++ b/src/services/fieldtranslator/AssetsFieldTranslator.php @@ -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; @@ -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) { diff --git a/src/services/fieldtranslator/HyperLinkFieldTranslator.php b/src/services/fieldtranslator/HyperLinkFieldTranslator.php index 8181f1ee..bce00661 100644 --- a/src/services/fieldtranslator/HyperLinkFieldTranslator.php +++ b/src/services/fieldtranslator/HyperLinkFieldTranslator.php @@ -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; @@ -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) diff --git a/src/services/fieldtranslator/MatrixFieldTranslator.php b/src/services/fieldtranslator/MatrixFieldTranslator.php index f7cec345..7365d490 100644 --- a/src/services/fieldtranslator/MatrixFieldTranslator.php +++ b/src/services/fieldtranslator/MatrixFieldTranslator.php @@ -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 { @@ -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) { diff --git a/src/services/fieldtranslator/NavigationFieldTranslator.php b/src/services/fieldtranslator/NavigationFieldTranslator.php index 1ac4dd2a..9aafd75d 100644 --- a/src/services/fieldtranslator/NavigationFieldTranslator.php +++ b/src/services/fieldtranslator/NavigationFieldTranslator.php @@ -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) { diff --git a/src/services/fieldtranslator/NeoFieldTranslator.php b/src/services/fieldtranslator/NeoFieldTranslator.php index 82a3934f..de8df9be 100644 --- a/src/services/fieldtranslator/NeoFieldTranslator.php +++ b/src/services/fieldtranslator/NeoFieldTranslator.php @@ -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 @@ -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; @@ -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, diff --git a/src/services/fieldtranslator/VizyFieldTranslator.php b/src/services/fieldtranslator/VizyFieldTranslator.php index e00a0efe..0edc761b 100644 --- a/src/services/fieldtranslator/VizyFieldTranslator.php +++ b/src/services/fieldtranslator/VizyFieldTranslator.php @@ -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 @@ -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) { diff --git a/src/services/repository/DraftRepository.php b/src/services/repository/DraftRepository.php index 29ce601e..25c2c3c3 100644 --- a/src/services/repository/DraftRepository.php +++ b/src/services/repository/DraftRepository.php @@ -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); }