ImportExtensionsFromQueueTask.php 23.4 KB
Newer Older
1
<?php
2

3
namespace T3o\TerFe2\Task;
4

5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8 9 10
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
11
 *
12 13
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
14
 *
15 16 17
 * The TYPO3 project - inspiring people to share!
 */

18
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
19
use Psr\Log\LoggerInterface;
20
use TYPO3\CMS\Core\Database\ConnectionPool;
21
use TYPO3\CMS\Core\Log\LogManager;
22
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
23
use TYPO3\CMS\Core\Utility\GeneralUtility;
24
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
25
use TYPO3\CMS\Extbase\Scheduler\Task;
26
use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
27 28 29 30 31

/**
 * Class ImportExtensionsFromQueueTask
 */
class ImportExtensionsFromQueueTask extends Task
32 33 34 35 36 37 38
{

    /**
     * PID for all extension related records
     *
     * @var int $pid
     */
39
    protected $pidExtensions = 2;
40

41 42 43 44 45
    /**
     * @var LoggerInterface
     */
    protected $logger;

46 47 48 49 50 51 52
    /**
     * executes the importer
     *
     * @return bool
     */
    public function execute()
    {
53 54
        $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);

55 56
        $this->logger->info('Task ImportExtensionsFromQueueTask started');

57 58 59 60
        $extensionsFromQueue = $this->getExtensionsFromQueue();

        // finish task if no extensions in queue
        if (empty($extensionsFromQueue)) {
61
            $this->logger->info('No new extensions in queue table');
62 63

            return true;
64 65 66 67 68 69 70
        }

        foreach ($extensionsFromQueue as $ext) {
            $extensionData = $this->getExtensionData($ext['extensionuid']);
            if (!$this->versionExists($extensionData)) {
                $extUid = $this->extensionExists($extensionData);
                $this->saveExtension($extUid, $extensionData, $ext['crdate']);
71 72
                $this->logger->info(sprintf(
                    'Extension "%s" version %s saved in ter_fe2',
73 74
                    $extensionData['extensionkey'],
                    $extensionData['version']
75
                ));
76 77

                // update the EXT:solr Index Queue
78
                if (ExtensionManagementUtility::isLoaded('solr')) {
79
                    $indexQueue = GeneralUtility::makeInstance(Queue::class);
80 81 82
                    $indexQueue->updateItem('tx_terfe2_domain_model_extension', $extUid);
                }
            }
83 84
            $this->logger->info(sprintf(
                'Extension "%s" still exists in ter_fe2 with version %s',
85 86
                $extensionData['extensionkey'],
                $extensionData['version']
87
            ));
88 89 90
            $this->removeExtensionFromQueue($ext['extensionuid']);
        }

91 92 93 94 95
        if (count($extensionsFromQueue) > 0) {
            $cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
            $cacheManager->flushCaches();
        }

96 97
        $this->logger->info('Task ImportExtensionsFromQueueTask finished');

98
        return true;
99 100
    }

101 102 103
    /**
     * @param int $extUid
     */
104 105
    public function removeExtensionFromQueue($extUid)
    {
106 107 108 109 110 111 112 113 114 115 116
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);

        $queryBuilder = $connectionPool->getQueryBuilderForTable('tx_ter_extensionqueue');
        $queryBuilder
            ->update('tx_ter_extensionqueue')
            ->where(
                $queryBuilder->expr()->eq('extensionuid', $extUid)
            )
            ->set('tstamp', time())
            ->set('imported_to_fe', 1)
            ->execute();
117 118 119 120 121 122 123 124 125 126
    }

    /**
     * Gets extensions from queue which
     * are not imported yet in ter_fe2
     *
     * @return array $extensions Extensions in queue table
     */
    public function getExtensionsFromQueue()
    {
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
        $tableName = 'tx_ter_extensionqueue';
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $statement = $queryBuilder
            ->select('extensionuid', 'crdate')
            ->from($tableName)
            ->where(
                $queryBuilder->expr()->eq('deleted', 0),
                $queryBuilder->expr()->eq('imported_to_fe', 0)
            )
            ->orderBy('crdate')
            ->execute();
        $statement->execute();

        return $statement->fetchAll(\PDO::FETCH_ASSOC);
143 144 145 146 147 148 149 150 151 152 153
    }

    /**
     * Gets the extension data out of ter tables
     *
     * @param int $extensionUid
     *
     * @return array $extData
     */
    public function getExtensionData($extensionUid)
    {
154 155 156 157 158 159 160 161
        $tableName = 'tx_ter_extensions';
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $statement = $queryBuilder
            ->select('exts.*', 'extdetails.*')
            ->from($tableName, 'exts')
162 163 164 165
            ->leftJoin(
                'exts',
                'tx_ter_extensiondetails',
                'extdetails',
166 167 168 169 170 171 172 173 174
                $queryBuilder->expr()->eq('exts.uid', $queryBuilder->quoteIdentifier('extdetails.extensionuid'))
            )
            ->where(
                $queryBuilder->expr()->eq('exts.uid', (int)$extensionUid)
            )
            ->execute();
        $statement->execute();

        return $statement->fetch(\PDO::FETCH_ASSOC);
175 176 177 178 179 180 181 182
    }

    /**
     * checks if a version with a specific version
     * string exists
     *
     * @param array $extData
     *
183
     * @return bool
184 185 186
     */
    public function versionExists($extData)
    {
187 188 189 190 191 192 193 194
        $tableName = 'tx_terfe2_domain_model_version';
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $statement = $queryBuilder
            ->count('ver.uid')
            ->from($tableName, 'ver')
195 196 197 198
            ->leftJoin(
                'ver',
                'tx_terfe2_domain_model_extension',
                'ext',
199 200 201 202 203 204 205 206 207 208
                $queryBuilder->expr()->eq('ext.uid', $queryBuilder->quoteIdentifier('ver.extension'))
            )
            ->where(
                $queryBuilder->expr()->eq('ver.deleted', 0),
                $queryBuilder->expr()->eq('ver.version_string', $queryBuilder->createNamedParameter($extData['version'])),
                $queryBuilder->expr()->eq('ext.ext_key', $queryBuilder->createNamedParameter($extData['extensionkey']))
            )
            ->execute();
        $statement->execute();

209
        return $statement->fetchColumn(0) > 0;
210 211 212 213 214 215 216 217 218
    }

    /**
     * @param array $extData
     *
     * @return int $uid extension uid
     */
    public function extensionExists($extData)
    {
219 220 221 222 223 224 225 226 227 228 229 230 231 232
        $tableName = 'tx_terfe2_domain_model_extension';
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $statement = $queryBuilder
            ->select('uid')
            ->from($tableName)
            ->where(
                $queryBuilder->expr()->eq('deleted', 0),
                $queryBuilder->expr()->eq('ext_key', $queryBuilder->createNamedParameter($extData['extensionkey']))
            )
            ->execute();
        $statement->execute();
        $extRec = $statement->fetch(\PDO::FETCH_ASSOC);
233 234 235
        if ($extRec) {
            return $extRec['uid'];
        }
236

237 238 239 240 241 242 243 244 245 246
        return $this->createExtension($extData);
    }

    /**
     * @param array $extData
     *
     * @return int $uid extension uid of new record
     */
    public function createExtension($extData)
    {
247
        $insertExtension = [
248
            'pid' => $this->pidExtensions,
249 250 251 252 253 254 255 256
            'ext_key' => $extData['extensionkey'],
            'last_upload' => time(),
            'last_maintained' => time(),
            'versions' => 0,
            'last_version' => 0,
            'frontend_user' => $extData['lastuploadbyusername'],
            'crdate' => time(),
            'tstamp' => time()
257 258
        ];

259 260 261
        $tableName = 'tx_terfe2_domain_model_extension';
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
        $queryBuilder = $connectionPool->getQueryBuilderForTable($tableName);
262

263
        $queryBuilder->insert($tableName)->values($insertExtension)->execute();
264 265

        return $connectionPool->getConnectionForTable($tableName)->lastInsertId($tableName);
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
    }

    /**
     * @param int $extUid
     * @param array $extData
     * @param int $crdate
     */
    public function saveExtension($extUid, $extData, $crdate)
    {
        $versionUid = $this->createVersion($extUid, $extData, $crdate);
        if ($versionUid) {
            $this->addRelations($versionUid, $extData['dependencies']);
            $this->updateExtension($versionUid, $extUid);
        }
    }

    /**
     * @param int $extUid
     * @param array $extData
     * @param int $crdate
     *
     * @return int $versionUid
     */
    public function createVersion($extUid, $extData, $crdate)
    {
291
        $extensionModel = GeneralUtility::makeInstance(Extension::class);
292
        $states = $extensionModel->getDefaultState(null);
293
        $categories = \T3o\TerFe2\Utility\CategoryUtility::getDefaultCategories();
294 295 296 297 298

        $folder1 = substr($extData['extensionkey'], 0, 1);
        $folder2 = substr($extData['extensionkey'], 1, 1);
        $t3xFile = PATH_site . 'fileadmin/ter/' . $folder1 . '/' . $folder2 . '/' . $extData['extensionkey'] . '_' . $extData['version'] . '.t3x';

299
        $insertVersion = [
300 301
            'pid' => $this->pidExtensions,
            'crdate' => (int)$crdate,
302 303 304 305 306
            'tstamp' => time(),
            'extension' => $extUid,
            'title' => $extData['title'],
            'description' => $extData['description'],
            'author' => $this->createAuthor($extData),
307
            'version_number' => VersionNumberUtility::convertVersionNumberToInteger($extData['version']),
308 309 310 311 312 313
            'version_string' => $extData['version'],
            'upload_date' => $crdate,
            'upload_comment' => $extData['uploadcomment'],
            'file_hash' => $extData['t3xfilemd5'],
            'download_counter' => 0,
            'frontend_download_counter' => 0,
314 315
            'state' => in_array((string)$extData['state'], $states) ? (string)$extData['state'] : 'n/a',
            'em_category' => array_key_exists((string)$extData['category'], $categories) ? (string)$extData['category'] : '',
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
            'load_order' => $extData['loadorder'],
            'priority' => $extData['priority'],
            'shy' => (boolean)$extData['shy'],
            'uploadfolder' => $extData['uploadfolder'] ? $extData['uploadfolder'] : '',
            'create_dirs' => $extData['createdirs'] ? $extData['createdirs'] : '',
            'modify_tables' => $extData['modifytables'] ? $extData['modifytables'] : '',
            'lock_type' => $extData['locktype'] ? $extData['locktype'] : '',
            'clear_cache_on_load' => (boolean)$extData['clearcacheonload'],
            'cgl_compliance' => $extData['codingguidelinescompliance'] ? $extData['codingguidelinescompliance'] : '',
            'cgl_compliance_note' => $extData['codingguidelinescompliancenote'] ? $extData['codingguidelinescompliancenote'] : '',
            'review_state' => 0,
            'manual' => '',
            'has_manual' => (boolean)$extData['ismanualincluded'],
            'software_relations' => 0,
            'extension_provider' => 'file',
            'has_zip_file' => 0,
            'has_images' => 0,
            't3x_file_size' => @filesize($t3xFile),
334 335
            'zip_file_size' => 0,
            'composer_info' => $extData['composerinfo']
336 337
        ];

338 339
        $this->ensureValidComposerNameInExtension($extUid, $extData['composerinfo']);

340 341 342 343
        $tableName = 'tx_terfe2_domain_model_version';
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
        $queryBuilder = $connectionPool->getQueryBuilderForTable($tableName);

344
        $queryBuilder->insert($tableName)->values($insertVersion)->execute();
345

346
        return $connectionPool->getConnectionForTable($tableName)->lastInsertId($tableName);
347 348
    }

349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
    private function ensureValidComposerNameInExtension(int $extUid, string $composerInfoJson)
    {
        $composerInfo = @\json_decode($composerInfoJson, true);
        if (empty($composerInfo['name'])) {
            return;
        }

        $tableName = 'tx_terfe2_domain_model_extension';
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
        $queryBuilder = $connectionPool->getQueryBuilderForTable($tableName);
        $persistedComposerName = $queryBuilder->select('composer_name')
            ->from($tableName)
            ->where(
                $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($extUid, \PDO::PARAM_INT))
            )
            ->execute()
            ->fetchColumn();

        if (empty($persistedComposerName) || $persistedComposerName === $composerInfo['name']) {
            return;
        }

        $queryBuilder = $connectionPool->getQueryBuilderForTable($tableName);
        $queryBuilder->update($tableName)
            ->set('composer_name', '')
            ->where(
                $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($extUid, \PDO::PARAM_INT))
            )
            ->execute();
    }

380 381 382 383 384 385
    /**
     * @param int $versionUid
     * @param int $extUid
     */
    public function updateExtension($versionUid, $extUid)
    {
386 387
        $highestVersionUid = $this->calculatedHighestVersion($versionUid, $extUid);

388 389 390 391 392 393 394 395 396 397 398 399 400 401
        $tableName = 'tx_terfe2_domain_model_extension';
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
        $queryBuilder = $connectionPool->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $queryBuilder
            ->update($tableName)
            ->set('tstamp', time())
            ->set('versions', $this->getNumberOfVersions($extUid))
            ->set('last_version', $highestVersionUid)
            ->where(
                $queryBuilder->expr()->eq('uid', $extUid)
            )
            ->execute();
402 403 404 405 406 407 408 409 410
    }

    /**
     * @param int $extUid
     *
     * @return int $numberOfVersions
     */
    public function getNumberOfVersions($extUid)
    {
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
        $tableName = 'tx_terfe2_domain_model_version';
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
        $queryBuilder = $connectionPool->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $statement = $queryBuilder
            ->count('uid')
            ->from($tableName)
            ->where(
                $queryBuilder->expr()->eq('extension', $extUid),
                $queryBuilder->expr()->eq('deleted', 0)
            )
            ->execute();
        $statement->execute();

        return $statement->fetchColumn(0);
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
    }

    /**
     * @param int $versionUid
     * @param string $dependencies
     */
    public function addRelations($versionUid, $dependencies)
    {
        $countRelations = 0;
        $dependencies = unserialize($dependencies);
        foreach ($dependencies as $relation) {
            $relationType = $relation['kind'];
            $relationKey = $relation['extensionKey'];
            $version = $this->getVersionByRange($relation['versionRange']);
            if ($relationKey) {
442
                $insertRelation = [
443 444 445 446 447 448
                    'relation_type' => $relationType,
                    'relation_key' => $relationKey,
                    'minimum_version' => $version[0],
                    'maximum_version' => $version[1],
                    'version' => $versionUid,
                    'related_extension' => $this->getUidOfRelatedExtension($relationKey)
449
                ];
450
                $countRelations++;
451 452 453 454

                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
                    ->getQueryBuilderForTable('tx_terfe2_domain_model_relation');

455
                $queryBuilder->insert('tx_terfe2_domain_model_relation')->values($insertRelation)->execute();
456 457 458
            }
        }

459 460 461 462 463 464 465 466 467 468
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable('tx_terfe2_domain_model_relation');

        $queryBuilder
            ->update('tx_terfe2_domain_model_version')
            ->set('software_relations', $countRelations)
            ->where(
                $queryBuilder->expr()->eq('uid', $versionUid)
            )
            ->execute();
469 470 471 472 473 474 475 476 477
    }

    /**
     * @param string $extKey
     *
     * @return int $uidOfRelatedExtension
     */
    public function getUidOfRelatedExtension($extKey)
    {
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
        $tableName = 'tx_terfe2_domain_model_extension';
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $statement = $queryBuilder
            ->select('uid')
            ->from($tableName)
            ->where(
                $queryBuilder->expr()->eq('ext_key', $queryBuilder->createNamedParameter($extKey)),
                $queryBuilder->expr()->eq('deleted', 0)
            )
            ->execute();
        $statement->execute();

        $extRec = $statement->fetch(\PDO::FETCH_ASSOC);
494 495 496
        if ($extRec['uid']) {
            return $extRec['uid'];
        }
497

498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
        return 0;
    }

    /**
     * @param array $extData
     *
     * @return int $authorUid
     */
    public function getAuthor($extData)
    {
        return $this->authorExists($extData);
    }

    /**
     * @param array $extData
     *
     * @return int $authorUid
     */
    public function authorExists($extData)
    {
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
        $tableName = 'tx_terfe2_domain_model_author';
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $statement = $queryBuilder
            ->select('uid')
            ->from($tableName)
            ->where(
                $queryBuilder->expr()->eq('deleted', 0),
                $queryBuilder->expr()->eq('username', $queryBuilder->createNamedParameter($extData['lastuploadbyusername'])),
                $queryBuilder->expr()->eq('name', $queryBuilder->createNamedParameter($extData['authorname'])),
                $queryBuilder->expr()->eq('email', $queryBuilder->createNamedParameter($extData['authoremail'])),
                $queryBuilder->expr()->eq('company', $queryBuilder->createNamedParameter($extData['authorcompany']))
            )
            ->execute();
        $statement->execute();

        $authorRec = $statement->fetch(\PDO::FETCH_ASSOC);
537 538 539 540 541 542 543 544 545 546 547 548 549 550
        if ($authorRec['uid']) {
            return $authorRec['uid'];
        }

        return $this->createAuthor($extData);
    }

    /**
     * @param array $extData
     *
     * @return int $authorUid
     */
    public function createAuthor($extData)
    {
551
        $insertAuthor = [
552 553 554 555 556
            'name' => $extData['authorname'],
            'email' => $extData['authoremail'],
            'company' => $extData['authorcompany'],
            'username' => $extData['lastuploadbyusername'],
            'frontend_user' => $this->getFeUserUidFromUsername($extData['lastuploadbyusername'])
557 558
        ];

559 560 561 562
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
        $tableName = 'tx_terfe2_domain_model_author';
        $queryBuilder = $connectionPool->getQueryBuilderForTable($tableName);

563
        $queryBuilder->insert($tableName)->values($insertAuthor)->execute();
564

565
        return $connectionPool->getConnectionForTable($tableName)->lastInsertId($tableName);
566 567 568 569 570 571 572 573 574
    }

    /**
     * @param string $username
     *
     * @return int $feUserUid
     */
    public function getFeUserUidFromUsername($username)
    {
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
        $tableName = 'fe_users';
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $statement = $queryBuilder
            ->select('uid')
            ->from($tableName)
            ->where(
                $queryBuilder->expr()->eq('username', $queryBuilder->createNamedParameter($username))
            )
            ->execute();
        $statement->execute();

        $userRec = $statement->fetch(\PDO::FETCH_ASSOC);
590 591 592
        if ($userRec['uid']) {
            return $userRec['uid'];
        }
593 594

        return false;
595 596 597 598 599 600 601 602 603 604
    }

    /**
     * Returns an array with minimum and maximum version number from range
     *
     * @param string $version Range of versions
     * @return array Minumum and maximum version number
     */
    protected function getVersionByRange($version)
    {
605 606 607
        $version = GeneralUtility::trimExplode('-', $version);
        $minimum = (!empty($version[0]) ? VersionNumberUtility::convertVersionNumberToInteger($version[0]) : 0);
        $maximum = (!empty($version[1]) ? VersionNumberUtility::convertVersionNumberToInteger($version[1]) : 0);
608

609
        return [$minimum, $maximum];
610 611
    }

612 613 614 615 616
    /**
     * Check which version is higher, so that we can se the right version in latest_version
     *
     * @param $versionUid
     * @param $extUid
617
     * @return int
618
     */
619
    private function calculatedHighestVersion($versionUid, $extUid): int
620 621 622 623 624 625 626 627
    {
        $currentHighestVersion = $this->getHighestVersion($extUid);
        if (empty($currentHighestVersion)) {
            return $versionUid;
        }

        $newVersionNumber = $this->getVersionNumber($versionUid);

628
        if ($newVersionNumber < $currentHighestVersion['version_number']) {
629 630 631 632 633 634 635 636 637 638 639 640 641
            $versionUid = $currentHighestVersion['uid'];
        }
        return $versionUid;
    }

    /**
     * Get the version number of the current version
     *
     * @param $versionUid
     * @return int
     */
    private function getVersionNumber($versionUid)
    {
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
        $tableName = 'tx_terfe2_domain_model_version';
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $statement = $queryBuilder
            ->select('version_number')
            ->from($tableName)
            ->where(
                $queryBuilder->expr()->eq('deleted', 0),
                $queryBuilder->expr()->eq('uid', $versionUid)
            )
            ->execute();
        $statement->execute();

        $res = $statement->fetch(\PDO::FETCH_ASSOC);
658 659 660 661 662 663 664 665 666 667 668 669 670

        if ($res['version_number']) {
            return $res['version_number'];
        }

        return 0;
    }

    /**
     * Gets the highest version number
     *
     * @param $extUid
     *
671
     * @return array|false|null
672
     */
673 674
    private function getHighestVersion($extUid)
    {
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
        $tableName = 'tx_terfe2_domain_model_version';
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getQueryBuilderForTable($tableName);
        $queryBuilder->getRestrictions()->removeAll();

        $statement = $queryBuilder
            ->select('uid', 'version_number')
            ->from($tableName)
            ->where(
                $queryBuilder->expr()->eq('deleted', 0),
                $queryBuilder->expr()->eq('extension', $extUid)
            )
            ->orderBy('version_number', 'DESC')
            ->execute();
        $statement->execute();

        $res = $statement->fetch(\PDO::FETCH_ASSOC);
692 693 694 695 696 697
        if (!empty($res)) {
            return $res;
        }

        return [];
    }
698
}