baseline
[omp.pkp.sfu.ca.git] / classes / install / form / UpgradeForm.inc.php
blob2461cc027d659fc1fca4b33082579dfed922e17e
1 <?php
3 /**
4 * @file classes/install/form/UpgradeForm.inc.php
6 * Copyright (c) 2003-2008 John Willinsky
7 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
9 * @class UpgradeForm
10 * @ingroup install_form
12 * @brief Form for system upgrades.
15 // $Id: UpgradeForm.inc.php,v 1.4 2009/09/22 19:22:09 asmecher Exp $
18 import('install.Upgrade');
19 import('form.Form');
21 class UpgradeForm extends Form {
23 /**
24 * Constructor.
26 function UpgradeForm() {
27 parent::Form('install/upgrade.tpl');
28 $this->addCheck(new FormValidatorPost($this));
31 /**
32 * Display the form.
34 function display() {
35 $templateMgr =& TemplateManager::getManager();
36 $templateMgr->assign_by_ref('version', VersionCheck::getCurrentCodeVersion());
38 parent::display();
41 /**
42 * Perform installation.
44 function execute() {
45 $templateMgr =& TemplateManager::getManager();
46 $installer = new Upgrade($this->_data);
48 // FIXME Use logger?
50 // FIXME Mostly common with InstallForm
52 if ($installer->execute()) {
53 if (!$installer->wroteConfig()) {
54 // Display config file contents for manual replacement
55 $templateMgr->assign(array('writeConfigFailed' => true, 'configFileContents' => $installer->getConfigContents()));
58 $templateMgr->assign('notes', $installer->getNotes());
59 $templateMgr->assign_by_ref('newVersion', $installer->getNewVersion());
60 $templateMgr->display('install/upgradeComplete.tpl');
62 } else {
63 switch ($installer->getErrorType()) {
64 case INSTALLER_ERROR_DB:
65 $this->dbInstallError($installer->getErrorMsg());
66 break;
67 default:
68 $this->installError($installer->getErrorMsg());
69 break;
73 $installer->destroy();
76 // FIXME Common with InstallForm
78 /**
79 * Fail with a generic installation error.
80 * @param $errorMsg string
82 function installError($errorMsg) {
83 $templateMgr =& TemplateManager::getManager();
84 $templateMgr->assign(array('isInstallError' => true, 'errorMsg' => $errorMsg));
85 $this->display();
88 /**
89 * Fail with a database installation error.
90 * @param $errorMsg string
92 function dbInstallError($errorMsg) {
93 $templateMgr =& TemplateManager::getManager();
94 $templateMgr->assign(array('isInstallError' => true, 'dbErrorMsg' => empty($errorMsg) ? Locale::translate('common.error.databaseErrorUnknown') : $errorMsg));
95 $this->display();