| 1 | <?php |
| 2 | |
| 3 | namespace wcf\acp\page; |
| 4 | |
| 5 | use wcf\data\package\installation\queue\PackageInstallationQueue; |
| 6 | use wcf\page\AbstractPage; |
| 7 | use wcf\system\exception\IllegalLinkException; |
| 8 | use wcf\system\package\PackageInstallationDispatcher; |
| 9 | use wcf\system\package\validation\PackageValidationManager; |
| 10 | use wcf\system\WCF; |
| 11 | |
| 12 | /** |
| 13 | * Shows a confirmation page prior to start installing. |
| 14 | * |
| 15 | * @author Alexander Ebert |
| 16 | * @copyright 2001-2019 WoltLab GmbH |
| 17 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
| 18 | */ |
| 19 | class PackageInstallationConfirmPage extends AbstractPage |
| 20 | { |
| 21 | /** |
| 22 | * @inheritDoc |
| 23 | */ |
| 24 | public $activeMenuItem = 'wcf.acp.menu.link.package.install'; |
| 25 | |
| 26 | /** |
| 27 | * package installation dispatcher object |
| 28 | * @var PackageInstallationDispatcher |
| 29 | */ |
| 30 | public $packageInstallationDispatcher; |
| 31 | |
| 32 | /** |
| 33 | * package installation queue object |
| 34 | * @var PackageInstallationQueue |
| 35 | */ |
| 36 | public $queue; |
| 37 | |
| 38 | /** |
| 39 | * queue id |
| 40 | * @var int |
| 41 | */ |
| 42 | public $queueID = 0; |
| 43 | |
| 44 | /** |
| 45 | * package validation result |
| 46 | * @var bool |
| 47 | */ |
| 48 | public $validationPassed = false; |
| 49 | |
| 50 | /** |
| 51 | * true if the package to be installed was uploaded via the import style |
| 52 | * form |
| 53 | * @var bool |
| 54 | */ |
| 55 | public $installingImportedStyle = false; |
| 56 | |
| 57 | /** |
| 58 | * @inheritDoc |
| 59 | */ |
| 60 | public function readParameters() |
| 61 | { |
| 62 | parent::readParameters(); |
| 63 | |
| 64 | if (isset($_REQUEST['queueID'])) { |
| 65 | $this->queueID = \intval($_REQUEST['queueID']); |
| 66 | } |
| 67 | $this->queue = new PackageInstallationQueue($this->queueID); |
| 68 | if (!$this->queue->queueID || $this->queue->done) { |
| 69 | throw new IllegalLinkException(); |
| 70 | } |
| 71 | |
| 72 | if ($this->queue->action == 'install') { |
| 73 | WCF::getSession()->checkPermissions(['admin.configuration.package.canInstallPackage']); |
| 74 | } else { |
| 75 | WCF::getSession()->checkPermissions(['admin.configuration.package.canUpdatePackage']); |
| 76 | } |
| 77 | |
| 78 | $this->installingImportedStyle = WCF::getSession()->getVar('stylePackageImportLocation') !== null; |
| 79 | if ($this->installingImportedStyle) { |
| 80 | WCF::getSession()->unregister('stylePackageImportLocation'); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @inheritDoc |
| 86 | */ |
| 87 | public function readData() |
| 88 | { |
| 89 | parent::readData(); |
| 90 | |
| 91 | $this->packageInstallationDispatcher = new PackageInstallationDispatcher($this->queue); |
| 92 | |
| 93 | // validate the package and all its requirements |
| 94 | $this->validationPassed = PackageValidationManager::getInstance()->validate($this->queue->archive, true); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @inheritDoc |
| 99 | */ |
| 100 | public function assignVariables() |
| 101 | { |
| 102 | parent::assignVariables(); |
| 103 | |
| 104 | WCF::getTPL()->assign([ |
| 105 | 'archive' => $this->packageInstallationDispatcher->getArchive(), |
| 106 | 'packageValidationArchives' => PackageValidationManager::getInstance()->getPackageValidationArchiveList(), |
| 107 | 'queue' => $this->queue, |
| 108 | 'validationPassed' => $this->validationPassed, |
| 109 | 'installingImportedStyle' => $this->installingImportedStyle, |
| 110 | ]); |
| 111 | } |
| 112 | } |