Skip to content
Open
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
Binary file added inc/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion inc/Smartling/ApiWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct(SettingsManager $manager, string $pluginName, string
*/
private function getConfigurationProfile(SubmissionEntity $submission): ConfigurationProfileEntity
{
$profile = $this->settings->getSingleSettingsProfile($submission->getSourceBlogId());
$profile = $this->settings->getProfileBySubmission($submission);
LogContextMixinHelper::addToContext('projectId', $profile->getProjectId());

if (TestRunHelper::isTestRunBlog($submission->getTargetBlogId())) {
Expand Down
2 changes: 1 addition & 1 deletion inc/Smartling/Base/SmartlingCoreAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function syncAttachment(SubmissionEntity $submission): void
$submission->getTargetId(),
])
);
$profile = $this->getSettingsManager()->getSingleSettingsProfile($submission->getSourceBlogId());
$profile = $this->getSettingsManager()->getProfileBySubmission($submission);
if (1 === $profile->getAlwaysSyncImagesOnUpload() || ($submission->getStatus() === SubmissionEntity::SUBMISSION_STATUS_NEW && !$targetFileExists)) {
$this->syncMediaFile($submission);
}
Expand Down
8 changes: 4 additions & 4 deletions inc/Smartling/Base/SmartlingCoreDownloadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function downloadTranslationBySubmission(SubmissionEntity $entity): void
LiveNotificationController::pushNotification(
$this
->getSettingsManager()
->getSingleSettingsProfile($entity->getSourceBlogId())
->getProfileBySubmission($entity)
->getProjectId(),
LiveNotificationController::getContentId($entity),
LiveNotificationController::SEVERITY_SUCCESS,
Expand All @@ -65,7 +65,7 @@ public function downloadTranslationBySubmission(SubmissionEntity $entity): void
LiveNotificationController::pushNotification(
$this
->getSettingsManager()
->getSingleSettingsProfile($entity->getSourceBlogId())
->getProfileBySubmission($entity)
->getProjectId(),
LiveNotificationController::getContentId($entity),
LiveNotificationController::SEVERITY_SUCCESS,
Expand All @@ -78,7 +78,7 @@ public function downloadTranslationBySubmission(SubmissionEntity $entity): void
LiveNotificationController::pushNotification(
$this
->getSettingsManager()
->getSingleSettingsProfile($entity->getSourceBlogId())
->getProfileBySubmission($entity)
->getProjectId(),
LiveNotificationController::getContentId($entity),
LiveNotificationController::SEVERITY_SUCCESS,
Expand All @@ -100,7 +100,7 @@ public function downloadTranslationBySubmission(SubmissionEntity $entity): void
LiveNotificationController::pushNotification(
$this
->getSettingsManager()
->getSingleSettingsProfile($entity->getSourceBlogId())
->getProfileBySubmission($entity)
->getProjectId(),
LiveNotificationController::getContentId($entity),
LiveNotificationController::SEVERITY_ERROR,
Expand Down
8 changes: 5 additions & 3 deletions inc/Smartling/Base/SmartlingCoreUploadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ protected function getFunctionProxyHelper(): WordpressFunctionProxyHelper

public function prepareUpload(SubmissionEntity $submission): SubmissionEntity
{
$this->getSubmissionManager()->stampConfigurationProfile($submission);

return $this->renewContentHash(
$this->createTargetContent(
$this->setFileUriIfNullId($submission)
Expand Down Expand Up @@ -259,7 +261,7 @@ public function applyXML(SubmissionEntity $submission, string $xml, XmlHelper $x
$targetContent = $targetContent->fromArray($translation['entity']);
}
$configurationProfile = $this->getSettingsManager()
->getSingleSettingsProfile($submission->getSourceBlogId());
->getProfileBySubmission($submission);

$percentage = $submission->getCompletionPercentage();
$this->getLogger()->debug(vsprintf('Current percentage is %s', [$percentage]));
Expand Down Expand Up @@ -424,7 +426,7 @@ public function bulkSubmit(UploadQueueItem $item): void
}
$submission = $item->getSubmissions()[0];
$locales = $item->getSmartlingLocales()->getList();
$profile = $this->getSettingsManager()->getSingleSettingsProfile($submission->getSourceBlogId());
$profile = $this->getSettingsManager()->getProfileBySubmission($submission);
try {
$xml = $this->getXMLFiltered($submission);
if ($xml === '') {
Expand Down Expand Up @@ -530,7 +532,7 @@ public function sendForTranslation(UploadQueueItem $item): void
return;
}

$configurationProfile = $this->getSettingsManager()->getSingleSettingsProfile($item->getSubmissions()[0]->getSourceBlogId());
$configurationProfile = $this->getSettingsManager()->getProfileBySubmission($item->getSubmissions()[0]);

// Clone attachment submission instead of uploading it, if "Clone attachment"
// option is enabled in configuration profile.
Expand Down
41 changes: 41 additions & 0 deletions inc/Smartling/DbAl/Migrations/Migration261001.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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 on purpose: the profile active today is not necessarily the
* one they were uploaded with, so they keep resolving the profile by source blog.
*/
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]
),
];
}
}
2 changes: 1 addition & 1 deletion inc/Smartling/DbAl/UploadQueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function purge(): void
}
if (!array_key_exists($submission->getSourceBlogId(), $profiles)) {
try {
$profile = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId());
$profile = $this->settingsManager->getProfileBySubmission($submission);
} catch (SmartlingDbException) {
$profile = null;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/Smartling/FTS/FtsApiWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
*/
private function getConfigurationProfile(SubmissionEntity $submission): ConfigurationProfileEntity
{
return $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId());
return $this->settingsManager->getProfileBySubmission($submission);
}

private function getFileTranslationsApi(ConfigurationProfileEntity $profile): FileTranslationsApiExtended
Expand Down
6 changes: 3 additions & 3 deletions inc/Smartling/FTS/FtsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function requestInstantTranslationBatch(array $submissions): array
try {
$fileUid = $this->uploadFile($firstSubmission);

$profile = $this->settingsManager->getSingleSettingsProfile($firstSubmission->getSourceBlogId());
$profile = $this->settingsManager->getProfileBySubmission($firstSubmission);
$sourceLocale = $this->apiWrapper->getSourceLocale($profile);
$targetLocales = [];

Expand Down Expand Up @@ -304,7 +304,7 @@ private function submitFile(SubmissionEntity $submission, string $fileUid): stri
{
$this->getLogger()->debug("Submitting file for instant translation, submissionId={$submission->getId()}, fileUid=$fileUid");

$profile = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId());
$profile = $this->settingsManager->getProfileBySubmission($submission);
$sourceLocale = $this->apiWrapper->getSourceLocale($profile);
$targetLocale = $profile->getSmartlingLocale($submission->getTargetBlogId());

Expand Down Expand Up @@ -398,7 +398,7 @@ private function downloadAndApply(SubmissionEntity $submission, string $fileUid,
{
$this->getLogger()->info("Downloading and applying translation, submissionId={$submission->getId()}, fileUid=$fileUid, mtUid=$mtUid");

$profile = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId());
$profile = $this->settingsManager->getProfileBySubmission($submission);
$targetLocale = $profile->getSmartlingLocale($submission->getTargetBlogId());

if (empty($targetLocale)) {
Expand Down
2 changes: 1 addition & 1 deletion inc/Smartling/Helpers/DetectChangesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function update(SubmissionEntity $submission, bool $needUpdateStatus, st

LiveNotificationController::pushNotification(
$this->settingsManager
->getSingleSettingsProfile($submission->getSourceBlogId())
->getProfileBySubmission($submission)
->getProjectId(),
LiveNotificationController::getContentId($submission),
LiveNotificationController::SEVERITY_WARNING,
Expand Down
10 changes: 5 additions & 5 deletions inc/Smartling/Helpers/FieldsFilterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
);
}

Expand All @@ -135,11 +135,11 @@ public function processStringsBeforeEncoding(
$this->removeFields(
$this->flattenArray($data),
$settings['ignore'],
$this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId())->getFilterFieldNameRegExp(),
$this->settingsManager->getProfileBySubmission($submission)->getFilterFieldNameRegExp(),
)
),
$strategy,
$this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId())->getFilterFieldNameRegExp(),
$this->settingsManager->getProfileBySubmission($submission)->getFilterFieldNameRegExp(),
$settings,
);
}
Expand Down Expand Up @@ -180,11 +180,11 @@ private function filterArray(array $array, SubmissionEntity $submission, string
$this->removeFields(
$array,
$settings['ignore'],
$this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId())->getFilterFieldNameRegExp(),
$this->settingsManager->getProfileBySubmission($submission)->getFilterFieldNameRegExp(),
),
),
$strategy,
$this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId())->getFilterFieldNameRegExp(),
$this->settingsManager->getProfileBySubmission($submission)->getFilterFieldNameRegExp(),
$this->contentSerializationHelper->prepareFieldProcessorValues($submission),
);
}
Expand Down
2 changes: 1 addition & 1 deletion inc/Smartling/Helpers/SubstringProcessorHelperAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private function passProfileFilters(array $attributes)
$fFilter = $this->getFieldsFilter();

$settings = $this->contentSerializationHelper->prepareFieldProcessorValues($submission);
$removeAsRegExp = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId())->getFilterFieldNameRegExp();
$removeAsRegExp = $this->settingsManager->getProfileBySubmission($submission)->getFilterFieldNameRegExp();
$attributes = $fFilter->removeFields($attributes, $settings['ignore'], $removeAsRegExp);
$attributes = $fFilter->removeFields($attributes, $settings['copy']['name'], $removeAsRegExp);

Expand Down
2 changes: 1 addition & 1 deletion inc/Smartling/Helpers/XmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function xmlEncode(array $source, SubmissionEntity $submission, array $or
{
$this->getLogger()->debug(sprintf('Started creating XML for fields: %s', base64_encode(var_export($source, true))));
try {
$profile = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId());
$profile = $this->settingsManager->getProfileBySubmission($submission);
} catch (SmartlingDbException) {
$profile = null;
}
Expand Down
6 changes: 3 additions & 3 deletions inc/Smartling/Jobs/LastModifiedCheckJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private function lastModifiedCheck(string $queueName, bool $failMissing): void
protected function processDownloadOnChange(array $submissions): void
{
foreach ($submissions as $submission) {
$profile = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId());
$profile = $this->settingsManager->getProfileBySubmission($submission);

if (ConfigurationProfileEntity::TRANSLATION_DOWNLOAD_MODE_PROGRESS_CHANGES === $profile->getDownloadOnChange()) {
$this->getLogger()
Expand Down Expand Up @@ -238,7 +238,7 @@ public function statusCheck(array $submissions): void
$submissions = $this->submissionManager->storeSubmissions($statusCheckResult);

foreach ($submissions as $submission) {
$profile = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId());
$profile = $this->settingsManager->getProfileBySubmission($submission);
if ($profile->getDownloadOnChange() !== ConfigurationProfileEntity::TRANSLATION_DOWNLOAD_MODE_MANUAL) {
$this->checkEntityForDownload($submission);
}
Expand Down Expand Up @@ -273,7 +273,7 @@ public function getSmartlingLocaleIdBySubmission(SubmissionEntity $submission):
{
return $this->settingsManager
->getSmartlingLocaleIdBySettingsProfile(
$this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId()),
$this->settingsManager->getProfileBySubmission($submission),
$submission->getTargetBlogId()
);
}
Expand Down
14 changes: 11 additions & 3 deletions inc/Smartling/Jobs/UploadJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,24 @@ private function processUploadQueue(int $blogId): void
$submission->setFileUri($this->fileUriHelper->generateFileUri($submission));
$this->submissionManager->storeEntity($submission);
}
if (!array_key_exists($submission->getSourceBlogId(), $profiles)) {
// Existing submissions are loaded from the queue by id, so they never pass through
// SubmissionManager::getSubmissionEntity(): remember the profile used for this upload here.
$previousProfileId = $submission->getConfigurationProfileId();
$this->submissionManager->stampConfigurationProfile($submission);
if ($submission->getConfigurationProfileId() !== $previousProfileId) {
$this->submissionManager->storeEntity($submission);
}
$profileKey = $submission->getConfigurationProfileId() ?? "blog{$submission->getSourceBlogId()}";
if (!array_key_exists($profileKey, $profiles)) {
try {
$profiles[$submission->getSourceBlogId()] = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId());
$profiles[$profileKey] = $this->settingsManager->getProfileBySubmission($submission);
} catch (SmartlingDbException) {
$this->failItem($item, 'Skipping upload of', "No active profile found for blogId={$submission->getSourceBlogId()}");
$this->uploadQueueManager->complete($item);
continue;
}
}
$profile = $profiles[$submission->getSourceBlogId()];
$profile = $profiles[$profileKey];
if ($item->getBatchUid() === '') {
try {
$item = $item->setBatchUid($this->api->getOrCreateJobInfoForDailyBucketJob($profile, [$submission->getFileUri()])->getBatchUid());
Expand Down
20 changes: 20 additions & 0 deletions inc/Smartling/Settings/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ public function getSingleSettingsProfile(int $mainBlogId): ConfigurationProfileE
throw new SmartlingDbException($message);
}

/**
* Returns the profile the submission was requested with, so delivery doesn't depend on which profile is active now.
* Falls back to the active profile of the source blog for submissions without a stored (or an existing) profile.
*
* @throws SmartlingDbException
*/
public function getProfileBySubmission(SubmissionEntity $submission): ConfigurationProfileEntity
{
$profileId = $submission->getConfigurationProfileId();
if ($profileId !== null) {
$profile = ArrayHelper::first($this->getEntityById($profileId));
if ($profile instanceof ConfigurationProfileEntity) {
return $profile;
}
$this->getLogger()->warning("Profile id=$profileId stored for submission id={$submission->getId()} not found, using active profile of source blog");
}

return $this->getSingleSettingsProfile($submission->getSourceBlogId());
}

/**
* @return int[]
* @throws SmartlingDbException
Expand Down
16 changes: 16 additions & 0 deletions inc/Smartling/Submissions/SubmissionEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class SubmissionEntity extends SmartlingEntityAbstract implements Submission
public const FIELD_LAST_ERROR = 'last_error';
public const FIELD_LOCKED_FIELDS = 'locked_fields';
public const FIELD_CREATED_AT = 'created_at';
public const FIELD_CONFIGURATION_PROFILE_ID = 'configuration_profile_id';

public const VIRTUAL_FIELD_JOB_LINK = 'job_link';

Expand Down Expand Up @@ -117,6 +118,7 @@ public static function getFieldDefinitions(): array
static::FIELD_LAST_ERROR => static::DB_TYPE_STRING_TEXT,
static::FIELD_LOCKED_FIELDS => 'TEXT NULL',
static::FIELD_CREATED_AT => static::DB_TYPE_DATETIME,
static::FIELD_CONFIGURATION_PROFILE_ID => 'INT(20) UNSIGNED NULL',
];
}

Expand Down Expand Up @@ -515,6 +517,20 @@ public function setSubmitter(string $submitter): SubmissionEntity
return $this;
}

public function getConfigurationProfileId(): ?int
{
$value = $this->stateFields[static::FIELD_CONFIGURATION_PROFILE_ID];

return $value === null ? null : (int)$value;
}

public function setConfigurationProfileId(?int $configurationProfileId): self
{
$this->stateFields[static::FIELD_CONFIGURATION_PROFILE_ID] = $configurationProfileId;

return $this;
}

public function getCreatedAt(): ?string
{
return $this->stateFields[static::FIELD_CREATED_AT];
Expand Down
Loading
Loading