$includes = glob(PSM_PATH_INC . '*.inc.php'); foreach ($includes as $file) { include_once $file; } // init db connection $db = new psm\Service\Database(); // sanity check! if (!defined('PSM_INSTALL') || !PSM_INSTALL) { if ($db->getDbHost() === null) { // no config file has been loaded, redirect the user to the install header('Location: install.php'); die; } // config file has been loaded, check if we have a connection if (!$db->status()) { die('Unable to establish database connection...'); } // attempt to load configuration from database if (!psm_load_conf()) { // unable to load from config table header('Location: install.php'); die; } // config load OK, make sure database version is up to date $installer = new \psm\Util\Install\Installer($db); if ($installer->isUpgradeRequired()) { die('Your database is for an older version and requires an upgrade, <a href="install.php">please click here</a> to update your database to the latest version.'); } } $lang = psm_get_conf('language', 'en_US'); psm_load_lang($lang);
/** * Execute the install and upgrade process to a newer version */ protected function executeInstall() { if (!defined('PSM_DB_PREFIX') || !$this->db->status()) { return $this->executeConfig(); } $add_user = false; // check if user submitted username + password in previous step // this would only be the case for new installs, and install from // before 3.0 $new_user = array('user_name' => psm_POST('username'), 'name' => psm_POST('username'), 'password' => psm_POST('password'), 'password_repeat' => psm_POST('password_repeat'), 'email' => psm_POST('email', ''), 'mobile' => '', 'level' => PSM_USER_ADMIN, 'pushover_key' => '', 'pushover_device' => ''); $validator = new \psm\Util\User\UserValidator($this->user); $logger = array($this, 'addMessage'); $installer = new \psm\Util\Install\Installer($this->db, $logger); if ($this->isUpgrade()) { $this->addMessage('Upgrade process started.', 'info'); $version_from = $this->getPreviousVersion(); if ($version_from === false) { $this->addMessage('Unable to locate your previous version. Please run a fresh install.', 'error'); } else { if (version_compare($version_from, PSM_VERSION, '=')) { $this->addMessage('Your installation is already at the latest version.', 'success'); } elseif (version_compare($version_from, PSM_VERSION, '>')) { $this->addMessage('This installer does not support downgrading, sorry.', 'error'); } else { $this->addMessage('Upgrading from ' . $version_from . ' to ' . PSM_VERSION, 'info'); $installer->upgrade($version_from, PSM_VERSION); } if (version_compare($version_from, '3.0.0', '<')) { $add_user = true; } } } else { // validate the lot try { $validator->email($new_user['email']); $validator->password($new_user['password'], $new_user['password_repeat']); } catch (\InvalidArgumentException $e) { $this->addMessage(psm_get_lang('users', 'error_' . $e->getMessage()), 'error'); return $this->executeConfig(); } $this->addMessage('Installation process started.', 'success'); $installer->install(); // add user $add_user = true; } if ($add_user) { unset($new_user['password_repeat']); $user_id = $this->db->save(PSM_DB_PREFIX . 'users', $new_user); if (intval($user_id) > 0) { $this->user->changePassword($user_id, $new_user['password']); $this->addMessage('User account has been created successfully.', 'success'); } else { $this->addMessage('There was an error adding your user account.', 'error'); } } return $this->twig->render('module/install/success.tpl.html', array('messages' => $this->getMessages())); }