Pimcore\Model\Tool\Setup::config PHP Method

config() public method

public config ( array $config = [] )
$config array
    public function config($config = [])
    {
        $settings = null;
        // check for an initial configuration template
        // used eg. by the demo installer
        $configTemplatePath = PIMCORE_CONFIGURATION_DIRECTORY . "/system.template.php";
        if (file_exists($configTemplatePath)) {
            try {
                $configTemplate = new \Zend_Config(include $configTemplatePath);
                if ($configTemplate->general) {
                    // check if the template contains a valid configuration
                    $settings = $configTemplate->toArray();
                    // unset database configuration
                    unset($settings["database"]["params"]["host"]);
                    unset($settings["database"]["params"]["port"]);
                }
            } catch (\Exception $e) {
            }
        }
        // set default configuration if no template is present
        if (!$settings) {
            // write configuration file
            $settings = ["general" => ["timezone" => "Europe/Berlin", "language" => "en", "validLanguages" => "en", "debug" => "1", "debugloglevel" => "debug", "custom_php_logfile" => "1", "extjs6" => "1"], "database" => ["adapter" => "Mysqli", "params" => ["username" => "root", "password" => "", "dbname" => ""]], "documents" => ["versions" => ["steps" => "10"], "default_controller" => "default", "default_action" => "default", "error_pages" => ["default" => "/"], "createredirectwhenmoved" => "", "allowtrailingslash" => "no", "generatepreview" => "1"], "objects" => ["versions" => ["steps" => "10"]], "assets" => ["versions" => ["steps" => "10"]], "services" => [], "cache" => ["excludeCookie" => ""], "httpclient" => ["adapter" => "Zend_Http_Client_Adapter_Socket"]];
        }
        $settings = array_replace_recursive($settings, $config);
        // create initial /website/var folder structure
        // @TODO: should use values out of startup.php (Constants)
        $varFolders = ["areas", "assets", "backup", "cache", "classes", "config", "email", "log", "plugins", "recyclebin", "search", "system", "tmp", "versions", "webdav"];
        foreach ($varFolders as $folder) {
            \Pimcore\File::mkdir(PIMCORE_WEBSITE_VAR . "/" . $folder);
        }
        $configFile = \Pimcore\Config::locateConfigFile("system.php");
        File::putPhpFile($configFile, to_php_data_file_format($settings));
    }

Usage Example

Beispiel #1
0
 public function installAction()
 {
     // database configuration host/unix socket
     $dbConfig = ['username' => $this->getParam("mysql_username"), 'password' => $this->getParam("mysql_password"), 'dbname' => $this->getParam("mysql_database")];
     $hostSocketValue = $this->getParam("mysql_host_socket");
     if (file_exists($hostSocketValue)) {
         $dbConfig["unix_socket"] = $hostSocketValue;
     } else {
         $dbConfig["host"] = $hostSocketValue;
         $dbConfig["port"] = $this->getParam("mysql_port");
     }
     // try to establish a mysql connection
     try {
         $db = \Zend_Db::factory($this->getParam("mysql_adapter"), $dbConfig);
         $db->getConnection();
         // check utf-8 encoding
         $result = $db->fetchRow('SHOW VARIABLES LIKE "character\\_set\\_database"');
         if ($result['Value'] != "utf8") {
             $errors[] = "Database charset is not utf-8";
         }
     } catch (\Exception $e) {
         $errors[] = "Couldn't establish connection to mysql: " . $e->getMessage();
     }
     // check username & password
     if (strlen($this->getParam("admin_password")) < 4 || strlen($this->getParam("admin_username")) < 4) {
         $errors[] = "Username and password should have at least 4 characters";
     }
     if (empty($errors)) {
         $setup = new Tool\Setup();
         // check if /website folder already exists, if not, look for /website_demo & /website_example
         // /website_install is just for testing in dev environment
         if (!is_dir(PIMCORE_WEBSITE_PATH)) {
             foreach (["website_install", "website_demo", "website_example"] as $websiteDir) {
                 $dir = PIMCORE_DOCUMENT_ROOT . "/" . $websiteDir;
                 if (is_dir($dir)) {
                     rename($dir, PIMCORE_WEBSITE_PATH);
                     break;
                 }
             }
         }
         $setup->config(array("database" => array("adapter" => $this->getParam("mysql_adapter"), "params" => $dbConfig)));
         // look for a template dump
         // eg. for use with demo installer
         $dbDataFile = PIMCORE_WEBSITE_PATH . "/dump/data.sql";
         $contentConfig = array("username" => $this->getParam("admin_username"), "password" => $this->getParam("admin_password"));
         if (!file_exists($dbDataFile)) {
             $setup->database();
             \Pimcore::initConfiguration();
             $setup->contents($contentConfig);
         } else {
             $setup->database();
             $setup->insertDump($dbDataFile);
             \Pimcore::initConfiguration();
             $setup->createOrUpdateUser($contentConfig);
         }
         $this->_helper->json(array("success" => true));
     } else {
         echo implode("<br />", $errors);
         die;
     }
 }