Ejemplo n.º 1
0
 public static function init($configfile, $mode = "running", $entryScript = "")
 {
     require_once "Installer.php";
     date_default_timezone_set("Asia/Jakarta");
     $bp = Setting::setupBasePath($configfile);
     $ap = Setting::$rootPath . DIRECTORY_SEPARATOR . "app";
     Setting::$path = $ap . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "settings.json";
     if (!is_file(Setting::$path)) {
         $configdir = dirname(Setting::$path);
         if (!is_dir($configdir)) {
             mkdir($configdir, 777, true);
         }
         $oldConfig = $bp . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "settings.json";
         if (is_file($oldConfig)) {
             rename($oldConfig, Setting::$path);
             header("Location: " . $_SERVER['DOCUMENT_URI']);
             die;
         }
         $json = Setting::$default;
         $json = json_encode($json, JSON_PRETTY_PRINT);
         $result = @file_put_contents(Setting::$path, $json);
         require_once "Installer.php";
         Installer::createIndexFile("install");
         Setting::$mode = "install";
     }
     $file = @file_get_contents(Setting::$path);
     ## set entry script
     Setting::$entryScript = realpath($entryScript == "" ? $_SERVER["SCRIPT_FILENAME"] : $entryScript);
     ## set default data value
     if (!$file || isset($result) && !$result) {
         Setting::$data = Setting::$default;
         $path = isset($result) && !$result ? $result : $file;
         if (!$path) {
             $path = Setting::$path;
         }
         $_GET['errorBeforeInstall'] = true;
         Setting::redirError("Failed to write in '{path}'", ["{path}" => $path]);
         return false;
     } else {
         $setting = json_decode($file, true);
         Setting::$data = Setting::arrayMergeRecursiveReplace(Setting::$default, $setting);
     }
     ## set host
     if (!Setting::get('app.host')) {
         $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
         $port = $_SERVER['SERVER_PORT'] == 443 || $_SERVER['SERVER_PORT'] == 80 ? "" : ":" . $_SERVER['SERVER_PORT'];
         Setting::set('app.host', $protocol . $_SERVER['HTTP_HOST'] . $port);
     }
     ## set debug
     if (Setting::$mode == null) {
         Setting::$mode = $mode;
     }
     if ($mode == 'testing') {
         Setting::$mode = 'testing';
     }
     if (Setting::get('app.mode') != 'production') {
         defined('YII_DEBUG') or define('YII_DEBUG', true);
         defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
     }
 }
Ejemplo n.º 2
0
 public static function init($config)
 {
     ## we hare to make sure the error page is shown
     ## so we need to strip yii unneeded config to make sure it is running
     $config['defaultController'] = "install";
     $config['components']['errorHandler'] = ['errorAction' => 'install/default/index'];
     Installer::checkInstall();
     if (Setting::$mode == "init") {
         $url = preg_replace('/\\/?plansys\\/?$/', '', Setting::fullPath());
         if (is_file(Setting::getRootPath() . DIRECTORY_SEPARATOR . "index.php")) {
             header("Location: " . $url . "/index.php");
             die;
         }
         if (!Installer::createIndexFile()) {
             Setting::redirError("Failed to write in \"{path}\" <br/> Permission denied", ['{path}' => Setting::getRootPath() . DIRECTORY_SEPARATOR . "index.php"]);
             return $config;
         } else {
             header("Location: " . $url . "/index.php?r=install/default/index");
             die;
         }
     }
     return $config;
 }
Ejemplo n.º 3
0
 public function actionDb()
 {
     $model = new InstallDbForm();
     $model->host = Setting::get('db.host');
     $model->username = Setting::get('db.username');
     $model->password = Setting::get('db.password');
     $model->dbname = Setting::get('db.dbname');
     $error = false;
     $mode = "init";
     if (isset($_POST['InstallDbForm'])) {
         $model->attributes = $_POST['InstallDbForm'];
         if ($model->validate()) {
             $error = false;
             try {
                 $dbh = new pdo("mysql:host={$model->host};dbname={$model->dbname}", $model->username, $model->password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
             } catch (PDOException $ex) {
                 $error = $ex->getMessage();
             }
             if (!$error) {
                 Setting::set('db.host', $model->host, false);
                 Setting::set('db.username', $model->username, false);
                 Setting::set('db.password', $model->password, false);
                 Setting::set('db.dbname', $model->dbname, false);
                 Setting::write();
                 if ($model->resetdb == "yes") {
                     Installer::createIndexFile("install");
                     $this->redirect(['/install/default/resetdb']);
                 } else {
                     Installer::createIndexFile("running");
                     $this->redirect(['/install/default/finish']);
                 }
             }
         }
     }
     $this->renderForm('InstallDbForm', $model, ['error' => $error, 'mode' => $mode]);
 }