ReviewController.php 2.73 KB
Newer Older
1
<?php
2 3
namespace T3o\TerFe2\Controller;

4 5
/*
 * This file is part of the TYPO3 CMS project.
6
 *
7 8 9
 * 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.
10
 *
11 12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14 15
 * The TYPO3 project - inspiring people to share!
 */
16

17 18 19
/**
 * Controller for the extension review
 */
20
class ReviewController extends \T3o\TerFe2\Controller\AbstractTerBasedController
21
{
22

23 24 25
    /**
     * Set unsecure flag of all given versions
     *
26
     * @param \T3o\TerFe2\Domain\Model\Extension $extension The extension to update
Thomas Löffler's avatar
Thomas Löffler committed
27
     * @param array $insecureVersions Version UIDs or empty string of no version was selected
28
     */
Thomas Löffler's avatar
Thomas Löffler committed
29
    public function updateAction(\T3o\TerFe2\Domain\Model\Extension $extension, array $insecureVersions)
30
    {
Thomas Löffler's avatar
Thomas Löffler committed
31
        $actionParameters = ['extension' => $extension];
32
        $versions = $extension->getVersions();
Thomas Löffler's avatar
Thomas Löffler committed
33 34
        $versionChanged = false;
        $versionRepository = $this->objectManager->get(\T3o\TerFe2\Domain\Repository\VersionRepository::class);
35
        $extensionRepository = $this->objectManager->get(\T3o\TerFe2\Domain\Repository\ExtensionRepository::class);
36

37
        foreach ($versions as $version) {
Thomas Löffler's avatar
Thomas Löffler committed
38
            /** @var \T3o\TerFe2\Domain\Model\Version $version */
39
            $reviewState = 0;
40
            if (in_array($version->getUid(), $insecureVersions)) {
41 42
                $reviewState = -1;
            }
43

44 45 46
            if ($reviewState === $version->getReviewState()) {
                continue;
            }
47

48
            $error = '';
Thomas Löffler's avatar
Thomas Löffler committed
49
            if ($this->terConnection->setReviewState($extension->getExtKey(), $version->getVersionString(), $reviewState, $error)) {
50
                $version->setReviewState($reviewState);
Thomas Löffler's avatar
Thomas Löffler committed
51 52
                $versionChanged = true;
                $versionRepository->update($version);
53
                $extensionRepository->update($extension);
54
            } else {
Thomas Löffler's avatar
Thomas Löffler committed
55
                $message = $this->translate('msg.reviewstate_not_enabled', [$version->getVersionString(), $error]);
Markus Sommer's avatar
Markus Sommer committed
56
                $this->redirectWithMessage($message, 'show', '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, 'Extension', null, $actionParameters);
57 58
            }
        }
59

Thomas Löffler's avatar
Thomas Löffler committed
60
        if ($versionChanged) {
Markus Sommer's avatar
Markus Sommer committed
61
            $this->redirectWithMessage($this->translate('msg.reviewstate_enabled'), 'show', '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, 'Extension', null, $actionParameters);
62 63 64
        }

        $message = $this->translate('msg.reviewstate_not_changed');
Markus Sommer's avatar
Markus Sommer committed
65
        $this->redirectWithMessage($message, 'show', '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, 'Extension', null, $actionParameters);
66 67
    }
}