Skip to content

add current blog constraint for cloning (WP-953) #577

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
11 changes: 6 additions & 5 deletions inc/Smartling/Jobs/UploadJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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);
}
Expand Down
21 changes: 2 additions & 19 deletions inc/Smartling/Submissions/SubmissionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obsolete, unused

{
$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()),
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Comment on lines +65 to +67
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember you mentioned that this is some specific to some client setup. But will this still work for any other clients who do not run cron from the specific blog?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defaults to blog 1 by default, which most clients use as the source

= 4.3.0 =
* Cloning should now handle relations for supported external plugins
* Added support for Elementor social icons widget
Expand Down
2 changes: 1 addition & 1 deletion smartling-connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down
3 changes: 2 additions & 1 deletion tests/Smartling/Submissions/SubmissionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down