Configuration is now saved during installation, started the Notify module.
[pivip.git] / project / modules / install / Module.php
blobb2c6f8d3415d969a58990f0f168bb5e9db080385
1 <?php
3 /**
4 * Pivip
5 * Copyright (C) 2008 Vincent Tunru
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 * @license http://www.fsf.org/licensing/licenses/info/GPLv2.html GPL v.2
21 * @category PivipModulesDefault
22 * @package Module_Install
23 * @copyright (C) 2008 Vincent Tunru
24 * @author Vincent Tunru <email@vincentt.org>
27 /**
28 * Manage installation of Pivip
30 * @see /library/Pivip/Module/Abstract.php
32 class Install_Module extends Pivip_Module_Abstract
34 /**
35 * Checks whether Pivip is installed
37 * First checks whether the database password has been changed, then
38 * whether a connection with the database can be made.
40 * @return boolean Whether Pivip is already installed.
42 public static function isInstalled()
44 $generalConfig = Zend_Registry::get('generalConfig');
45 if(!isset($generalConfig->database->adapter) ||
46 !isset($generalConfig->database->params->dbname) ||
47 !isset($generalConfig->database->params->username) ||
48 !isset($generalConfig->database->params->password) ||
49 'username' == $generalConfig->database->params->username ||
50 'password' == $generalConfig->database->params->password)
52 return false;
54 try
56 $db = Zend_Db::factory($generalConfig->database);
57 } catch(Exception $e) {
58 return false;
60 Zend_Registry::set('db', $db);
61 return true;
64 /**
65 * Communicate that Pivip needs configuration
67 * Always returns true since Pivip needs to be told the database settings.
69 * @return boolean True, Pivip needs to be configured
71 public static function needsConfiguring()
73 return true;
76 /**
77 * Edit the configuration files, install modules.
79 * @throws Pivip_Install_Exception
80 * @return boolean Whether the installation succeeded
82 public function install()
86 /**
87 * Remove all Pivip-related tables from the database
89 * @throws Pivip_Install_Exception
90 * @return boolean Whether uninstallation succeeded
92 public function uninstall()
96 /**
97 * Commence installation when Pivip isn't installed yet
99 public static function bootstrap()
101 if(self::isInstalled())
103 return;
105 $nextRequest = new Zend_Controller_Request_Simple('index', 'install',
106 'install');
107 $frontController = Zend_Controller_Front::getInstance();
108 $actionStack = $frontController
109 ->getPlugin('Zend_Controller_Plugin_ActionStack');
110 if(!$actionStack)
112 $actionStack = new Zend_Controller_Plugin_ActionStack();
113 $frontController->registerPlugin($actionStack);
115 $actionStack->pushStack($nextRequest);
116 $route = new Zend_Controller_Router_Route('install/:phase/*',
117 array('module' => 'install',
118 'controller' => 'install',
119 'action' => 'index',
120 'phase' => 'index'));
121 $frontController->getRouter()->addRoute('install', $route);