Skip to content

Commit f58764d

Browse files
committed
[TASK] Set glossary not sync when entry was updated
1 parent 166af7c commit f58764d

File tree

6 files changed

+125
-0
lines changed

6 files changed

+125
-0
lines changed

Classes/Domain/Repository/GlossaryEntryRepository.php

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

1010
class GlossaryEntryRepository
1111
{
12+
/**
13+
* @deprecated
14+
*/
1215
public function hasEntriesForGlossary(int $parentId): bool
1316
{
1417
$entries = $this->findEntriesByGlossary($parentId);
@@ -17,6 +20,7 @@ public function hasEntriesForGlossary(int $parentId): bool
1720

1821
/**
1922
* @return array<string, mixed>
23+
* @deprecated
2024
*/
2125
public function findEntriesByGlossary(int $parentId): array
2226
{
@@ -33,4 +37,23 @@ public function findEntriesByGlossary(int $parentId): array
3337

3438
return $result->fetchAll() ?: [];
3539
}
40+
41+
/**
42+
* @return array{uid: int}
43+
*/
44+
public function findEntryByUid(int $uid): array
45+
{
46+
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
47+
->getConnectionForTable('tx_wvdeepltranslate_glossaryentry');
48+
49+
$result = $connection->select(
50+
['*'],
51+
'tx_wvdeepltranslate_glossaryentry',
52+
[
53+
'uid' => $uid,
54+
]
55+
);
56+
57+
return $result->fetch() ?: [];
58+
}
3659
}

Classes/Domain/Repository/GlossaryRepository.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,16 @@ private function getGlossariesInRootByCurrentPage(int $pageId): array
489489
}
490490
return $ids;
491491
}
492+
493+
public function setGlossaryNotSyncOnPage(int $pageId): void
494+
{
495+
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
496+
->getQueryBuilderForTable('tx_wvdeepltranslate_glossary');
497+
498+
$queryBuilder->update('tx_wvdeepltranslate_glossary')
499+
->set('glossary_ready', 0)
500+
->where(
501+
$queryBuilder->expr()->eq('pid', $pageId)
502+
)->execute();
503+
}
492504
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WebVision\WvDeepltranslate\Hooks\Glossary;
6+
7+
use TYPO3\CMS\Core\DataHandling\DataHandler;
8+
use TYPO3\CMS\Core\Messaging\FlashMessage;
9+
use TYPO3\CMS\Core\Messaging\FlashMessageService;
10+
use TYPO3\CMS\Core\Utility\GeneralUtility;
11+
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
12+
use WebVision\WvDeepltranslate\Domain\Repository\GlossaryEntryRepository;
13+
use WebVision\WvDeepltranslate\Domain\Repository\GlossaryRepository;
14+
15+
class UpdatedGlossaryEntryTermHook
16+
{
17+
private GlossaryRepository $glossaryRepository;
18+
19+
private GlossaryEntryRepository $glossaryEntryRepository;
20+
21+
public function __construct(
22+
?GlossaryRepository $glossaryRepository = null,
23+
?GlossaryEntryRepository $glossaryEntryRepository = null
24+
) {
25+
$this->glossaryRepository = $glossaryRepository ?? GeneralUtility::makeInstance(GlossaryRepository::class);
26+
$this->glossaryEntryRepository = $glossaryEntryRepository ?? GeneralUtility::makeInstance(GlossaryEntryRepository::class);
27+
}
28+
29+
/**
30+
* @param int|string $id
31+
* @param array{glossary: int} $fieldArray
32+
*/
33+
public function processDatamap_afterDatabaseOperations(
34+
string $status,
35+
string $table,
36+
$id,
37+
array $fieldArray,
38+
DataHandler $dataHandler
39+
): void {
40+
if ($status !== 'update') {
41+
return;
42+
}
43+
44+
if ($table !== 'tx_wvdeepltranslate_glossaryentry') {
45+
return;
46+
}
47+
48+
$glossary = $this->glossaryEntryRepository->findEntryByUid($id);
49+
50+
if (empty($glossary)) {
51+
return;
52+
}
53+
54+
$this->glossaryRepository->setGlossaryNotSyncOnPage($glossary['pid']);
55+
56+
$flashMessage = new FlashMessage(
57+
LocalizationUtility::translate(
58+
'glossary.not-sync.message',
59+
'wv_deepltranslate'
60+
),
61+
LocalizationUtility::translate(
62+
'glossary.not-sync.title',
63+
'wv_deepltranslate'
64+
),
65+
FlashMessage::INFO,
66+
true
67+
);
68+
69+
GeneralUtility::makeInstance(FlashMessageService::class)
70+
->getMessageQueueByIdentifier()
71+
->enqueue($flashMessage);
72+
}
73+
}

Resources/Private/Language/de.locallang.xlf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@
160160
<source>DeepL Sync ready</source>
161161
<target>DeepL Sync abgeschlossen</target>
162162
</trans-unit>
163+
<trans-unit id="glossary.not-sync.message">
164+
<source>Glossary synchronization with DeepL is pending. Your glossaries are not operational.</source>
165+
<target>Die Glossar-Synchronisierung mit DeepL ist steht aus. Ihre Glossare sind nicht einsatzbereit.</target>
166+
</trans-unit>
167+
<trans-unit id="glossary.not-sync.title">
168+
<source>DeepL Glossary is out of Sync</source>
169+
<taget>DeepL Glossar ist nicht synchronisiert</taget>
170+
</trans-unit>
163171

164172
<trans-unit id="glossaryentry">
165173
<source>Glossary entry</source>

Resources/Private/Language/locallang.xlf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@
148148
<trans-unit id="glossary.sync.title">
149149
<source>DeepL Sync ready</source>
150150
</trans-unit>
151+
<trans-unit id="glossary.not-sync.message">
152+
<source>Glossary synchronization with DeepL is pending. Your glossaries are not operational.</source>
153+
</trans-unit>
154+
<trans-unit id="glossary.not-sync.title">
155+
<source>DeepL Glossary is out of Sync</source>
156+
</trans-unit>
151157

152158
<trans-unit id="glossaryentry">
153159
<source>Glossary entry</source>

ext_localconf.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][]
1919
= \WebVision\WvDeepltranslate\Hooks\AllowLanguageSynchronizationHook::class;
2020

21+
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][]
22+
= \WebVision\WvDeepltranslate\Hooks\Glossary\UpdatedGlossaryEntryTermHook::class;
23+
2124
//hook for translate content
2225
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processTranslateToClass']['deepl']
2326
= \WebVision\WvDeepltranslate\Hooks\TranslateHook::class;

0 commit comments

Comments
 (0)