Skip to content

Commit

Permalink
Release/3.3.0 (#472)
Browse files Browse the repository at this point in the history
* fixed: error shown in dev mode when a new update is available

* fixed: draft not created when entry is disabled in target site

* fixed: error opening static translation page after craft 4.5.0

* fixed: file upload error

* updated: change log and version bumped
  • Loading branch information
bhupeshappfoster authored Sep 26, 2023
1 parent 416f402 commit 551aeb0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 30 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": "3.2.10",
"pluginVersion": "3.3.0",
"pluginAuthorName": "Acclaro",
"pluginVendorName": "Acclaro",
"pluginAuthorUrl": "http://www.acclaro.com/",
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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/).

## 3.3.0 - 2023-09-26

### Fixed
- An issue uploading files after craft 4.5.0 update.
- An issue where create draft was failing and showing success message to user. ([AcclaroInc#463](https://github.com/AcclaroInc/craft-translations/issues/463))
- An issue where static translation page was showing error after craft 4.5.0 update. ([AcclaroInc#468](https://github.com/AcclaroInc/craft-translations/issues/468))
- An issue where error was thrown in craft dev mode when a plugin update is available. ([AcclaroInc#461](https://github.com/AcclaroInc/craft-translations/issues/461))

## 3.2.10 - 2023-09-04

### Updated
Expand Down
8 changes: 2 additions & 6 deletions src/controllers/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ public function actionImportFile()

$fileInfo = pathinfo($filename);

$uploadVolumeId = ArrayHelper::getValue(Translations::getInstance()->getSettings(), 'uploadVolume');

$folder = Craft::$app->getAssets()->getRootFolderByVolumeId($uploadVolumeId);
$folder = Craft::$app->getAssets()->getUserTemporaryUploadFolder();

$pathInfo = pathinfo($file);

Expand Down Expand Up @@ -313,9 +311,7 @@ public function actionImportFile()
} else {
$filename = Assets::prepareAssetName($file->name);

$uploadVolumeId = ArrayHelper::getValue(Translations::getInstance()->getSettings(), 'uploadVolume');

$folder = Craft::$app->getAssets()->getRootFolderByVolumeId($uploadVolumeId);
$folder = Craft::$app->getAssets()->getUserTemporaryUploadFolder();

$compatibleFilename = $file->tempName . '.' . Constants::FILE_FORMAT_TXT;

Expand Down
32 changes: 18 additions & 14 deletions src/services/repository/DraftRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,22 @@ public function createDrafts($element, $order, $site, $wordCounts, $file=null)
{
$element = $element->getIsDraft() ? $element->getCanonical() : $element;

switch (get_class($element)) {
case Product::class:
$draft = Translations::$plugin->commerceRepository->createDraft($element, $site, $order->title);
break;
case GlobalSet::class:
$draft = Translations::$plugin->globalSetDraftRepository->createDraft($element, $site, $order->title);
break;
case Asset::class:
$draft = Translations::$plugin->assetDraftRepository->createDraft($element, $site, $order->title, $order->sourceSite);
break;
default:
$draft = Translations::$plugin->entryRepository->createDraft($element, $site, $order->title);
try {
switch (get_class($element)) {
case Product::class:
$draft = Translations::$plugin->commerceRepository->createDraft($element, $site, $order->title);
break;
case GlobalSet::class:
$draft = Translations::$plugin->globalSetDraftRepository->createDraft($element, $site, $order->title);
break;
case Asset::class:
$draft = Translations::$plugin->assetDraftRepository->createDraft($element, $site, $order->title, $order->sourceSite);
break;
default:
$draft = Translations::$plugin->entryRepository->createDraft($element, $site, $order->title);
}
} catch(Exception $e) {
throw $e;
}

if (!($file instanceof FileModel)) {
Expand All @@ -273,7 +277,7 @@ public function createDrafts($element, $order, $site, $wordCounts, $file=null)

if (empty($draft)) {
Translations::$plugin->logHelper->log( '['. __METHOD__ .'] Empty draft found: Order'.json_decode($order), Constants::LOG_LEVEL_ERROR );
return false;
throw new \Exception("Unable to create draft.");
}

if (!$file->hasPreview()) {
Expand Down Expand Up @@ -302,7 +306,7 @@ public function createDrafts($element, $order, $site, $wordCounts, $file=null)

Translations::$plugin->fileRepository->saveFile($file);

return false;
throw $e;
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/services/repository/EntryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public function createDraft(ElementInterface $entry, $site, $orderName)
return $draft;
} catch (\Exception $e) {
Translations::$plugin->logHelper->log( '['. __METHOD__ .'] CreateDraft exception:: '.$e->getMessage(), Constants::LOG_LEVEL_ERROR );
return [];
throw new \Exception("Creating draft.");
}
}

private function makeNewDraft($canonical, $creatorId, $name, $notes, $newAttributes, $provisional = false)
{
$canonical = $canonical->getIsDraft() ? $canonical->getCanonical() : $canonical;
$canonical = $canonical->getIsDraft() ? $canonical->getCanonical() : $canonical;
// Fire a 'beforeCreateDraft' event
$event = new DraftEvent([
'canonical' => $canonical,
Expand All @@ -64,12 +64,11 @@ private function makeNewDraft($canonical, $creatorId, $name, $notes, $newAttribu
$this->trigger('beforeCreateDraft', $event);
$name = $event->draftName;
$notes = $event->draftNotes;

$transaction = Craft::$app->getDb()->beginTransaction();
try {
$targetSiteId = $newAttributes['siteId'];
$enabledForSites = Craft::$app->getElements()->getEnabledSiteIdsForElement($canonical->id);
$isNewForSite = !in_array($targetSiteId, $enabledForSites);
$entryInTargetSite = Translations::$plugin->elementRepository->getElementById($canonical->id, $targetSiteId);

// Create the draft row
$draftId = (new Drafts())->insertDraftRow($name, $notes, $creatorId, $canonical->id, $canonical::trackChanges(), $provisional);
Expand All @@ -86,12 +85,12 @@ private function makeNewDraft($canonical, $creatorId, $name, $notes, $newAttribu
'trackChanges' => $canonical::trackChanges(),
];

if ($isNewForSite) {
if (!$entryInTargetSite) {
unset($newAttributes['siteId']);
}
$draft = Craft::$app->getElements()->duplicateElement($canonical, $newAttributes);

if ($isNewForSite) {
if (!$entryInTargetSite) {
// We can only set the target site it it does not exist else craft erros out.
$draft->siteId = $targetSiteId;
if (!Craft::$app->getElements()->saveElement($draft)) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/repository/StaticTranslationsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private function getFileStrings($path, $file, ElementQueryInterface $query, $cat
$translateId = ElementHelper::normalizeSlug($original);
$view = Craft::$app->getView();
$site = Craft::$app->getSites()->getSiteById($query->siteId);
$translation = Craft::t($category, $original, null, $site->language);
$translation = Craft::t($category, $original, [], $site->language);

$field = $view->renderTemplate('_includes/forms/text', [
'id' => $translateId,
Expand Down
2 changes: 1 addition & 1 deletion src/templates/_index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="edition-name">{{ edition }}</div>
<div class="edition-trial">{{ craft.app.getPlugins().getPlugin(pluginHandle).getVersion() }}</div>
</div>
{% if updates and updates.releases %}
{% if updates %}
<a class="btn small go" href="utilities/updates" data-icon="info" style="margin: 7px 0px 10px 0px;"> Update available</a>
{% endif %}
{% endblock %}
Expand Down

0 comments on commit 551aeb0

Please sign in to comment.