Commits

Jacob Moen committed 0535285

Trying to fool-proof installer

  • Participants
  • Parent commits 7d3838a

Comments (0)

Files changed (3)

 # php_flag log_errors On
 
 # Do not display errors in browser (production - Off, development - On)
-# php_flag display_errors Off
+php_flag display_errors On
 
 # Do not display startup errors (production - Off, development - On)
 # php_flag display_startup_errors Off

installer/index.php

 <?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';
 // 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();

installer/protected/controllers/InstallController.php

         $error = 0;
         if(is_writable(dirname(__FILE__).'/../../../assets')) {
             $message .= 'assets directory is <b><font color="green">writable</font></b><br/>';
-        } else
-        {
+        } elseif(@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__).'/../../../uploads')) {
-            $message .= 'uploads directory is <b><font color="green">writable</font></b><br/>';
-        } else
-        {
-            $message .= 'uploads directory is not writable - <b><font color="red">error!</font></b><br/>';
-            $error += 1;
-        }
-        if(is_writable(dirname(__FILE__).'/../../../repositories')) {
-            $message .= 'repositories directory is <b><font color="green">writable</font></b><br/>';
-        } else
-        {
-            $message .= 'repositories 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
-        {
+        } elseif(@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__).'/../../../protected/config')) {
             $message .= 'protected/config directory is <b><font color="green">writable</font></b><br/>';
-        } else
-        {
+        } elseif(@chmod(dirname(__FILE__).'/../../../protected/config', 0755)) {
+            $message .= 'protected/config directory has been made <b><font color="green">writable</font></b><br/>';
+        } else {
             $message .= 'protected/config directory is not writable - <b><font color="red">error!</font></b><br/>';
             $error += 1;
         }