/** * 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())); }