Source

topics / installer / index.php

Full commit
<?php
function checkInstallerPermissions()
{
    $out = array();
    $message = '';
    $error = 0;
    if(is_writable(dirname(__FILE__).'/assets')) {
        $message .= 'assets directory is <b><font color="green">writable</font></b><br/>';
    } else {
        if(@chmod(dirname(__FILE__).'/assets', 0755)) {
            $message .= 'assets directory has been made <b><font color="green">writable</font></b><br/>';
        } else {
            $message .= 'assets directory is not writable - <b><font color="red">error!</font></b><br/>';
            $error += 1;
        }
    }
    if(is_writable(dirname(__FILE__).'/protected/runtime')) {
        $message .= 'protected/runtime directory is <b><font color="green">writable</font></b><br/>';
    } else {
        if(@chmod(dirname(__FILE__).'/../../../protected/runtime', 0755)) {
            $message .= 'protected/runtime directory has been made <b><font color="green">writable</font></b><br/>';
        } else {
            $message .= 'protected/runtime directory is not writable - <b><font color="red">error!</font></b><br/>';
            $error += 1;
        }
    }
    if(is_writable(dirname(__FILE__).'/')) {
        $message .= 'installer directory is <b><font color="green">writable</font></b><br/>';
    } else {
        if(@chmod(dirname(__FILE__).'/../../../protected/config', 0755)) {
        $message .= 'installer directory has been made <b><font color="green">writable</font></b><br/>';
        } else {
            $message .= 'installer directory is not writable - <b><font color="red">error!</font></b><br/>';
            $error += 1;
        }
    }
    $out['message'] = $message;
    $out['error'] = $error;
    return $out;
}

// change the following paths if necessary
$yii=dirname(__FILE__).'/../../yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

if(!file_exists($yii))
{
    die("<font color=\"red\">Error:</font> Cannot find Yii!<br/>
            Please check and correct the path to Yii in <em>{$_SERVER['SERVER_NAME']}/installer/index.php</em> and <em>{$_SERVER['SERVER_NAME']}/index.php</em>");
}
if(file_exists(dirname(__FILE__).'/lock')) {
    die("<font color=\"red\">Attention:</font> Installer has been locked.<br/>
        Please remove the lock file in the installer directory and try again.");
}
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',2);
require_once($yii);

$status = checkInstallerPermissions();
$message = $status['message'];
$message .= '<br/>';
$failed = false;
if($status['error'] > 0) {
    $failed = true;
    $message .= "There were {$status['error']} errors.<br/>";
    $message .= 'Please adjust permissions so that the above entries are writable by the Apache process.<br/>';
    die($message);
}

Yii::createWebApplication($config)->run();