Skip to content

Commit 1985b61

Browse files
Merge pull request #552 from Smartling/WP-920-add-profiles-filter-and-download-option
add manual download mode, add profile filter (WP-920)
2 parents d388dc5 + f0968ea commit 1985b61

7 files changed

Lines changed: 54 additions & 21 deletions

File tree

inc/Smartling/Base/ExportedAPI.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Smartling\Helpers\EventParameters\SmartlingFileUriFilterParamater;
99
use Smartling\Helpers\EventParameters\TranslationStringFilterParameters;
1010
use Smartling\Models\NotificationParameters;
11-
use Smartling\Models\UploadQueueEntity;
1211
use Smartling\Models\UploadQueueItem;
12+
use Smartling\Settings\ConfigurationProfileEntity;
1313
use Smartling\Submissions\SubmissionEntity;
1414
use Smartling\Vendor\Symfony\Component\DependencyInjection\ContainerBuilder;
1515

@@ -225,4 +225,9 @@ interface ExportedAPI
225225
* @param array items
226226
*/
227227
public const FILTER_BULK_SUBMIT_PREPARE_ITEMS = 'smartling_filter_bulk_submit_prepare_items';
228+
229+
/**
230+
* @param ConfigurationProfileEntity[]
231+
*/
232+
public const FILTER_ACTIVE_PROFILES = 'smartling_filter_active_profiles';
228233
}

inc/Smartling/Jobs/LastModifiedCheckJob.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ protected function processFileUriSet(array $submissions, bool $failMissing): arr
115115
return $submissions;
116116
}
117117

118-
/**
119-
* @param array $serializedPair
120-
* @return bool
121-
*/
122118
private function validateSerializedPair(array $serializedPair): bool
123119
{
124120
$result = false;
@@ -198,7 +194,7 @@ protected function processDownloadOnChange(array $submissions): void
198194
foreach ($submissions as $submission) {
199195
$profile = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId());
200196

201-
if (($profile instanceof ConfigurationProfileEntity) && 1 === $profile->getDownloadOnChange()) {
197+
if (ConfigurationProfileEntity::TRANSLATION_DOWNLOAD_MODE_PROGRESS_CHANGES === $profile->getDownloadOnChange()) {
202198
$this->getLogger()
203199
->debug(vsprintf('Adding submission %s to Download queue as it was changed.', [$submission->getId()]));
204200
$this->queue->enqueue([$submission->getId()], QueueInterface::QUEUE_NAME_DOWNLOAD_QUEUE);
@@ -240,15 +236,15 @@ public function statusCheck(array $submissions): void
240236
$submissions = $this->submissionManager->storeSubmissions($statusCheckResult);
241237

242238
foreach ($submissions as $submission) {
243-
$this->checkEntityForDownload($submission);
239+
$profile = $this->settingsManager->getSingleSettingsProfile($submission->getSourceBlogId());
240+
if ($profile->getDownloadOnChange() !== ConfigurationProfileEntity::TRANSLATION_DOWNLOAD_MODE_MANUAL) {
241+
$this->checkEntityForDownload($submission);
242+
}
244243
}
245244

246245
$this->getLogger()->debug('Processing status check finished.');
247246
}
248247

249-
/**
250-
* @param SubmissionEntity $entity
251-
*/
252248
public function checkEntityForDownload(SubmissionEntity $entity): void
253249
{
254250
if (100 === $entity->getCompletionPercentage() && 1 !== $entity->getIsCloned()) {
@@ -271,10 +267,6 @@ public function checkEntityForDownload(SubmissionEntity $entity): void
271267
}
272268
}
273269

274-
/**
275-
* @param SubmissionEntity $submission
276-
* @return string
277-
*/
278270
public function getSmartlingLocaleIdBySubmission(SubmissionEntity $submission): string
279271
{
280272
return $this->settingsManager

inc/Smartling/Settings/ConfigurationProfileEntity.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class ConfigurationProfileEntity extends SmartlingEntityAbstract
2020

2121
public const UPLOAD_ON_CHANGE_AUTO = 1;
2222

23+
public const TRANSLATION_DOWNLOAD_MODE_TRANSLATION_COMPLETED = 0;
24+
public const TRANSLATION_DOWNLOAD_MODE_PROGRESS_CHANGES = 1;
25+
public const TRANSLATION_DOWNLOAD_MODE_MANUAL = 2;
26+
27+
2328
public const TRANSLATION_PUBLISHING_MODE_NO_CHANGE = 0;
2429
public const TRANSLATION_PUBLISHING_MODE_PUBLISH = 1;
2530
public const TRANSLATION_PUBLISHING_MODE_DRAFT = 2;
@@ -353,7 +358,6 @@ public function setChangeAssetStatusOnCompletedTranslation(int $status): void
353358
/**
354359
* Alias for $this->setChangeAssetStatusOnCompletedTranslation, required for EntityAbstract::fromArray();
355360
* @noinspection PhpUnused
356-
* @noinspection UnknownInspectionInspection
357361
*/
358362
public function setPublishCompleted(int $publishCompleted): void
359363
{

inc/Smartling/Settings/SettingsManager.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace Smartling\Settings;
44

5+
use Smartling\Base\ExportedAPI;
56
use Smartling\DbAl\EntityManagerAbstract;
7+
use Smartling\DbAl\LocalizationPluginProxyInterface;
8+
use Smartling\DbAl\SmartlingToCMSDatabaseAccessWrapperInterface;
69
use Smartling\Exception\BlogNotFoundException;
710
use Smartling\Exception\SmartlingConfigException;
811
use Smartling\Exception\SmartlingDbException;
@@ -11,11 +14,23 @@
1114
use Smartling\Helpers\QueryBuilder\Condition\ConditionBlock;
1215
use Smartling\Helpers\QueryBuilder\Condition\ConditionBuilder;
1316
use Smartling\Helpers\QueryBuilder\QueryBuilder;
17+
use Smartling\Helpers\SiteHelper;
1418
use Smartling\Helpers\TestRunHelper;
19+
use Smartling\Helpers\WordpressFunctionProxyHelper;
1520
use Smartling\Submissions\SubmissionEntity;
1621

1722
class SettingsManager extends EntityManagerAbstract
1823
{
24+
public function __construct(
25+
SmartlingToCMSDatabaseAccessWrapperInterface $dbal,
26+
int $pageSize,
27+
SiteHelper $siteHelper,
28+
LocalizationPluginProxyInterface $localizationProxy,
29+
private WordpressFunctionProxyHelper $wpProxy,
30+
) {
31+
parent::__construct($dbal, $pageSize, $siteHelper, $localizationProxy);
32+
}
33+
1934
/**
2035
* @return ConfigurationProfileEntity[]
2136
*/
@@ -44,7 +59,18 @@ public function getActiveProfiles(): array
4459
{
4560
$cnt = 0;
4661

47-
return $this->getEntities($cnt, true);
62+
$profiles = $this->wpProxy->apply_filters(
63+
ExportedAPI::FILTER_ACTIVE_PROFILES,
64+
$this->getEntities($cnt, true),
65+
);
66+
foreach ($profiles as $profile) {
67+
if (!$profile instanceof ConfigurationProfileEntity) {
68+
throw new \RuntimeException('Expected instance of ' . ConfigurationProfileEntity::class . ', got ' .
69+
is_object($profile) ? get_class($profile) : gettype($profile));
70+
}
71+
}
72+
73+
return $profiles;
4874
}
4975

5076
/**

inc/Smartling/WP/View/ConfigurationProfileForm.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,9 @@ class="toggleExpert"><strong><?= __('Show Expert Settings', $domain) ?></strong>
652652
HtmlTagGeneratorHelper::renderSelectOptions(
653653
$profile->getDownloadOnChange(),
654654
[
655-
0 => __('Translation Completed', $domain),
656-
1 => __('Progress Changes', $domain),
655+
ConfigurationProfileEntity::TRANSLATION_DOWNLOAD_MODE_TRANSLATION_COMPLETED => __('Translation Completed', $domain),
656+
ConfigurationProfileEntity::TRANSLATION_DOWNLOAD_MODE_PROGRESS_CHANGES => __('Progress Changes', $domain),
657+
ConfigurationProfileEntity::TRANSLATION_DOWNLOAD_MODE_MANUAL => __('Manual', $domain),
657658
]
658659
),
659660
['name' => 'smartling_settings[download_on_change]'])

inc/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ services:
288288
- "%submission.pagesize%"
289289
- "@site.helper"
290290
- "@multilang.proxy"
291+
- "@wp.proxy"
291292

292293
plugin.info:
293294
class: Smartling\Helpers\PluginInfo

readme.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,18 @@ Additional information on the Smartling Connector for WordPress can be found [he
6262
3. Track translation status within WordPress from the Submissions Board. View overall progress of submitted translation requests as well as resend updated content.
6363

6464
== Changelog ==
65+
= 3.9.17 =
66+
* Added `smartling_filter_active_profiles` filter
67+
* Added `Manual` translation download mode
68+
6569
= 3.9.16 =
66-
* Exclude WordPress built in style editor strings from translation
70+
* Excluded WordPress built in style editor strings from translation
6771

6872
= 3.9.15 =
69-
* Add expert setting to skip ACF filter `acf_parse_save_blocks` removal. Defaults to on.
73+
* Added expert setting to skip ACF filter `acf_parse_save_blocks` removal. Defaults to on.
7074

7175
= 3.9.14 =
72-
* Remove excessive logging
76+
* Removed excessive logging
7377

7478
= 3.9.13 =
7579
* Improved handling of service strings inside nested ACF fields: they no longer should be sent for translation

0 commit comments

Comments
 (0)