import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Install_CompleteController extends Monkeys_Controller_Action
|
||||
class Install_CompleteController extends CommunityID_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Install_CredentialsController extends Monkeys_Controller_Action
|
||||
class Install_CredentialsController extends CommunityID_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
@ -24,13 +24,13 @@ class Install_CredentialsController extends Monkeys_Controller_Action
|
||||
$this->view->form = $appSession->installForm;
|
||||
unset($appSession->installForm);
|
||||
} else {
|
||||
$this->view->form = new InstallForm();
|
||||
$this->view->form = new Install_Form_Install();
|
||||
}
|
||||
}
|
||||
|
||||
public function saveAction()
|
||||
{
|
||||
$form = new InstallForm();
|
||||
$form = new Install_Form_Install();
|
||||
$formData = $this->_request->getPost();
|
||||
|
||||
$form->populate($formData);
|
||||
@ -53,13 +53,13 @@ class Install_CredentialsController extends Monkeys_Controller_Action
|
||||
$this->_importDb();
|
||||
|
||||
if (!$this->_writeConfig($form)) {
|
||||
throw new Exception('Couldn\'t write to config file file ' . APP_DIR . DIRECTORY_SEPARATOR . 'config.php');
|
||||
throw new Exception('Couldn\'t write to config file ' . APP_DIR . DIRECTORY_SEPARATOR . 'config.php');
|
||||
}
|
||||
|
||||
$this->_forward('index', 'complete');
|
||||
}
|
||||
|
||||
private function _connectToDbEngine(InstallForm $form)
|
||||
private function _connectToDbEngine(Install_Form_Install $form)
|
||||
{
|
||||
$this->_config->database->params->host = $form->getValue('hostname');
|
||||
$this->_config->database->params->username = $form->getValue('dbusername');
|
||||
@ -69,10 +69,10 @@ class Install_CredentialsController extends Monkeys_Controller_Action
|
||||
// without attempting to connect to the dbname
|
||||
$this->_config->database->params->dbname = null;
|
||||
|
||||
return Setup::setDatabase();
|
||||
return Application::setDatabase();
|
||||
}
|
||||
|
||||
private function _createDbIfMissing(InstallForm $form)
|
||||
private function _createDbIfMissing(Install_Form_Install $form)
|
||||
{
|
||||
$this->_config->database->params->host = $form->getValue('hostname');
|
||||
$this->_config->database->params->username = $form->getValue('dbusername');
|
||||
@ -80,15 +80,15 @@ class Install_CredentialsController extends Monkeys_Controller_Action
|
||||
|
||||
$this->_config->database->params->dbname = $form->getValue('dbname');
|
||||
|
||||
if (!Setup::setDatabase()) {
|
||||
if (!Application::setDatabase()) {
|
||||
try {
|
||||
$this->_config->database->params->dbname = null;
|
||||
Setup::setDatabase();
|
||||
Application::setDatabase();
|
||||
|
||||
// binding doesn't work here for some reason
|
||||
Zend_Registry::get('db')->getConnection()->query("CREATE DATABASE `" . $form->getValue('dbname') . "`");
|
||||
$this->_config->database->params->dbname = $form->getValue('dbname');
|
||||
Setup::setDatabase();
|
||||
Application::setDatabase();
|
||||
} catch (PDOException $e) { // when using PDO, it throws this exception, not Zend's
|
||||
return false;
|
||||
}
|
||||
@ -97,7 +97,7 @@ class Install_CredentialsController extends Monkeys_Controller_Action
|
||||
return true;
|
||||
}
|
||||
|
||||
private function _writeConfig(InstallForm $form)
|
||||
private function _writeConfig(Install_Form_Install $form)
|
||||
{
|
||||
$this->_config->environment->installed = true;
|
||||
$this->_config->email->supportemail = $form->getValue('supportemail');
|
||||
@ -113,8 +113,6 @@ class Install_CredentialsController extends Monkeys_Controller_Action
|
||||
'{environment.registrations_enabled}' => $this->_config->environment->registrations_enabled? 'true' : 'false',
|
||||
'{environment.locale}' => $this->_config->environment->locale,
|
||||
'{environment.template}' => $this->_config->environment->template,
|
||||
'{news_feed.url}' => $this->_config->news_feed->url,
|
||||
'{news_feed.num_items}' => $this->_config->news_feed->num_items,
|
||||
'{logging.location}' => $this->_config->logging->location,
|
||||
'{logging.level}' => $this->_config->logging->level,
|
||||
'{subdomain.enabled}' => $this->_config->subdomain->enabled? 'true' : 'false',
|
||||
@ -168,7 +166,7 @@ class Install_CredentialsController extends Monkeys_Controller_Action
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
private function _forwardFormError(InstallForm $form)
|
||||
private function _forwardFormError(Install_Form_Install $form)
|
||||
{
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
$appSession->installForm = $form;
|
||||
@ -181,7 +179,7 @@ class Install_CredentialsController extends Monkeys_Controller_Action
|
||||
$errors = array();
|
||||
$webServerUser = $this->_getProcessUser();
|
||||
|
||||
if (!is_writable(APP_DIR) && !is_writable(APP_DIR . '/config.php')) {
|
||||
if (!is_writable(APP_DIR) && !is_writable(APP_DIR . DIRECTORY_SEPARATOR . 'config.php')) {
|
||||
$errors[] = $this->view->translate('The directory where Community-ID is installed must be writable by the web server user (%s). Another option is to create an EMPTY config.php file that is writable by that user.', $webServerUser);
|
||||
}
|
||||
if (!is_writable(WEB_DIR . '/captchas')) {
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Install_IndexController extends Monkeys_Controller_Action
|
||||
class Install_IndexController extends CommunityID_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Install_PermissionsController extends Monkeys_Controller_Action
|
||||
class Install_PermissionsController extends CommunityID_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
|
125
modules/install/controllers/UpgradeController.php
Normal file
125
modules/install/controllers/UpgradeController.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Install_UpgradeController extends CommunityID_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
// double check upgrade is necessary in case someone access this action directly
|
||||
if (!$this->_needsUpgrade()) {
|
||||
$this->_redirect('');
|
||||
return;
|
||||
}
|
||||
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
if (isset($appSession->loginForm)) {
|
||||
$this->view->loginForm = $appSession->loginForm;
|
||||
unset($appSession->loginForm);
|
||||
} else {
|
||||
$this->view->loginForm = new Install_Form_UpgradeLogin();
|
||||
}
|
||||
}
|
||||
|
||||
public function proceedAction()
|
||||
{
|
||||
// double check upgrade is necessary in case someone access this action directly
|
||||
if (!$this->_needsUpgrade()) {
|
||||
$this->_redirect('');
|
||||
return;
|
||||
}
|
||||
|
||||
$form = new Install_Form_UpgradeLogin();
|
||||
$formData = $this->_request->getPost();
|
||||
$form->populate($formData);
|
||||
|
||||
if (!$form->isValid($formData)) {
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
$appSession->loginForm = $form;
|
||||
$this->_forward('index');
|
||||
return;
|
||||
}
|
||||
|
||||
$users = new Users_Model_Users();
|
||||
$result = $users->authenticate($this->_request->getPost('username'),
|
||||
$this->_request->getPost('password'));
|
||||
|
||||
if (!$result) {
|
||||
$this->_helper->FlashMessenger->addMessage($this->view->translate('Invalid credentials'));
|
||||
$this->_redirect('index');
|
||||
return;
|
||||
}
|
||||
|
||||
$user = $users->getUser();
|
||||
if ($user->role != Users_Model_User::ROLE_ADMIN) {
|
||||
Zend_Auth::getInstance()->clearIdentity();
|
||||
$this->_helper->FlashMessenger->addMessage($this->view->translate('Invalid credentials'));
|
||||
$this->_redirect('index');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_runUpgrades(true);
|
||||
$upgradedVersion = $this->_runUpgrades(false);
|
||||
|
||||
$this->_helper->FlashMessenger->addMessage($this->view->translate('Upgrade was successful. You are now on version %s', $upgradedVersion));
|
||||
$this->_redirect('/');
|
||||
}
|
||||
|
||||
private function _runUpgrades($onlyCheckFiles = true)
|
||||
{
|
||||
require 'setup/versions.php';
|
||||
|
||||
$includeFiles = false;
|
||||
$db = Zend_Registry::get('db');
|
||||
foreach ($versions as $version) {
|
||||
if ($version == $this->_getDbVersion()) {
|
||||
$includeFiles = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$includeFiles) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fileName = APP_DIR . '/setup/upgrade_'.$version.'.sql';
|
||||
|
||||
if ($onlyCheckFiles) {
|
||||
if (!file_exists($fileName)) {
|
||||
$this->_helper->FlashMessenger->addMessage($this->view->translate('Correct before upgrading: File %s is required to proceed', $fileName));
|
||||
$this->_redirect('index');
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$query = '';
|
||||
$lines = file($fileName);
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line != '') {
|
||||
$query .= $line;
|
||||
}
|
||||
if (substr($line, -1) == ';') {
|
||||
try {
|
||||
$db->query($query);
|
||||
} catch (Zend_Db_Statement_Mysqli_Exception $e) {
|
||||
Zend_Registry::get('logger')->log("Error in this query: $query", Zend_Log::ERR);
|
||||
throw $e;
|
||||
}
|
||||
$query = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user