Example #1
0
 function indexAction()
 {
     $request = new Bolts_Request($this->getRequest());
     $basepath = Zend_Registry::get('basepath');
     $this->view->timezones = Bolts_Common::getTimeZonesArray();
     if ($this->getRequest()->isPost()) {
         $errors = array();
         /*
          * TODO: Check that smarty dirs are writeable, etc. dir is writable, etc. dir is NOT writeable after install, libraries exist,
          * log level is set to something
          */
         if (!file_exists($basepath . "/.htaccess")) {
             $errors[] = $this->_T("Missing .htaccess file in %s. Maybe use %s/template.htaccess ?", array($basepath, $basepath));
         }
         $etc_dir = $basepath . "/etc";
         $config_filename = $etc_dir . "/config.ini";
         $tmp_path = $basepath . "/tmp";
         $smarty_compile_dir = $tmp_path . "/view_compiles";
         $smarty_cache_dir = $tmp_path . "/cache";
         $image_cache_dir = $tmp_path . "/image_cache";
         $upload_path = $basepath . "/uploads";
         $log_path = $basepath . "/logs";
         $module_cfg = parse_ini_file($basepath . "/modules/bolts/module.ini", true);
         $dir_array = array($etc_dir, $tmp_path, $upload_path, $log_path);
         foreach ($dir_array as $dir) {
             if (!is_writable($dir)) {
                 $errors[] = $this->_T("Web server can't write to %s.", $dir);
             }
         }
         if ($request->admin_username == null) {
             $errors[] = $this->_T("Admin username cannot be blank.");
         }
         if ($request->admin_email == null) {
             $errors[] = $this->_T("Admin email cannot be blank.");
         }
         if ($request->app_name == null) {
             $errors[] = $this->_T("Application name cannot be blank.");
         }
         $cfg_array = array("database" => array("adapter" => "PDO_MYSQL", "params" => array("host" => $request->db_host, "dbname" => $request->db_name, "username" => $request->db_user, "password" => $request->db_pass, "port" => $request->db_port)));
         if (!is_null($request->db_sock)) {
             $cfg_array['database']['params']['unix_socket'] = $request->db_sock;
             // this is often something like /var/run/mysqld/mysqld.sock
         }
         $dbconfig = new Zend_Config($cfg_array);
         $db = Zend_Db::factory($dbconfig->database);
         try {
             if (count($errors) == 0) {
                 $tables = $db->listTables();
                 if (count($tables) > 0) {
                     $errors[] = $this->_T("The specified database is not empty.");
                 }
                 // get the table creation script
                 $ddl_file = $basepath . "/core/bolts/sql/" . $dbconfig->database->adapter . "/install.sql";
                 if (file_exists($ddl_file)) {
                     $queries = explode(";", file_get_contents($ddl_file));
                     $db->beginTransaction();
                     try {
                         foreach ($queries as $query) {
                             if (trim($query) != "") {
                                 $query = str_replace("@@@@ADMIN_USERNAME@@@@", $request->admin_username, $query);
                                 $query = str_replace("@@@@ADMIN_EMAIL@@@@", $request->admin_email, $query);
                                 $query = str_replace("@@@@CREATED_ON@@@@@", date("Y-m-d H:i:s"), $query);
                                 $db->query($query);
                             }
                         }
                         $db->commit();
                     } catch (Exception $e) {
                         $db->rollBack();
                         $errors[] = $e->getMessage();
                     }
                 } else {
                     $errors[] = $this->_T("Database creation script not found.");
                 }
             }
         } catch (Exception $e) {
             $errors[] = $e->getMessage();
         }
         if (count($errors) == 0) {
             // everything worked out okay, attempt to write the config file
             $config = array("db.communitas.adapter" => "PDO_MYSQL", "db.communitas.config.host" => $request->db_host, "db.communitas.config.dbname" => $request->db_name, "db.communitas.config.username" => $request->db_user, "db.communitas.config.password" => $request->db_pass, "db.communitas.config.port" => $request->db_port, "db.communitas.config.default" => "true");
             if (!is_null($request->db_sock)) {
                 $config['db.communitas.config.unix_socket'] = $request->db_sock;
             }
             $config_file .= Bolts_ConfigFile::makeSection("databases", "Database Settings", "This is the default database.", $config);
             $Bolts_config = array("timezone" => $request->Bolts_timezone, "launched" => "1", "prelaunch_url" => "http://google.com", "allowed_ips" => "127.0.0.1", "zf_path" => $basepath . "/lib/ZendFramework/library", "smarty_path" => $basepath . "/lib/Smarty/libs", "asido_path" => $basepath . "/lib/Asido", "image_cache_dir" => $image_cache_dir, "log_filename" => $log_path . "/bolts.log", "log_level" => "6", "addtl_includes" => "");
             $config_file .= Bolts_ConfigFile::makeSection("application", "Application Settings", "These are the application specific settings.", $Bolts_config);
             // create directories if needed
             if (!file_exists($smarty_compile_dir)) {
                 mkdir($smarty_compile_dir, 0777, true);
             }
             if (!file_exists($smarty_cache_dir)) {
                 mkdir($smarty_cache_dir, 0777, true);
             }
             if (!file_exists($image_cache_dir)) {
                 mkdir($image_cache_dir, 0777, true);
             }
             $smarty_config = array("config.compile_dir" => $smarty_compile_dir, "config.cache_dir" => $smarty_cache_dir);
             $config_file .= Bolts_ConfigFile::makeSection("smarty", "Smarty Settings", "These are the settings for the Smarty template engine.", $smarty_config);
             if (file_put_contents($config_filename, $config_file) === false) {
                 $this->view->config_file = $config_file;
                 $this->view->config_filename = $config_filename;
                 $this->view->success = "Database installed, but could not write config file. Please create the file \"" . $config_filename . "\" and paste this following into it:";
             } else {
                 $this->_redirect("/bolts/install/secondstage/username/" . $request->admin_username . "/appname/" . $request->app_name);
             }
         } else {
             $this->view->errors = $errors;
             $this->view->db_host = $request->db_host;
             $this->view->db_name = $request->db_name;
             $this->view->db_user = $request->db_user;
             $this->view->db_pass = $request->db_pass;
             $this->view->db_port = $request->db_port;
             $this->view->db_sock = $request->db_sock;
             $this->view->app_name = $request->app_name;
             $this->view->admin_username = $request->admin_username;
             $this->view->admin_email = $request->admin_email;
             $this->view->Bolts_timezone = $request->Bolts_timezone;
         }
     } else {
         $this->view->db_host = "localhost";
         $this->view->db_name = "bolts";
         $this->view->db_user = "******";
         $this->view->db_pass = "";
         $this->view->db_port = "3306";
         $this->view->db_sock = "";
         $this->view->app_name = "My Application";
         $this->view->admin_username = "******";
         $this->view->Bolts_timezone = "America/Los_Angeles";
     }
 }
Example #2
0
 function cache()
 {
     $basepath = Zend_Registry::get('basepath');
     $config_cache_file = $basepath . "/etc/cached_config.ini";
     if (file_exists($config_cache_file)) {
         unlink($config_cache_file);
     }
     if (!file_exists($config_cache_file)) {
         $cacheable = $this->fetchAll('is_cached = 1');
         $config_cache = array();
         if (count($cacheable) > 0) {
             foreach ($cacheable as $config_item) {
                 $config_cache[$config_item->module . "." . $config_item->ckey] = $config_item->value;
             }
         }
         $comment = "THIS FILE IS AUTO-GENERATED. DO NOT EDIT THIS FILE DIRECTLY. YOUR CHANGES WILL BE OVERWRITTEN.";
         $config_cache_string = Bolts_ConfigFile::makeSection("cached", "Cached Config", $comment, $config_cache);
         file_put_contents($config_cache_file, $config_cache_string);
     }
 }