Source for file Install.php
Documentation is available at Install.php
// include the config file
require_once '../util/AlphaConfig.inc';
require_once $config->get('sysRoot'). 'alpha/controller/AlphaController.inc';
require_once $config->get('sysRoot'). 'alpha/view/AlphaView.inc';
require_once $config->get('sysRoot'). 'alpha/controller/AlphaControllerInterface.inc';
* Controller used install the database
* @package alpha::controller
* @author John Collins <dev@alphaframework.org>
* @version $Id: Install.php 1341 2011-03-17 15:02:02Z johnc $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
* * Neither the name of the Alpha Framework nor the names
* of its contributors may be used to endorse or promote
* products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
private static $logger = null;
self::$logger = new Logger('Install');
self::$logger->debug('>>__construct()');
parent::__construct('Public');
// if there is nobody logged in, we will send them off to the Login controller to do so before coming back here
if(!isset ($_SESSION['currentUser'])) {
self::$logger->info('Nobody logged in, invoking Login controller...');
require_once $config->get('sysRoot'). 'alpha/controller/Login.php';
$controller = new Login();
$controller->setName('Login');
$controller->setUnitOfWork(array('Login', 'Install'));
$controller->doGET(array());
self::$logger->debug('<<__construct');
// ensure that the super class constructor is called, indicating the rights group
parent::__construct('Admin');
// set up the title and meta details
$this->setTitle('Installing '. $config->get('sysTitle'));
self::$logger->debug('<<__construct');
public function doGET($params) {
self::$logger->debug('>>doGET($params=['. var_export($params, true). '])');
$this->createAppDirectories();
// start a new database transaction
echo '<p>Attempting to create the DEnum tables...';
if(!$DEnum->checkTableExists())
self::$logger->info('Created the ['. $DEnum->getTableName(). '] table successfully');
if(!$DEnumItem->checkTableExists())
self::$logger->info('Created the ['. $DEnumItem->getTableName(). '] table successfully');
// create a default article DEnum category
$DEnum = new DEnum('ArticleObject::section');
$DEnumItem->set('value', 'Main');
$DEnumItem->set('DEnumID', $DEnum->getID());
self::$logger->error($e->getMessage());
* Loop over each business object in the system, and create a table for it
$loadedClasses = array();
foreach($classNames as $classname) {
foreach($loadedClasses as $classname) {
echo '<p>Attempting to create the table for the class ['. $classname. ']...';
if(!$BO->checkTableExists()) {
if($BO->checkTableNeedsUpdate()) {
$missingFields = $BO->findMissingFields();
$count = count($missingFields);
for($i = 0; $i < $count; $i++ )
$BO->addProperty($missingFields[$i]);
// this are safe to ignore for now as they will be auto-created later once all of the tables are in place
self::$logger->warn($eice->getMessage());
}catch (FailedLookupCreateException $elce) {
// this are safe to ignore for now as they will be auto-created later once all of the tables are in place
self::$logger->warn($elce->getMessage());
self::$logger->info('Created the ['. $BO->getTableName(). '] table successfully');
echo AlphaView::displayUpdateMessage('Created the ['. $BO->getTableName(). '] table successfully');
self::$logger->error($e->getMessage());
* Create the Admin and Standard groups
$adminGroup->set('name', 'Admin');
$standardGroup->set('name', 'Standard');
echo '<p>Attempting to create the Admin and Standard groups...';
self::$logger->info('Created the Admin and Standard rights groups successfully');
echo AlphaView::displayUpdateMessage('Created the Admin and Standard rights groups successfully');
// this are safe to ignore for now as they will be auto-created later once all of the tables are in place
self::$logger->warn($eice->getMessage());
}catch (FailedLookupCreateException $elce) {
// this are safe to ignore for now as they will be auto-created later once all of the tables are in place
self::$logger->warn($elce->getMessage());
self::$logger->error($e->getMessage());
* Save the admin user to the database in the right group
echo '<p>Attempting to save the Admin account...';
$admin->set('displayName', 'Admin');
$admin->set('email', $_SESSION['currentUser']->get('email'));
$admin->set('password', $_SESSION['currentUser']->get('password'));
self::$logger->info('Created the admin user account ['. $_SESSION['currentUser']->get('email'). '] successfully');
$adminGroup->loadByAttribute('name', 'Admin');
$lookup = $adminGroup->getMembers()->getLookup();
$lookup->setValue(array($admin->getID(), $adminGroup->getID()));
self::$logger->info('Added the admin account to the Admin group successfully');
echo AlphaView::displayUpdateMessage('Added the admin account to the Admin group successfully');
// this are safe to ignore for now as they will be auto-created later once all of the tables are in place
self::$logger->warn($eice->getMessage());
}catch (FailedLookupCreateException $elce) {
// this are safe to ignore for now as they will be auto-created later once all of the tables are in place
self::$logger->warn($elce->getMessage());
self::$logger->error($e->getMessage());
self::$logger->info('Finished installation!');
self::$logger->debug('<<doGET');
* Copies a .htaccess file that restricts public access to the target directory
private function copyRestrictedAccessFileToDirectory($dir) {
copy($config->get('sysRoot'). 'alpha/.htaccess', $dir. '/.htaccess');
* Creates the standard application directories
private function createAppDirectories() {
// set the umask first before attempt mkdir
* Create the logs directory, then instantiate a new logger
$logsDir = $config->get('sysRoot'). 'logs';
echo '<p>Attempting to create the logs directory <em>'. $logsDir. '</em>...';
$this->copyRestrictedAccessFileToDirectory($logsDir);
self::$logger = new Logger('Install');
self::$logger->info('Started installation process!');
self::$logger->info('Logs directory ['. $logsDir. '] successfully created');
echo AlphaView::displayUpdateMessage('Logs directory ['. $logsDir. '] successfully created');
* Create the cron tasks directory
$tasksDir = $config->get('sysRoot'). 'tasks';
echo '<p>Attempting to create the tasks directory <em>'. $tasksDir. '</em>...';
$this->copyRestrictedAccessFileToDirectory($logsDir);
self::$logger->info('Tasks directory ['. $tasksDir. '] successfully created');
echo AlphaView::displayUpdateMessage('Tasks directory ['. $tasksDir. '] successfully created');
* Create the controller directory
$controllerDir = $config->get('sysRoot'). 'controller';
echo '<p>Attempting to create the controller directory <em>'. $controllerDir. '</em>...';
mkdir($controllerDir, 0766);
self::$logger->info('Controller directory ['. $controllerDir. '] successfully created');
echo AlphaView::displayUpdateMessage('Controllers directory ['. $controllerDir. '] successfully created');
* Create the model directory
$modelDir = $config->get('sysRoot'). 'model';
echo '<p>Attempting to create the model directory <em>'. $modelDir. '</em>...';
$this->copyRestrictedAccessFileToDirectory($modelDir);
self::$logger->info('Model directory ['. $modelDir. '] successfully created');
echo AlphaView::displayUpdateMessage('Model directory ['. $modelDir. '] successfully created');
* Create the view directory
$viewDir = $config->get('sysRoot'). 'view';
echo '<p>Attempting to create the view directory <em>'. $viewDir. '</em>...';
$this->copyRestrictedAccessFileToDirectory($viewDir);
self::$logger->info('View directory ['. $viewDir. '] successfully created');
echo AlphaView::displayUpdateMessage('View directory ['. $viewDir. '] successfully created');
* Create the attachments directory
$attachmentsDir = $config->get('sysRoot'). 'attachments';
echo '<p>Attempting to create the attachments directory <em>'. $attachmentsDir. '</em>...';
mkdir($attachmentsDir, 0766);
$this->copyRestrictedAccessFileToDirectory($attachmentsDir);
self::$logger->info('Attachments directory ['. $attachmentsDir. '] successfully created');
echo AlphaView::displayUpdateMessage('Attachments directory ['. $attachmentsDir. '] successfully created');
* Create the cache directory and sub-directories
$cacheDir = $config->get('sysRoot'). 'cache';
$htmlDir = $config->get('sysRoot'). 'cache/html';
$imagesDir = $config->get('sysRoot'). 'cache/images';
$pdfDir = $config->get('sysRoot'). 'cache/pdf';
$xlsDir = $config->get('sysRoot'). 'cache/xls';
echo '<p>Attempting to create the cache directory <em>'. $cacheDir. '</em>...';
$this->copyRestrictedAccessFileToDirectory($cacheDir);
self::$logger->info('Cache directory ['. $cacheDir. '] successfully created');
echo AlphaView::displayUpdateMessage('Cache directory ['. $cacheDir. '] successfully created');
echo '<p>Attempting to create the HTML cache directory <em>'. $htmlDir. '</em>...';
$this->copyRestrictedAccessFileToDirectory($htmlDir);
self::$logger->info('Cache directory ['. $htmlDir. '] successfully created');
echo AlphaView::displayUpdateMessage('Cache directory ['. $htmlDir. '] successfully created');
echo '<p>Attempting to create the cache directory <em>'. $imagesDir. '</em>...';
$this->copyRestrictedAccessFileToDirectory($imagesDir);
self::$logger->info('Cache directory ['. $imagesDir. '] successfully created');
echo AlphaView::displayUpdateMessage('Cache directory ['. $imagesDir. '] successfully created');
echo '<p>Attempting to create the cache directory <em>'. $pdfDir. '</em>...';
$this->copyRestrictedAccessFileToDirectory($pdfDir);
self::$logger->info('Cache directory ['. $pdfDir. '] successfully created');
echo AlphaView::displayUpdateMessage('Cache directory ['. $pdfDir. '] successfully created');
echo '<p>Attempting to create the cache directory <em>'. $xlsDir. '</em>...';
$this->copyRestrictedAccessFileToDirectory($xlsDir);
self::$logger->info('Cache directory ['. $xlsDir. '] successfully created');
echo AlphaView::displayUpdateMessage('Cache directory ['. $xlsDir. '] successfully created');
public function doPOST($params) {
self::$logger->debug('>>doPOST($params=['. var_export($params, true). '])');
self::$logger->debug('<<doPOST');
* Custom version of the check rights method that only checks for a session for the config admin username/password,
* when the system database is not set-up
self::$logger->debug('>>checkRights()');
self::$logger->debug('<<checkRights [true]');
self::$logger->debug('<<checkRights [false]');
// the person is logged in?
if (isset ($_SESSION['currentUser'])) {
if ($_SESSION['currentUser']->get('email') == $config->get('sysInstallUsername')) {
self::$logger->debug('<<checkRights [true]');
// now build the new controller
if(basename($_SERVER['PHP_SELF']) == 'Install.php') {
$controller->doPOST($_REQUEST);
$controller->doGET($_GET);
|