From 45040143ffac9cc42b692b3b412192d057c1ff97 Mon Sep 17 00:00:00 2001 From: Vitalii Solovei Date: Tue, 19 Aug 2025 09:46:24 +0200 Subject: [PATCH] add current blog constraint for cloning (WP-953) --- composer.json | 2 +- inc/Smartling/Jobs/UploadJob.php | 11 +++++----- .../Submissions/SubmissionManager.php | 21 ++----------------- readme.txt | 5 ++++- smartling-connector.php | 2 +- .../Submissions/SubmissionManagerTest.php | 3 ++- 6 files changed, 16 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index f1f472f5..26e06cf1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "smartling/wordpress-connector", "license": "GPL-2.0-or-later", - "version": "4.3.0", + "version": "4.3.1", "description": "", "type": "wordpress-plugin", "repositories": [ diff --git a/inc/Smartling/Jobs/UploadJob.php b/inc/Smartling/Jobs/UploadJob.php index fd3b440b..c0880aa4 100644 --- a/inc/Smartling/Jobs/UploadJob.php +++ b/inc/Smartling/Jobs/UploadJob.php @@ -41,12 +41,13 @@ public function run(string $source): void if ($source !== '') { $message .= ", source=\"$source\""; } - $message .= '.'; + $blogId = $this->wpProxy->get_current_blog_id(); + $message .= ", blogId=$blogId"; $this->getLogger()->debug("Started $message"); - $this->processUploadQueue($this->wpProxy->get_current_blog_id()); + $this->processUploadQueue($blogId); - $this->processCloning(); + $this->processCloning($blogId); $this->getLogger()->debug("Finished $message"); } @@ -106,9 +107,9 @@ private function processUploadQueue(int $blogId): void } } - private function processCloning(): void + private function processCloning(int $blogId): void { - while (($submission = $this->submissionManager->findSubmissionForCloning()) !== null) { + while (($submission = $this->submissionManager->findSubmissionForCloning($blogId)) !== null) { do_action(ExportedAPI::ACTION_SMARTLING_CLONE_CONTENT, $submission); $this->placeLockFlag(true); } diff --git a/inc/Smartling/Submissions/SubmissionManager.php b/inc/Smartling/Submissions/SubmissionManager.php index 913ea997..afd0b8ec 100644 --- a/inc/Smartling/Submissions/SubmissionManager.php +++ b/inc/Smartling/Submissions/SubmissionManager.php @@ -288,30 +288,13 @@ public function findOne(array $parameters): ?SubmissionEntity return null; } - /** - * Looks for submissions with status = 'New' AND batch_uid <> '' AND is_locked = 0 - */ - public function findSubmissionForUploadJob(): ?SubmissionEntity - { - $pageOptions = ['limit' => 1, 'page' => 1]; - - $query = QueryBuilder::buildSelectQuery( - $this->getDbal()->completeTableName(SubmissionEntity::getTableName()), - array_keys(SubmissionEntity::getFieldDefinitions()), - $this->getConditionBlockForUploadJob(), - [], - $pageOptions - ); - - return $this->fetchData($query)[0] ?? null; - } - - public function findSubmissionForCloning(): ?SubmissionEntity + public function findSubmissionForCloning(int $blogId): ?SubmissionEntity { $block = new ConditionBlock(ConditionBuilder::CONDITION_BLOCK_LEVEL_OPERATOR_AND); $block->addCondition(Condition::getCondition(ConditionBuilder::CONDITION_SIGN_EQ, SubmissionEntity::FIELD_STATUS, [SubmissionEntity::SUBMISSION_STATUS_NEW])); $block->addCondition(Condition::getCondition(ConditionBuilder::CONDITION_SIGN_EQ, SubmissionEntity::FIELD_IS_CLONED, [1])); $block->addCondition(Condition::getCondition(ConditionBuilder::CONDITION_SIGN_EQ, SubmissionEntity::FIELD_IS_LOCKED, [0])); + $block->addCondition(new Condition(ConditionBuilder::CONDITION_SIGN_EQ, SubmissionEntity::FIELD_SOURCE_BLOG_ID, [$blogId])); $data = $this->fetchData(QueryBuilder::buildSelectQuery( $this->getDbal()->completeTableName(SubmissionEntity::getTableName()), diff --git a/readme.txt b/readme.txt index 84a7b919..dd5b00ff 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: translation, localization, localisation, translate, multilingual, smartlin Requires at least: 5.5 Tested up to: 6.6.2 Requires PHP: 8.0 -Stable tag: 4.3.0 +Stable tag: 4.3.1 License: GPLv2 or later Translate content in WordPress quickly and seamlessly with Smartling, the industry-leading Translation Management System. @@ -62,6 +62,9 @@ Additional information on the Smartling Connector for WordPress can be found [he 3. Track translation status within WordPress from the Submissions Board. View overall progress of submitted translation requests as well as resend updated content. == Changelog == += 4.3.1 = +* Changed cloning to only work with submissions from the blog that initiates the cron job + = 4.3.0 = * Cloning should now handle relations for supported external plugins * Added support for Elementor social icons widget diff --git a/smartling-connector.php b/smartling-connector.php index 22c257b2..c6e8fa06 100755 --- a/smartling-connector.php +++ b/smartling-connector.php @@ -11,7 +11,7 @@ * Plugin Name: Smartling Connector * Plugin URI: https://www.smartling.com/products/automate/integrations/wordpress/ * Description: Integrate your WordPress site with Smartling to upload your content and download translations. - * Version: 4.3.0 + * Version: 4.3.1 * Author: Smartling * Author URI: https://www.smartling.com * License: GPL-2.0+ diff --git a/tests/Smartling/Submissions/SubmissionManagerTest.php b/tests/Smartling/Submissions/SubmissionManagerTest.php index a5f53536..4f425421 100644 --- a/tests/Smartling/Submissions/SubmissionManagerTest.php +++ b/tests/Smartling/Submissions/SubmissionManagerTest.php @@ -118,10 +118,11 @@ public function testFindSubmissionsForCloning() $x->expects($this->once())->method('fetchData')->willReturnCallback(function(string $query) { $this->assertStringContainsString("`is_cloned` = '1'", $query); $this->assertStringContainsString("`is_locked` = '0'", $query); + $this->assertStringContainsString("`source_blog_id` = '1'", $query); return []; }); - $x->findSubmissionForCloning(); + $x->findSubmissionForCloning(1); } public function testStoreEmptyEntity()