first commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/install/DowngradeNotSupportedException.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @brief Exception indicating an unsupported downgrade.
|
||||
*/
|
||||
|
||||
namespace PKP\install;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
class DowngradeNotSupportedException extends Exception
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(string $message = 'Downgrade not supported', int $code = 0, ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,274 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @defgroup install Install
|
||||
* Implements a software installer, including a flexible upgrader that can
|
||||
* manage schema changes, data representation changes, etc.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file classes/install/PKPInstall.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class PKPInstall
|
||||
*
|
||||
* @ingroup install
|
||||
*
|
||||
* @see Installer, InstallForm
|
||||
*
|
||||
* @brief Perform system installation.
|
||||
*
|
||||
* This script will:
|
||||
* - Create the database (optionally), and install the database tables and initial data.
|
||||
* - Update the config file with installation parameters.
|
||||
*/
|
||||
|
||||
namespace PKP\install;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\core\Services;
|
||||
use APP\facades\Repo;
|
||||
use Illuminate\Support\Facades\Config as FacadesConfig;
|
||||
use PKP\config\Config;
|
||||
use PKP\core\Core;
|
||||
use PKP\core\PKPString;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\facades\Locale;
|
||||
use PKP\file\FileManager;
|
||||
use PKP\security\Role;
|
||||
use PKP\security\Validation;
|
||||
use PKP\services\PKPSchemaService;
|
||||
use PKP\site\SiteDAO;
|
||||
use PKP\site\Version;
|
||||
|
||||
class PKPInstall extends Installer
|
||||
{
|
||||
/** @var int Minimum password length */
|
||||
public const MIN_PASSWORD_LENGTH = 6;
|
||||
|
||||
/**
|
||||
* Returns true iff this is an upgrade process.
|
||||
*/
|
||||
public function isUpgrade()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-installation.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function preInstall()
|
||||
{
|
||||
if (!isset($this->currentVersion)) {
|
||||
$this->currentVersion = Version::fromString('');
|
||||
}
|
||||
|
||||
$this->locale = $this->getParam('locale');
|
||||
$this->installedLocales = $this->getParam('additionalLocales');
|
||||
if (!isset($this->installedLocales) || !is_array($this->installedLocales)) {
|
||||
$this->installedLocales = [];
|
||||
}
|
||||
if (!in_array($this->locale, $this->installedLocales) && Locale::isLocaleValid($this->locale)) {
|
||||
array_push($this->installedLocales, $this->locale);
|
||||
}
|
||||
|
||||
// Map valid config options to Illuminate database drivers
|
||||
$driver = strtolower($this->getParam('databaseDriver'));
|
||||
if (substr($driver, 0, 8) === 'postgres') {
|
||||
$driver = 'pgsql';
|
||||
} else {
|
||||
$driver = 'mysql';
|
||||
}
|
||||
|
||||
$config = FacadesConfig::get('database');
|
||||
$config['default'] = $driver;
|
||||
$config['connections'][$driver] = [
|
||||
'driver' => $driver,
|
||||
'host' => $this->getParam('databaseHost'),
|
||||
'port' => $this->getParam('databasePort'),
|
||||
'unix_socket' => $this->getParam('unixSocket'),
|
||||
'database' => $this->getParam('databaseName'),
|
||||
'username' => $this->getParam('databaseUsername'),
|
||||
'password' => $this->getParam('databasePassword'),
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_general_ci',
|
||||
];
|
||||
FacadesConfig::set('database', $config);
|
||||
|
||||
return parent::preInstall();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Installer actions
|
||||
//
|
||||
|
||||
/**
|
||||
* Get the names of the directories to create.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCreateDirectories()
|
||||
{
|
||||
return ['site'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create required files directories
|
||||
* FIXME No longer needed since FileManager will auto-create?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function createDirectories()
|
||||
{
|
||||
// Check if files directory exists and is writeable
|
||||
if (!(file_exists($this->getParam('filesDir')) && is_writeable($this->getParam('filesDir')))) {
|
||||
// Files upload directory unusable
|
||||
$this->setError(Installer::INSTALLER_ERROR_GENERAL, 'installer.installFilesDirError');
|
||||
return false;
|
||||
} else {
|
||||
// Create required subdirectories
|
||||
$dirsToCreate = $this->getCreateDirectories();
|
||||
$dirsToCreate[] = 'usageStats';
|
||||
$fileManager = new FileManager();
|
||||
foreach ($dirsToCreate as $dirName) {
|
||||
$dirToCreate = $this->getParam('filesDir') . '/' . $dirName;
|
||||
if (!file_exists($dirToCreate)) {
|
||||
if (!$fileManager->mkdir($dirToCreate)) {
|
||||
$this->setError(Installer::INSTALLER_ERROR_GENERAL, 'installer.installFilesDirError');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if public files directory exists and is writeable
|
||||
$publicFilesDir = Config::getVar('files', 'public_files_dir');
|
||||
if (!(file_exists($publicFilesDir) && is_writeable($publicFilesDir))) {
|
||||
// Public files upload directory unusable
|
||||
$this->setError(Installer::INSTALLER_ERROR_GENERAL, 'installer.publicFilesDirError');
|
||||
return false;
|
||||
} else {
|
||||
// Create required subdirectories
|
||||
$dirsToCreate = $this->getCreateDirectories();
|
||||
$fileManager = new FileManager();
|
||||
foreach ($dirsToCreate as $dirName) {
|
||||
$dirToCreate = $publicFilesDir . '/' . $dirName;
|
||||
if (!file_exists($dirToCreate)) {
|
||||
if (!$fileManager->mkdir($dirToCreate)) {
|
||||
$this->setError(Installer::INSTALLER_ERROR_GENERAL, 'installer.publicFilesDirError');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the configuration file.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function createConfig()
|
||||
{
|
||||
$request = Application::get()->getRequest();
|
||||
return $this->updateConfig(
|
||||
[
|
||||
'general' => [
|
||||
'installed' => 'On',
|
||||
'base_url' => $request->getBaseUrl(),
|
||||
'enable_beacon' => $this->getParam('enableBeacon') ? 'On' : 'Off',
|
||||
'allowed_hosts' => json_encode([$request->getServerHost(null, false)]),
|
||||
'time_zone' => $this->getParam('timeZone')
|
||||
],
|
||||
'database' => [
|
||||
'driver' => $this->getParam('databaseDriver'),
|
||||
'host' => $this->getParam('databaseHost'),
|
||||
'username' => $this->getParam('databaseUsername'),
|
||||
'password' => $this->getParam('databasePassword'),
|
||||
'name' => $this->getParam('databaseName')
|
||||
],
|
||||
'i18n' => [
|
||||
'locale' => $this->getParam('locale'),
|
||||
'connection_charset' => 'utf8',
|
||||
],
|
||||
'files' => [
|
||||
'files_dir' => $this->getParam('filesDir')
|
||||
],
|
||||
'oai' => [
|
||||
'repository_id' => $this->getParam('oaiRepositoryId')
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create initial required data.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function createData()
|
||||
{
|
||||
$siteLocale = $this->getParam('locale');
|
||||
|
||||
// Add initial site administrator user
|
||||
$user = Repo::user()->newDataObject();
|
||||
$user->setUsername($this->getParam('adminUsername'));
|
||||
$user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
|
||||
$user->setGivenName($user->getUsername(), $siteLocale);
|
||||
$user->setFamilyName($user->getUsername(), $siteLocale);
|
||||
$user->setEmail($this->getParam('adminEmail'));
|
||||
$user->setDateRegistered(Core::getCurrentDate());
|
||||
$user->setInlineHelp(1);
|
||||
Repo::user()->add($user);
|
||||
|
||||
// Create an admin user group
|
||||
$adminUserGroup = Repo::userGroup()->newDataObject();
|
||||
$adminUserGroup->setRoleId(Role::ROLE_ID_SITE_ADMIN);
|
||||
$adminUserGroup->setContextId(\PKP\core\PKPApplication::CONTEXT_ID_NONE);
|
||||
$adminUserGroup->setDefault(true);
|
||||
foreach ($this->installedLocales as $locale) {
|
||||
$name = __('default.groups.name.siteAdmin', [], $locale);
|
||||
$namePlural = __('default.groups.plural.siteAdmin', [], $locale);
|
||||
$adminUserGroup->setData('name', $name, $locale);
|
||||
$adminUserGroup->setData('namePlural', $namePlural, $locale);
|
||||
}
|
||||
Repo::userGroup()->add($adminUserGroup);
|
||||
|
||||
// Put the installer into this user group
|
||||
Repo::userGroup()->assignUserToGroup($user->getId(), $adminUserGroup->getId());
|
||||
|
||||
// Add initial site data
|
||||
/** @var SiteDAO */
|
||||
$siteDao = DAORegistry::getDAO('SiteDAO');
|
||||
$site = $siteDao->newDataObject();
|
||||
$site->setRedirect(0);
|
||||
$site->setMinPasswordLength(static::MIN_PASSWORD_LENGTH);
|
||||
$site->setPrimaryLocale($siteLocale);
|
||||
$site->setInstalledLocales($this->installedLocales);
|
||||
$site->setSupportedLocales($this->installedLocales);
|
||||
$site->setUniqueSiteID(PKPString::generateUUID());
|
||||
$siteDao->insertSite($site);
|
||||
|
||||
Repo::emailTemplate()->dao->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), $this->installedLocales);
|
||||
|
||||
// Install default site settings
|
||||
$schemaService = Services::get('schema');
|
||||
$site = $schemaService->setDefaults(PKPSchemaService::SCHEMA_SITE, $site, $site->getSupportedLocales(), $site->getPrimaryLocale());
|
||||
$site->setData('contactEmail', $this->getParam('adminEmail'), $site->getPrimaryLocale());
|
||||
$siteDao->updateObject($site);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\install\PKPInstall', '\PKPInstall');
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/install/form/InstallForm.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class InstallForm
|
||||
*
|
||||
* @ingroup install
|
||||
*
|
||||
* @see Install
|
||||
*
|
||||
* @brief Form for system installation.
|
||||
*/
|
||||
|
||||
namespace PKP\install\form;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\install\Install;
|
||||
use APP\template\TemplateManager;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use PKP\core\Core;
|
||||
use PKP\core\PKPApplication;
|
||||
use PKP\core\PKPString;
|
||||
use PKP\facades\Locale;
|
||||
use PKP\i18n\LocaleMetadata;
|
||||
use PKP\install\Installer;
|
||||
use PKP\xslt\XSLTransformer;
|
||||
|
||||
class InstallForm extends MaintenanceForm
|
||||
{
|
||||
/** @var array locales supported by this system */
|
||||
public $supportedLocales;
|
||||
|
||||
/** @var array locale completeness booleans */
|
||||
public $localesComplete;
|
||||
|
||||
/** @var array database drivers supported by this system */
|
||||
public $supportedDatabaseDrivers = [
|
||||
// <driver> => array(<php-module>, <name>)
|
||||
'mysqli' => ['mysqli', 'MySQLi'],
|
||||
'postgres9' => ['pgsql', 'PostgreSQL'],
|
||||
'mysql' => ['mysql', 'MySQL']
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ?\PKP\core\PKPRequest $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
parent::__construct($request, 'install/install.tpl');
|
||||
|
||||
$allLocales = Locale::getLocales();
|
||||
$this->supportedLocales = Locale::getFormattedDisplayNames(null, $allLocales, LocaleMetadata::LANGUAGE_LOCALE_WITHOUT, false);
|
||||
$this->localesComplete = array_map(fn (LocaleMetadata $locale) => $locale->isComplete(), $allLocales);
|
||||
|
||||
foreach ($this->supportedDatabaseDrivers as $driver => [$module]) {
|
||||
if (!extension_loaded($module)) {
|
||||
unset($this->supportedDatabaseDrivers[$driver]);
|
||||
}
|
||||
}
|
||||
|
||||
// Validation checks for this form
|
||||
$form = $this;
|
||||
$this->addCheck(new \PKP\form\validation\FormValidatorInSet($this, 'locale', 'required', 'installer.form.localeRequired', array_keys($this->supportedLocales)));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'locale', 'required', 'installer.form.localeRequired', fn (string $locale) => Locale::isLocaleValid($locale)));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'filesDir', 'required', 'installer.form.filesDirRequired'));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'adminUsername', 'required', 'installer.form.usernameRequired'));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidatorUsername($this, 'adminUsername', 'required', 'installer.form.usernameAlphaNumeric'));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'adminPassword', 'required', 'installer.form.passwordRequired'));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidatorCustom($this, 'adminPassword', 'required', 'installer.form.passwordsDoNotMatch', fn (string $password) => $password == $form->getData('adminPassword2')));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidatorEmail($this, 'adminEmail', 'required', 'installer.form.emailRequired'));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidatorInSet($this, 'databaseDriver', 'required', 'installer.form.databaseDriverRequired', array_keys($this->supportedDatabaseDrivers)));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'databaseName', 'required', 'installer.form.databaseNameRequired'));
|
||||
$this->addCheck(new \PKP\form\validation\FormValidatorInSet($this, 'timeZone', 'required', 'installer.form.timeZoneRequired', DateTimeZone::listIdentifiers()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc Form::display
|
||||
*
|
||||
* @param null|mixed $request
|
||||
* @param null|mixed $template
|
||||
*/
|
||||
public function display($request = null, $template = null)
|
||||
{
|
||||
$timeZones = array_reduce(DateTimeZone::listIdentifiers(), function ($timeZones, $current) {
|
||||
if ($current !== 'UTC') {
|
||||
$time = (new DateTime('now', new DateTimeZone($current)))->format('P');
|
||||
$groups = explode('/', $current);
|
||||
$continent = array_shift($groups);
|
||||
$timeZone = str_replace('_', ' ', implode(' - ', $groups));
|
||||
$timeZones[$continent ?? $timeZone][$current] = $timeZone . " ({$time})";
|
||||
}
|
||||
return $timeZones;
|
||||
}, ['UTC' => 'UTC']);
|
||||
|
||||
$templateMgr = TemplateManager::getManager($request);
|
||||
$languages = array_map(fn (LocaleMetadata $locale) => $locale->getDisplayName($locale->locale, true), Locale::getLocales());
|
||||
asort($languages);
|
||||
$templateMgr->assign([
|
||||
'timeZoneOptions' => $timeZones,
|
||||
'languageOptions' => $languages,
|
||||
'localeOptions' => $this->supportedLocales,
|
||||
'localesComplete' => $this->localesComplete,
|
||||
'allowFileUploads' => ini_get('file_uploads') ? __('common.yes') : __('common.no'),
|
||||
'maxFileUploadSize' => ini_get('upload_max_filesize'),
|
||||
'databaseDriverOptions' => $this->getDatabaseDriversOptions(),
|
||||
'supportsMBString' => PKPString::hasMBString() ? __('common.yes') : __('common.no'),
|
||||
'phpIsSupportedVersion' => version_compare(PKPApplication::PHP_REQUIRED_VERSION, PHP_VERSION) != 1,
|
||||
'xslEnabled' => XSLTransformer::checkSupport(),
|
||||
'xslRequired' => Application::REQUIRES_XSL,
|
||||
'phpRequiredVersion' => PKPApplication::PHP_REQUIRED_VERSION,
|
||||
'phpVersion' => PHP_VERSION,
|
||||
]);
|
||||
|
||||
parent::display($request, $template);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc MaintenanceForm::initData
|
||||
*/
|
||||
public function initData()
|
||||
{
|
||||
$docRoot = dirname($_SERVER['DOCUMENT_ROOT']);
|
||||
if (Core::isWindows()) {
|
||||
// Replace backslashes with slashes for the default files directory.
|
||||
$docRoot = str_replace('\\', '/', $docRoot);
|
||||
}
|
||||
|
||||
// Add a trailing slash for paths that aren't filesystem root
|
||||
if ($docRoot !== '/') {
|
||||
$docRoot .= '/';
|
||||
}
|
||||
|
||||
$this->_data = [
|
||||
'timeZone' => 'UTC',
|
||||
'locale' => Locale::getLocale(),
|
||||
'additionalLocales' => [],
|
||||
'filesDir' => $docRoot . 'files',
|
||||
'databaseDriver' => 'mysqli',
|
||||
'databaseHost' => 'localhost',
|
||||
'databaseUsername' => Application::getName(),
|
||||
'databasePassword' => '',
|
||||
'databaseName' => Application::getName(),
|
||||
'oaiRepositoryId' => Application::getName() . '.' . $this->_request->getServerHost(),
|
||||
'enableBeacon' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign form data to user-submitted data.
|
||||
*/
|
||||
public function readInputData()
|
||||
{
|
||||
$this->readUserVars([
|
||||
'timeZone',
|
||||
'locale',
|
||||
'additionalLocales',
|
||||
'filesDir',
|
||||
'adminUsername',
|
||||
'adminPassword',
|
||||
'adminPassword2',
|
||||
'adminEmail',
|
||||
'databaseDriver',
|
||||
'databaseHost',
|
||||
'databaseUsername',
|
||||
'databasePassword',
|
||||
'databaseName',
|
||||
'oaiRepositoryId',
|
||||
'enableBeacon',
|
||||
]);
|
||||
|
||||
if ($this->getData('additionalLocales') == null || !is_array($this->getData('additionalLocales'))) {
|
||||
$this->setData('additionalLocales', []);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform installation.
|
||||
*
|
||||
* @param mixed[] ...$functionArgs Function arguments
|
||||
*/
|
||||
public function execute(...$functionArgs)
|
||||
{
|
||||
parent::execute(...$functionArgs);
|
||||
|
||||
$templateMgr = TemplateManager::getManager($this->_request);
|
||||
$installer = new Install($this->_data);
|
||||
|
||||
if ($installer->execute()) {
|
||||
if (!$installer->wroteConfig()) {
|
||||
// Display config file contents for manual replacement
|
||||
$templateMgr->assign(['writeConfigFailed' => true, 'configFileContents' => $installer->getConfigContents()]);
|
||||
}
|
||||
|
||||
$templateMgr->display('install/installComplete.tpl');
|
||||
} else {
|
||||
switch ($installer->getErrorType()) {
|
||||
case Installer::INSTALLER_ERROR_DB:
|
||||
$this->dbInstallError($installer->getErrorMsg());
|
||||
break;
|
||||
default:
|
||||
$this->installError($installer->getErrorMsg());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$installer->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the available databases
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDatabaseDriversOptions()
|
||||
{
|
||||
return array_map(fn ($item) => $item[1], $this->supportedDatabaseDrivers);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\install\form\InstallForm', '\InstallForm');
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/install/form/MaintenanceForm.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class MaintenanceForm
|
||||
*
|
||||
* @ingroup install_form
|
||||
*
|
||||
* @brief Base form for system maintenance (install/upgrade).
|
||||
*/
|
||||
|
||||
namespace PKP\install\form;
|
||||
|
||||
use APP\template\TemplateManager;
|
||||
use PKP\core\PKPRequest;
|
||||
use PKP\form\Form;
|
||||
use PKP\site\VersionCheck;
|
||||
|
||||
class MaintenanceForm extends Form
|
||||
{
|
||||
/** @var ?PKPRequest */
|
||||
public $_request;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param ?PKPRequest $request
|
||||
*/
|
||||
public function __construct($request, $template)
|
||||
{
|
||||
parent::__construct($template);
|
||||
$this->_request = $request;
|
||||
$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc Form::display
|
||||
*
|
||||
* @param ?PKPRequest $request
|
||||
* @param ?string $template
|
||||
*/
|
||||
public function display($request = null, $template = null)
|
||||
{
|
||||
$templateMgr = TemplateManager::getManager($this->_request);
|
||||
$templateMgr->assign('version', VersionCheck::getCurrentCodeVersion());
|
||||
parent::display($request, $template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail with a generic installation error.
|
||||
*
|
||||
* @param string $errorMsg
|
||||
* @param bool $translate
|
||||
*/
|
||||
public function installError($errorMsg, $translate = true)
|
||||
{
|
||||
$templateMgr = TemplateManager::getManager($this->_request);
|
||||
$templateMgr->assign(['isInstallError' => true, 'errorMsg' => $errorMsg, 'translateErrorMsg' => $translate]);
|
||||
$this->display($this->_request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail with a database installation error.
|
||||
*
|
||||
* @param string $errorMsg
|
||||
*/
|
||||
public function dbInstallError($errorMsg)
|
||||
{
|
||||
$templateMgr = TemplateManager::getManager($this->_request);
|
||||
$templateMgr->assign(['isInstallError' => true, 'dbErrorMsg' => empty($errorMsg) ? __('common.error.databaseErrorUnknown') : $errorMsg]);
|
||||
error_log($errorMsg);
|
||||
$this->display($this->_request);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\install\form\MaintenanceForm', '\MaintenanceForm');
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/install/form/UpgradeForm.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class UpgradeForm
|
||||
*
|
||||
* @ingroup install_form
|
||||
*
|
||||
* @brief Form for system upgrades.
|
||||
*/
|
||||
|
||||
namespace PKP\install\form;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\install\Upgrade;
|
||||
use APP\template\TemplateManager;
|
||||
use PKP\install\Installer;
|
||||
|
||||
class UpgradeForm extends MaintenanceForm
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
parent::__construct($request, 'install/upgrade.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform installation.
|
||||
*/
|
||||
public function execute(...$functionParams)
|
||||
{
|
||||
parent::execute(...$functionParams);
|
||||
|
||||
Application::upgrade();
|
||||
$templateMgr = TemplateManager::getManager($this->_request);
|
||||
$installer = new Upgrade($this->_data);
|
||||
|
||||
// FIXME Use logger?
|
||||
|
||||
// FIXME Mostly common with InstallForm
|
||||
|
||||
if ($installer->execute()) {
|
||||
if (!$installer->wroteConfig()) {
|
||||
// Display config file contents for manual replacement
|
||||
$templateMgr->assign(['writeConfigFailed' => true, 'configFileContents' => $installer->getConfigContents()]);
|
||||
}
|
||||
|
||||
$templateMgr->assign('notes', $installer->getNotes());
|
||||
$templateMgr->assign('newVersion', $installer->getNewVersion());
|
||||
$templateMgr->display('install/upgradeComplete.tpl');
|
||||
} else {
|
||||
switch ($installer->getErrorType()) {
|
||||
case Installer::INSTALLER_ERROR_DB:
|
||||
$this->dbInstallError($installer->getErrorMsg());
|
||||
break;
|
||||
default:
|
||||
$this->installError($installer->getErrorMsg());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$installer->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\install\form\UpgradeForm', '\UpgradeForm');
|
||||
}
|
||||
Reference in New Issue
Block a user