Skip to content

Commit f14569c

Browse files
authored
Merge pull request #134 from lilt/4.x-ignore-dropdowns
Add setting to ignore all dropdowns
2 parents bcabb9b + e90b7b0 commit f14569c

File tree

7 files changed

+98
-7
lines changed

7 files changed

+98
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 4.4.1 - 2023-11-08
8+
### Added
9+
- Ignore dropdowns setting
10+
711
## 4.4.0 - 2023-10-04
812
### Added
913
- Queue manager

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "lilt/craft-lilt-plugin",
33
"description": "The Lilt plugin makes it easy for you to send content to Lilt for translation right from within Craft CMS.",
44
"type": "craft-plugin",
5-
"version": "4.4.0",
5+
"version": "4.4.1",
66
"keywords": [
77
"craft",
88
"cms",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* General Configuration
5+
*
6+
* All of your system's general configuration settings go in here. You can see a
7+
* list of the available settings in vendor/craftcms/cms/src/config/GeneralConfig.php.
8+
*
9+
* @see \craft\config\GeneralConfig
10+
*/
11+
12+
use craft\helpers\App;
13+
14+
$isDev = App::env('ENVIRONMENT') === 'dev';
15+
$isProd = App::env('ENVIRONMENT') === 'production';
16+
17+
return [
18+
// Default Week Start Day (0 = Sunday, 1 = Monday...)
19+
'defaultWeekStartDay' => 1,
20+
21+
// Whether generated URLs should omit "index.php"
22+
'omitScriptNameInUrls' => true,
23+
24+
// The URI segment that tells Craft to load the control panel
25+
'cpTrigger' => App::env('CP_TRIGGER') ?: 'admin',
26+
27+
// The secure key Craft will use for hashing and encrypting data
28+
'securityKey' => App::env('SECURITY_KEY'),
29+
30+
// Whether Dev Mode should be enabled (see https://craftcms.com/guides/what-dev-mode-does)
31+
'devMode' => true,
32+
33+
// Whether administrative changes should be allowed
34+
'allowAdminChanges' => true,
35+
36+
// Whether updates should be allowed
37+
'allowUpdates' => $isDev,
38+
39+
// Whether crawlers should be allowed to index pages and following links
40+
'disallowRobots' => !$isProd,
41+
42+
'aliases' => [
43+
'@assetBasePath' => App::env('ASSET_BASE_PATH') ?: "./assets",
44+
'@assetBaseUrl' => App::env('ASSET_BASE_URL') ?: "/assets",
45+
],
46+
];

src/modules/FetchJobStatusFromConnector.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ public function execute($queue): void
6161
return;
6262
}
6363

64+
$mutex = Craft::$app->getMutex();
65+
$mutexKey = $this->getMutexKey();
66+
if (!$mutex->acquire($mutexKey)) {
67+
Craft::error(sprintf('Job %s is already processing job %d', __CLASS__, $this->jobId));
68+
69+
$this->markAsDone($queue);
70+
return;
71+
}
72+
6473
$liltJob = Craftliltplugin::getInstance()->connectorJobRepository->findOneById($this->liltJobId);
6574
$isJobFinished = $liltJob->getStatus() !== JobResponse::STATUS_PROCESSING
6675
&& $liltJob->getStatus() !== JobResponse::STATUS_QUEUED;
@@ -314,6 +323,10 @@ public function getRetryJob(): BaseJob
314323

315324
public static function getDelay(): int
316325
{
326+
if (!Craft::$app->config->general->devMode) {
327+
return self::DELAY_IN_SECONDS;
328+
}
329+
317330
$envDelay = getenv('CRAFT_LILT_PLUGIN_QUEUE_DELAY_IN_SECONDS');
318331
if (!empty($envDelay) || $envDelay === '0') {
319332
return (int)$envDelay;

src/services/ServiceInitializer.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public function run(): void
9898
'class' => ListenerRegister::class,
9999
'availableListeners' => CraftliltpluginParameters::LISTENERS,
100100
],
101+
'settingsRepository' => [
102+
'class' => SettingsRepository::class,
103+
],
101104
]);
102105

103106
$pluginInstance->setComponents([
@@ -153,7 +156,7 @@ function () {
153156
]);
154157

155158
$getProvidersMap = static function () use ($pluginInstance) {
156-
return [
159+
$providersMap = [
157160
CraftliltpluginParameters::CRAFT_FIELDS_PLAINTEXT => new PlainTextContentProvider(),
158161
CraftliltpluginParameters::CRAFT_REDACTOR_FIELD => new RedactorPluginFieldContentProvider(),
159162
CraftliltpluginParameters::CRAFT_FIELDS_TABLE => new TableContentProvider(),
@@ -179,6 +182,13 @@ function () {
179182
#SuperTable Plugin
180183
CraftliltpluginParameters::CRAFT_FIELDS_SUPER_TABLE => new ElementQueryContentProvider(),
181184
];
185+
186+
//TODO: make it in proper way
187+
if (Craftliltplugin::getInstance()->settingsRepository->ignoreDropdowns()) {
188+
unset($providersMap[CraftliltpluginParameters::CRAFT_FIELDS_DROPDOWN]);
189+
}
190+
191+
return $providersMap;
182192
};
183193

184194
$pluginInstance->set(
@@ -261,10 +271,6 @@ function () {
261271
'class' => ConnectorFileRepository::class,
262272
'apiInstance' => $pluginInstance->connectorJobsApi,
263273
],
264-
'settingsRepository' =>
265-
[
266-
'class' => SettingsRepository::class,
267-
],
268274
'editJobHandler' =>
269275
[
270276
'class' => EditJobHandler::class,

src/services/providers/field/FieldContentProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function provide(ProvideContentCommand $provideContentCommand)
2525
{
2626
$fieldClass = get_class($provideContentCommand->getField());
2727

28-
if (!isset($this->providersMap[$fieldClass])) {
28+
if (!isset($this->providersMap[$fieldClass]) || empty($this->providersMap[$fieldClass])) {
2929
return null;
3030
}
3131

src/services/repositories/SettingsRepository.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace lilthq\craftliltplugin\services\repositories;
1111

12+
use Craft;
13+
use lilthq\craftliltplugin\parameters\CraftliltpluginParameters;
1214
use lilthq\craftliltplugin\records\SettingRecord;
1315

1416
class SettingsRepository
@@ -19,6 +21,8 @@ class SettingsRepository
1921
public const QUEUE_EACH_TRANSLATION_FILE_SEPARATELY = 'queue_each_translation_file_separately';
2022
public const QUEUE_MANAGER_EXECUTED_AT = 'queue_manager_executed_at';
2123

24+
public const IGNORE_DROPDOWNS = 'ignore_dropdowns';
25+
2226
public function saveLiltApiConnectionConfiguration(string $connectorApiUrl, string $connectorApiKey): void
2327
{
2428
# connectorApiKey
@@ -52,6 +56,24 @@ public function isQueueEachTranslationFileSeparately(): bool
5256
return (bool)$settingValue->value;
5357
}
5458

59+
public function ignoreDropdowns(): bool
60+
{
61+
$tableSchema = Craft::$app->getDb()->schema->getTableSchema(CraftliltpluginParameters::SETTINGS_TABLE_NAME);
62+
if ($tableSchema === null) {
63+
return false;
64+
}
65+
66+
$settingValue = SettingRecord::findOne(
67+
['name' => SettingsRepository::IGNORE_DROPDOWNS]
68+
);
69+
70+
if (empty($settingValue) || empty($settingValue->value)) {
71+
return false;
72+
}
73+
74+
return (bool)$settingValue->value;
75+
}
76+
5577
public function save(string $name, string $value): bool
5678
{
5779
$settingRecord = SettingRecord::findOne(['name' => $name]);

0 commit comments

Comments
 (0)