Repository navigation
store configuration profile for delivery (WP-1021) #636
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
Changes from all commits
d19e3fc
54ca0fa
b8e4092
06bdd03
908058a
537700e
f7b967f
f969608
32c79eb
412cba1
d78346e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| namespace Smartling\DbAl\Migrations; | ||
|
|
||
| use Smartling\DbAl\DB; | ||
| use Smartling\Submissions\SubmissionEntity; | ||
|
|
||
| /** | ||
| * Stores the configuration profile a submission was requested with. | ||
| * | ||
| * Existing rows are left NULL: until stamped, they keep resolving the profile by source | ||
| * blog. SubmissionManager::getSubmissionEntity() backfills the column with the currently | ||
| * active profile the first time a pre-existing submission is (re)submitted for translation, | ||
| * so an in-flight row stays NULL only until it is next touched by an upload/resubmit flow. | ||
| */ | ||
| class Migration261001 implements SmartlingDbMigrationInterface | ||
| { | ||
| public function getVersion(): int | ||
| { | ||
| return 261001; | ||
| } | ||
|
|
||
| public function getQueries($tablePrefix = 'wp_'): array | ||
| { | ||
| $db = new DB(); | ||
| $tableName = $db->completeTableName(SubmissionEntity::getTableName()); | ||
|
|
||
| // Migration240315 may already have created the table with the current field definitions. | ||
| $existingColumns = $db->getColumnArray("SHOW COLUMNS FROM `$tableName`"); | ||
| if (in_array(SubmissionEntity::FIELD_CONFIGURATION_PROFILE_ID, $existingColumns, true)) { | ||
| return []; | ||
| } | ||
|
|
||
| return [ | ||
| sprintf( | ||
| 'ALTER TABLE `%s` ADD COLUMN `%s` %s', | ||
| $tableName, | ||
| SubmissionEntity::FIELD_CONFIGURATION_PROFILE_ID, | ||
| SubmissionEntity::getFieldDefinitions()[SubmissionEntity::FIELD_CONFIGURATION_PROFILE_ID] | ||
| ), | ||
| ]; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,7 +111,7 @@ public function removeIgnoringFields(SubmissionEntity $submission, array $data): | |
| $this->prepareSourceData($data) | ||
| ), | ||
| $this->contentSerializationHelper->prepareFieldProcessorValues($submission)['ignore'], | ||
| $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId())->getFilterFieldNameRegExp()), | ||
| $this->settingsManager->getProfileBySubmission($submission)->getFilterFieldNameRegExp()), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 suggestion $profile = $this->settingsManager->getProfileBySubmission($submission);
// ... $profile->getFilterFieldNameRegExp()
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved |
||
| ); | ||
| } | ||
|
|
||
|
|
@@ -128,18 +128,19 @@ public function processStringsBeforeEncoding( | |
| } | ||
|
|
||
| $settings = $this->contentSerializationHelper->prepareFieldProcessorValues($submission); | ||
| $filterFieldNameRegExp = $this->settingsManager->getProfileBySubmission($submission)->getFilterFieldNameRegExp(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 warning Fix: resolve the profile in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed — |
||
|
|
||
| return $this->passConnectionProfileFilters( | ||
| $this->passFieldProcessorsBeforeSendFilters( | ||
| $submission, | ||
| $this->removeFields( | ||
| $this->flattenArray($data), | ||
| $settings['ignore'], | ||
| $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId())->getFilterFieldNameRegExp(), | ||
| $filterFieldNameRegExp, | ||
| ) | ||
| ), | ||
| $strategy, | ||
| $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId())->getFilterFieldNameRegExp(), | ||
| $filterFieldNameRegExp, | ||
| $settings, | ||
| ); | ||
| } | ||
|
|
@@ -174,17 +175,19 @@ public function applyTranslatedValues(SubmissionEntity $submission, array $origi | |
|
|
||
| private function filterArray(array $array, SubmissionEntity $submission, string $strategy, array $settings): array | ||
| { | ||
| $filterFieldNameRegExp = $this->settingsManager->getProfileBySubmission($submission)->getFilterFieldNameRegExp(); | ||
|
|
||
| return $this->passConnectionProfileFilters( | ||
| $this->passFieldProcessorsFilters( | ||
| $submission, | ||
| $this->removeFields( | ||
| $array, | ||
| $settings['ignore'], | ||
| $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId())->getFilterFieldNameRegExp(), | ||
| $filterFieldNameRegExp, | ||
| ), | ||
| ), | ||
| $strategy, | ||
| $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId())->getFilterFieldNameRegExp(), | ||
| $filterFieldNameRegExp, | ||
| $this->contentSerializationHelper->prepareFieldProcessorValues($submission), | ||
| ); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 critical
Credentials/project now come from the stored profile, but the locale passed to the API still comes from the active profile:
SettingsManager::getSmartlingLocaleBySubmission()(SettingsManager.php:95) still callsgetSingleSettingsProfile($submission->getSourceBlogId()). It is used bydownloadFile()(line 189) andgetStatus()(line 215) here, plusUploadQueueManager::getSmartlingLocale()andSmartlingCoreTrait.Scenario: submission stamped with profile A (project A, target blog 2 →
de-DE), user switches active profile to B (blog 2 →de, or blog 2 not mapped). Status check / download for A's file goes to project A with B's locale, or throwsSmartlingConfigException→ automated delivery fails, which is exactly the WP-1021 case.Fix:
plus a test with stored ≠ active profile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed —
getSmartlingLocaleBySubmission()now callsgetProfileBySubmission()instead ofgetSingleSettingsProfile(), matchingApiWrapper::getConfigurationProfile(). It falls back to the active profile exactly the same waygetProfileBySubmission()already does for the no-stamp/deleted-profile cases, sodownloadFile()/getStatus()/UploadQueueManager::getSmartlingLocale()/SmartlingCoreTraitall pick this up automatically. Added a test with stored profile A (localede-DE) vs. active profile B, asserting A's locale is used andgetSingleSettingsProfile()is never called.