Skip to content

Commit

Permalink
[TASK] Cleanup of x-classing classes
Browse files Browse the repository at this point in the history
Refactoring pointed out that parts of the x-classed code are identical to the
core. Remove this avoiding issues during bug fixes and security patches inside
the core, which we must handle ourselves.
  • Loading branch information
calien666 committed Dec 19, 2024
1 parent aadc945 commit 1560c1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 129 deletions.
9 changes: 7 additions & 2 deletions Classes/Override/Core12/DatabaseRecordList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
namespace WebVision\Deepltranslate\Core\Override\Core12;

use WebVision\Deepltranslate\Core\Access\AllowedTranslateAccess;
use WebVision\Deepltranslate\Core\Event\DisallowTableFromDeeplTranslateEvent;
use WebVision\Deepltranslate\Core\Utility\DeeplBackendUtility;

/**
* Class for rendering of Web>List module
*
* @internal
* @override
*/
class DatabaseRecordList extends \TYPO3\CMS\Backend\RecordList\DatabaseRecordList
{
Expand All @@ -28,8 +32,9 @@ public function makeLocalizationPanel($table, $row, array $translations): string
return $out;
}

// glossaries should not be auto translated by DeepL
if ($table === 'tx_wvdeepltranslate_glossaryentry') {
$tableDisallowedEvent = new DisallowTableFromDeeplTranslateEvent($table);
$this->eventDispatcher->dispatch($tableDisallowedEvent);
if ($tableDisallowedEvent->isTranslateButtonsAllowed() === false) {
return $out;
}

Expand Down
127 changes: 0 additions & 127 deletions Classes/Override/LocalizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,133 +44,6 @@ public function __construct()
$this->pageRenderer->addInlineLanguageLabelFile('EXT:deepltranslate_core/Resources/Private/Language/locallang.xlf');
}

/**
* Get used languages in a page
*/
public function getUsedLanguagesInPage(ServerRequestInterface $request): ResponseInterface
{
$params = $request->getQueryParams();
if (!isset($params['pageId'], $params['languageId'])) {
return new JsonResponse(null, 400);
}

$pageId = (int)$params['pageId'];
$languageId = (int)$params['languageId'];
$mode = $params['mode'] ?? '';

/** @var TranslationConfigurationProvider $translationProvider */
$translationProvider = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
$systemLanguages = $translationProvider->getSystemLanguages($pageId);

$availableLanguages = [];

// First check whether column has localized records
$elementsInColumnCount = $this->localizationRepository->getLocalizedRecordCount($pageId, $languageId);
$result = [];
if ($elementsInColumnCount !== 0) {
// check elements in column - empty if source records do not exist anymore
$result = $this->localizationRepository->fetchOriginLanguage($pageId, $languageId);
if ($result !== []) {
$availableLanguages[] = $systemLanguages[$result['sys_language_uid']];
}
}
if ($elementsInColumnCount === 0 || $result === []) {
$fetchedAvailableLanguages = $this->localizationRepository->fetchAvailableLanguages($pageId, $languageId);
foreach ($fetchedAvailableLanguages as $language) {
if (isset($systemLanguages[$language['sys_language_uid']])) {
$availableLanguages[] = $systemLanguages[$language['sys_language_uid']];
}
}
}
// Language "All" should not appear as a source of translations (see bug 92757) and keys should be sequential
$availableLanguages = array_values(
array_filter($availableLanguages, static function (array $languageRecord): bool {
return (int)$languageRecord['uid'] !== -1;
})
);

//for DeepL auto mode
if (!empty($availableLanguages)) {
if ($mode == 'localizedeeplauto') {
foreach ($availableLanguages as &$availableLanguage) {
$availableLanguage['uid'] = 'auto-' . $availableLanguage['uid'];
$availableLanguage['ISOcode'] = 'AUT';
}
}
}

// Pre-render all flag icons
foreach ($availableLanguages as &$language) {
if ($language['flagIcon'] === 'empty-empty') {
$language['flagIcon'] = '';
} else {
$language['flagIcon'] = $this->iconFactory->getIcon($language['flagIcon'], Icon::SIZE_SMALL)->render();
}
}

return (new JsonResponse())->setPayload($availableLanguages);
}

/**
* Get a prepared summary of records being translated
*
* @param ServerRequestInterface $request
* @return ResponseInterface
* @throws Exception
*/
public function getRecordLocalizeSummary(ServerRequestInterface $request): ResponseInterface
{
$params = $request->getQueryParams();
if (!isset($params['pageId'], $params['destLanguageId'], $params['languageId'])) {
return new JsonResponse(null, 400);
}

$pageId = (int)$params['pageId'];
$destLanguageId = (int)$params['destLanguageId'];
//getting source language id
$languageId = $this->getSourceLanguageId($params['languageId']);

$records = [];
$result = $this->localizationRepository->getRecordsToCopyDatabaseResult(
$pageId,
$destLanguageId,
$languageId,
'*'
);

$flatRecords = [];
while ($row = $result->fetchAssociative()) {
BackendUtility::workspaceOL('tt_content', $row, -99, true);
if (!$row || VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
continue;
}
$colPos = $row['colPos'];
if (!isset($records[$colPos])) {
$records[$colPos] = [];
}
$records[$colPos][] = [
'icon' => $this->iconFactory->getIconForRecord('tt_content', $row, Icon::SIZE_SMALL)->render(),
'title' => $row[$GLOBALS['TCA']['tt_content']['ctrl']['label']],
'uid' => $row['uid'],
];
$flatRecords[] = $row;
}

$payloadBody = [
'records' => $records,
'columns' => $this->getPageColumns($pageId, $flatRecords, $params),
];

$event = new AfterRecordSummaryForLocalizationEvent($payloadBody['records'], $payloadBody['columns']);
$this->eventDispatcher->dispatch($event);
$payloadBody = [
'records' => $event->getRecords(),
'columns' => $event->getColumns(),
];

return (new JsonResponse())->setPayload($payloadBody);
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
Expand Down

0 comments on commit 1560c1b

Please sign in to comment.