Skip to content

Commit f39ea33

Browse files
authored
Merge pull request #165 from web-vision/discussion/glossary-handling
[TASK] Change glossary to original handling
2 parents 1a7a771 + f58764d commit f39ea33

File tree

56 files changed

+1645
-734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1645
-734
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
.php-cs-fixer.dist.php export-ignore
1414
.phplint.yml export-ignore
1515
.stylelintrc export-ignore
16+
docker-compose.yaml export-ignore
1617

1718
# Enforce checkout with linux lf consistent over all plattforms
1819
*.xml text eol=lf

Classes/Command/GlossariesEntriesCleanupCommand.php renamed to Classes/Command/GlossaryCleanupCommand.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace WebVision\WvDeepltranslate\Command;
66

7+
use Doctrine\DBAL\DBALException;
78
use Symfony\Component\Console\Command\Command;
89
use Symfony\Component\Console\Helper\ProgressBar;
910
use Symfony\Component\Console\Helper\Table;
@@ -13,9 +14,10 @@
1314
use Symfony\Component\Console\Style\SymfonyStyle;
1415
use TYPO3\CMS\Core\Utility\GeneralUtility;
1516
use WebVision\WvDeepltranslate\Domain\Repository\GlossaryRepository;
17+
use WebVision\WvDeepltranslate\Service\Client\DeepLException;
1618
use WebVision\WvDeepltranslate\Service\DeeplGlossaryService;
1719

18-
class GlossariesEntriesCleanupCommand extends Command
20+
class GlossaryCleanupCommand extends Command
1921
{
2022
protected DeeplGlossaryService $deeplGlossaryService;
2123

@@ -45,17 +47,23 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
4547
{
4648
if (empty($input->getOption('yes'))) {
4749
$io = new SymfonyStyle($input, $output);
48-
$yes = $io->ask('Really all delete? [yY] ');
50+
$yes = $io->ask('Really all delete? [yY]');
4951
if (strtolower($yes) !== 'y') {
50-
$output->writeln('Selectiong wrong. Abort.');
52+
$output->writeln('Abort.');
5153
exit;
5254
}
5355
$input->setOption('yes', true);
5456
}
5557
}
5658

57-
protected function execute(InputInterface $input, OutputInterface $output): int
58-
{
59+
/**
60+
* @throws DeepLException
61+
* @throws DBALException
62+
*/
63+
protected function execute(
64+
InputInterface $input,
65+
OutputInterface $output
66+
): int {
5967
if ($input->getOption('yes') === false) {
6068
$output->writeln('Deletion not confirmed. Cancel.');
6169
/**
@@ -75,6 +83,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7583
return 0;
7684
}
7785

86+
/**
87+
* @throws DeepLException
88+
* @throws DBALException
89+
*/
7890
private function removeAllGlossaryEntries(OutputInterface $output): void
7991
{
8092
$glossaries = $this->deeplGlossaryService->listGlossaries();
@@ -117,7 +129,7 @@ private function removeAllGlossaryEntries(OutputInterface $output): void
117129
$table->render();
118130
$output->writeln('');
119131

120-
$findNotConnected = $this->glossaryRepository->getGlossariesDeeplIdSet();
132+
$findNotConnected = $this->glossaryRepository->getGlossariesDeeplConnected();
121133

122134
if (count($findNotConnected) === 0) {
123135
$output->writeln('No glossaries with sync mismatch.');

Classes/Command/GlossariesEntriesListCommand.php renamed to Classes/Command/GlossaryListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use TYPO3\CMS\Core\Utility\GeneralUtility;
1313
use WebVision\WvDeepltranslate\Service\DeeplGlossaryService;
1414

15-
class GlossariesEntriesListCommand extends Command
15+
class GlossaryListCommand extends Command
1616
{
1717
protected DeeplGlossaryService $deeplGlossaryService;
1818

Classes/Command/GlossarySyncCommand.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Input\InputOption;
1010
use Symfony\Component\Console\Output\OutputInterface;
11+
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
1112
use TYPO3\CMS\Core\Utility\GeneralUtility;
1213
use WebVision\WvDeepltranslate\Domain\Repository\GlossaryRepository;
14+
use WebVision\WvDeepltranslate\Service\Client\DeepLException;
1315
use WebVision\WvDeepltranslate\Service\DeeplGlossaryService;
14-
use WebVision\WvDeepltranslate\Traits\GlossarySyncTrait;
1516

1617
class GlossarySyncCommand extends Command
1718
{
18-
use GlossarySyncTrait;
19-
2019
protected DeeplGlossaryService $deeplGlossaryService;
2120

2221
protected GlossaryRepository $glossaryRepository;
@@ -27,12 +26,16 @@ public function __construct(
2726
?GlossaryRepository $glossaryRepository = null
2827
) {
2928
parent::__construct($name);
30-
$this->deeplGlossaryService = $deeplGlossaryService ?? GeneralUtility::makeInstance(DeeplGlossaryService::class);
31-
$this->glossaryRepository = $glossaryRepository ?? GeneralUtility::makeInstance(GlossaryRepository::class);
29+
$this->deeplGlossaryService = $deeplGlossaryService
30+
?? GeneralUtility::makeInstance(DeeplGlossaryService::class);
31+
$this->glossaryRepository = $glossaryRepository
32+
?? GeneralUtility::makeInstance(GlossaryRepository::class);
3233
}
3334

34-
protected function initialize(InputInterface $input, OutputInterface $output)
35-
{
35+
protected function initialize(
36+
InputInterface $input,
37+
OutputInterface $output
38+
): void {
3639
$this->setDescription('Sync all glossaries to DeepL API')
3740
->addOption(
3841
'pageId',
@@ -43,13 +46,22 @@ protected function initialize(InputInterface $input, OutputInterface $output)
4346
);
4447
}
4548

46-
protected function execute(InputInterface $input, OutputInterface $output): int
47-
{
48-
$pageId = $input->getOption('pageId');
49-
$glossaries = $this->glossaryRepository->findAllGlossaries($pageId);
49+
/**
50+
* @throws DeepLException
51+
* @throws SiteNotFoundException
52+
*/
53+
protected function execute(
54+
InputInterface $input,
55+
OutputInterface $output
56+
): int {
57+
$pageId = (int)$input->getOption('pageId');
58+
$glossaries = [$pageId];
59+
if ($pageId === 0) {
60+
$glossaries = $this->glossaryRepository->findAllGlossaries();
61+
}
5062

5163
foreach ($glossaries as $glossary) {
52-
$this->syncSingleGlossary($glossary['uid']);
64+
$this->deeplGlossaryService->syncGlossaries($glossary['uid']);
5365
}
5466

5567
/**

Classes/Controller/GlossarySyncController.php

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace WebVision\WvDeepltranslate\Controller;
66

77
use Psr\Http\Message\ServerRequestInterface;
8+
use TYPO3\CMS\Core\Exception;
89
use TYPO3\CMS\Core\Http\RedirectResponse;
910
use TYPO3\CMS\Core\Messaging\FlashMessage;
1011
use TYPO3\CMS\Core\Messaging\FlashMessageService;
@@ -13,63 +14,35 @@
1314
use WebVision\WvDeepltranslate\Domain\Repository\GlossaryRepository;
1415
use WebVision\WvDeepltranslate\Exception\InvalidArgumentException;
1516
use WebVision\WvDeepltranslate\Service\DeeplGlossaryService;
16-
use WebVision\WvDeepltranslate\Traits\GlossarySyncTrait;
17-
use WebVision\WvDeepltranslate\Utility\DeeplBackendUtility;
1817

1918
class GlossarySyncController
2019
{
21-
use GlossarySyncTrait;
2220
protected DeeplGlossaryService $deeplGlossaryService;
2321

24-
protected GlossaryRepository $glossaryRepository;
25-
2622
public function __construct(
2723
?DeeplGlossaryService $deeplGlossaryService = null,
2824
?GlossaryRepository $glossaryRepository = null
2925
) {
30-
$this->deeplGlossaryService = $deeplGlossaryService ?? GeneralUtility::makeInstance(DeeplGlossaryService::class);
31-
$this->glossaryRepository = $glossaryRepository ?? GeneralUtility::makeInstance(GlossaryRepository::class);
26+
$this->deeplGlossaryService = $deeplGlossaryService
27+
?? GeneralUtility::makeInstance(DeeplGlossaryService::class);
3228
}
3329

3430
/**
3531
* @throws InvalidArgumentException
32+
* @throws Exception
3633
*/
3734
public function update(ServerRequestInterface $request)
3835
{
3936
$processingParameters = $request->getQueryParams();
4037

41-
if (!isset($processingParameters['mode'])) {
42-
throw new InvalidArgumentException(
43-
'Mode is not defined. Synchronization not completed.',
44-
1676935386416
45-
);
46-
}
47-
48-
if (
49-
$processingParameters['mode'] !== DeeplBackendUtility::RENDER_TYPE_ELEMENT
50-
&& $processingParameters['mode'] !== DeeplBackendUtility::RENDER_TYPE_PAGE
51-
) {
52-
throw new InvalidArgumentException(
53-
'No mode' . $processingParameters['mode'] . ' defined',
54-
1676935573680
55-
);
56-
}
57-
5838
if (!isset($processingParameters['uid'])) {
5939
throw new InvalidArgumentException(
6040
'No ID given for glossary synchronization',
6141
1676935668643
6242
);
6343
}
6444

65-
switch ($processingParameters['mode']) {
66-
case DeeplBackendUtility::RENDER_TYPE_PAGE:
67-
$this->syncGlossariesOfPage((int)$processingParameters['uid']);
68-
break;
69-
case DeeplBackendUtility::RENDER_TYPE_ELEMENT:
70-
$this->syncSingleGlossary((int)$processingParameters['uid']);
71-
break;
72-
}
45+
$this->deeplGlossaryService->syncGlossaries((int)$processingParameters['uid']);
7346

7447
$flashMessage = GeneralUtility::makeInstance(
7548
FlashMessage::class,
@@ -80,21 +53,15 @@ public function update(ServerRequestInterface $request)
8053
LocalizationUtility::translate(
8154
'glossary.sync.title',
8255
'wv_deepltranslate'
83-
)
56+
),
57+
FlashMessage::OK,
58+
true
8459
);
60+
8561
GeneralUtility::makeInstance(FlashMessageService::class)
8662
->getMessageQueueByIdentifier()
8763
->enqueue($flashMessage);
8864

8965
return new RedirectResponse($processingParameters['returnUrl']);
9066
}
91-
92-
private function syncGlossariesOfPage(int $uid): void
93-
{
94-
$glossaries = $this->glossaryRepository->findAllGlossaries($uid);
95-
96-
foreach ($glossaries as $glossary) {
97-
$this->syncSingleGlossary($glossary['uid']);
98-
}
99-
}
10067
}

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
}

0 commit comments

Comments
 (0)