示例#1
0
 /**
  * Save configurations build by installer interface
  */
 public function make()
 {
     // prepare configurations to save
     /** @var array $cfg */
     $cfg = App::$Properties->getAll('default');
     $this->before();
     $cfg['baseDomain'] = $this->baseDomain;
     $cfg['database'] = $this->db;
     $cfg['adminEmail'] = $this->email;
     $cfg['singleLanguage'] = $this->singleLanguage;
     $cfg['multiLanguage'] = (bool) $this->multiLanguage;
     $cfg['passwordSalt'] = '$2a$07$' . Str::randomLatinNumeric(mt_rand(21, 30)) . '$';
     $cfg['debug']['cookie']['key'] = 'fdebug_' . Str::randomLatinNumeric(mt_rand(4, 16));
     $cfg['debug']['cookie']['value'] = Str::randomLatinNumeric(mt_rand(32, 128));
     // import database tables
     $connectName = 'install';
     include root . '/Private/Database/install.php';
     // insert admin user
     $user = new User();
     $user->setConnection('install');
     $user->login = $this->user['login'];
     $user->email = $this->user['email'];
     $user->role_id = 4;
     $user->password = App::$Security->password_hash($this->user['password'], $cfg['passwordSalt']);
     $user->save();
     $profile = new Profile();
     $profile->setConnection('install');
     $profile->user_id = $user->id;
     $profile->save();
     // set installation version
     $system = new System();
     $system->setConnection('install');
     $system->var = 'version';
     $system->data = Version::VERSION;
     $system->save();
     // write config data
     App::$Properties->writeConfig('default', $cfg);
     // make routing configs based on preset property
     $routing = [];
     switch ($this->mainpage) {
         case 'news':
             $routing = ['Alias' => ['Front' => ['/' => '/content/list/news', '/about' => '/content/read/page/about-page']]];
             break;
         case 'about':
             $routing = ['Alias' => ['Front' => ['/' => '/content/read/page/about-page']]];
             break;
     }
     // write routing configurations
     App::$Properties->writeConfig('routing', $routing);
     // write installer lock
     File::write('/Private/Install/install.lock', 'Installation is locked!');
 }
示例#2
0
 /**
  * Set default model properties
  */
 public function before()
 {
     $this->scriptVersion = Version::VERSION;
     $this->dbVersion = System::getVar('version')['data'];
     $this->versionsEqual = version_compare($this->scriptVersion, $this->dbVersion) === 0;
     $this->findLatestVersion();
     $this->haveRemoteNew = $this->lastVersion !== null && version_compare($this->scriptVersion, $this->lastVersion) === -1;
 }
示例#3
0
 /**
  * Include files with update queries
  */
 public function make()
 {
     // run update queries from included files
     foreach ($this->updateQueries as $file) {
         @(include root . '/Private/Database/Updates/' . $file . '.php');
     }
     // update version in db table
     $row = System::getVar('version');
     $row->data = $this->scriptVersion;
     $row->save();
 }
示例#4
0
文件: Main.php 项目: phpffcms/ffcms
 /**
  * Console installation
  * @return string
  * @throws NativeException
  */
 public function actionInstall()
 {
     if (File::exist('/Private/Install/install.lock')) {
         throw new NativeException('Installation is locked! Please delete /Private/Install/install.lock');
     }
     echo Console::$Output->writeHeader('License start');
     echo File::read('/LICENSE') . PHP_EOL;
     echo Console::$Output->writeHeader('License end');
     $config = Console::$Properties->get('database');
     $newConfig = [];
     // creating default directory's
     foreach (self::$installDirs as $obj) {
         // looks like a directory
         if (!Str::contains('.', $obj)) {
             Directory::create($obj, 0777);
         }
     }
     echo Console::$Output->write('Upload and private directories are successful created!');
     // set chmods
     echo $this->actionChmod();
     // database config from input
     echo Console::$Output->writeHeader('Database connection configuration');
     echo 'Driver(default:' . $config['driver'] . '):';
     $dbDriver = Console::$Input->read();
     if (Arr::in($dbDriver, ['mysql', 'pgsql', 'sqlite'])) {
         $newConfig['driver'] = $dbDriver;
     }
     // for sqlite its would be a path
     echo 'Host(default:' . $config['host'] . '):';
     $dbHost = Console::$Input->read();
     if (!Str::likeEmpty($dbHost)) {
         $newConfig['host'] = $dbHost;
     }
     echo 'Database name(default:' . $config['database'] . '):';
     $dbName = Console::$Input->read();
     if (!Str::likeEmpty($dbName)) {
         $newConfig['database'] = $dbName;
     }
     echo 'User(default:' . $config['username'] . '):';
     $dbUser = Console::$Input->read();
     if (!Str::likeEmpty($dbUser)) {
         $newConfig['username'] = $dbUser;
     }
     echo 'Password(default:' . $config['password'] . '):';
     $dbPwd = Console::$Input->read();
     if (!Str::likeEmpty($dbPwd)) {
         $newConfig['password'] = $dbPwd;
     }
     echo 'Table prefix(default:' . $config['prefix'] . '):';
     $dbPrefix = Console::$Input->read();
     if (!Str::likeEmpty($dbPrefix)) {
         $newConfig['prefix'] = $dbPrefix;
     }
     // merge configs and add new connection to db pull
     $dbConfigs = Arr::merge($config, $newConfig);
     Console::$Database->addConnection($dbConfigs, 'install');
     try {
         Console::$Database->connection('install')->getDatabaseName();
     } catch (\Exception $e) {
         return 'Testing database connection is failed! Run installer again and pass tested connection data! Log: ' . $e->getMessage();
     }
     // autoload isn't work here
     include root . '/Apps/Controller/Console/Db.php';
     // import db data
     $dbController = new DbController();
     echo $dbController->actionImportAll('install');
     // add system info about current install version
     $system = new System();
     $system->setConnection('install');
     $system->var = 'version';
     $system->data = Version::VERSION;
     $system->save();
     // set website send from email from input
     $emailConfig = Console::$Properties->get('adminEmail');
     echo 'Website sendFrom email(default: ' . $emailConfig . '):';
     $email = Console::$Input->read();
     if (!Str::isEmail($email)) {
         $email = $emailConfig;
     }
     // set base domain
     echo 'Website base domain name(ex. ffcms.org):';
     $baseDomain = Console::$Input->read();
     if (Str::likeEmpty($baseDomain)) {
         $baseDomain = Console::$Properties->get('baseDomain');
     }
     // generate other configuration data and security salt, key's and other
     echo Console::$Output->writeHeader('Writing configurations');
     /** @var array $allCfg */
     $allCfg = Console::$Properties->getAll('default');
     $allCfg['database'] = $dbConfigs;
     $allCfg['adminEmail'] = $email;
     $allCfg['baseDomain'] = $baseDomain;
     echo Console::$Output->write('Generate password salt for BLOWFISH crypt');
     $allCfg['passwordSalt'] = '$2a$07$' . Str::randomLatinNumeric(mt_rand(21, 30)) . '$';
     echo Console::$Output->write('Generate security cookies for debug panel');
     $allCfg['debug']['cookie']['key'] = 'fdebug_' . Str::randomLatinNumeric(mt_rand(8, 32));
     $allCfg['debug']['cookie']['value'] = Str::randomLatinNumeric(mt_rand(32, 128));
     // write config data
     $writeCfg = Console::$Properties->writeConfig('default', $allCfg);
     if ($writeCfg !== true) {
         return 'File /Private/Config/Default.php is unavailable to write data!';
     }
     File::write('/Private/Install/install.lock', 'Install is locked');
     return 'Configuration done! FFCMS 3 is successful installed! Visit your website. You can add administrator using command php console.php db/adduser';
 }