Skip to content

Commit

Permalink
Merge pull request #455 from AcclaroInc/release/3.2.8
Browse files Browse the repository at this point in the history
Bug/543/super table fields duplicated on merge and apply (#454)
  • Loading branch information
bhupeshappfoster authored Jul 3, 2023
2 parents 816c040 + 813b3e7 commit 417497b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 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.7",
"pluginVersion": "3.2.8",
"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.2.8 - 2023-07-03

### Fixed
- An issue where supertable field blocks were getting duplicated. ([AcclaroInc#453](https://github.com/AcclaroInc/craft-translations/issues/453))

### Updated
- Required Craft version to `4.4.2` to resolve Server side template injection vulnerabilities.

## 3.2.7 - 2023-06-06

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
],
"require": {
"craftcms/cms": "^4.0.0",
"craftcms/cms": "^4.4.2",
"guzzlehttp/guzzle": "^7.0",
"composer/composer": "^2.1.9",
"spatie/guzzle-rate-limiter-middleware": "^2.0"
Expand Down
16 changes: 16 additions & 0 deletions src/services/repository/EntryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ private function makeNewDraft($canonical, $creatorId, $name, $notes, $newAttribu

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

// Create the draft row
$draftId = (new Drafts())->insertDraftRow($name, $notes, $creatorId, $canonical->id, $canonical::trackChanges(), $provisional);

Expand All @@ -82,8 +86,20 @@ private function makeNewDraft($canonical, $creatorId, $name, $notes, $newAttribu
'trackChanges' => $canonical::trackChanges(),
];

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

if ($isNewForSite) {
// 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)) {
throw new \Exception("Failed to save draft in target site");
}
$draft = Craft::$app->getElements()->propagateElement($draft, $targetSiteId);
}

$transaction->commit();
} catch (\Throwable $e) {
$transaction->rollBack();
Expand Down

0 comments on commit 417497b

Please sign in to comment.