Ejemplo n.º 1
0
 protected function storeConfiguration()
 {
     $dbConfig = $this->dataSource->getDatabaseConfiguration();
     $config = ['debug' => true, 'database' => ['driver' => $dbConfig['driver'], 'host' => $dbConfig['host'], 'database' => $dbConfig['database'], 'username' => $dbConfig['username'], 'password' => $dbConfig['password'], 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => $dbConfig['prefix'], 'strict' => false], 'url' => $this->dataSource->getBaseUrl(), 'paths' => ['api' => 'api', 'admin' => 'admin']];
     $this->info('Testing config');
     $this->container->instance('flarum.config', $config);
     $this->container->make('flarum.db');
     $this->info('Writing config');
     file_put_contents($this->getConfigFile(), '<?php return ' . var_export($config, true) . ';');
 }
Ejemplo n.º 2
0
 protected function storeConfiguration()
 {
     $dbConfig = $this->dataSource->getDatabaseConfiguration();
     $config = ['debug' => true, 'database' => ['driver' => $dbConfig['driver'], 'host' => $dbConfig['host'], 'database' => $dbConfig['database'], 'username' => $dbConfig['username'], 'password' => $dbConfig['password'], 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => $dbConfig['prefix'], 'strict' => false], 'url' => $this->dataSource->getBaseUrl(), 'paths' => ['api' => 'api', 'admin' => 'admin']];
     $this->info('Testing config');
     $this->application->instance('flarum.config', $config);
     /* @var $db \Illuminate\Database\ConnectionInterface */
     $db = $this->application->make('flarum.db');
     $version = $db->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
     if (version_compare($version, '5.5.0', '<')) {
         throw new Exception('MySQL version too low. You need at least MySQL 5.5.');
     }
     $this->info('Writing config');
     file_put_contents($this->getConfigFile(), '<?php return ' . var_export($config, true) . ';');
 }
Ejemplo n.º 3
0
 protected function install()
 {
     try {
         $this->dbConfig = $this->dataSource->getDatabaseConfiguration();
         $validation = $this->getValidator()->make($this->dbConfig, ['driver' => 'required|in:mysql', 'host' => 'required', 'database' => 'required|alpha_dash', 'username' => 'required|alpha_dash', 'prefix' => 'alpha_dash|max:10']);
         if ($validation->fails()) {
             throw new Exception(implode("\n", call_user_func_array('array_merge', $validation->getMessageBag()->toArray())));
         }
         $this->baseUrl = $this->dataSource->getBaseUrl();
         $this->settings = $this->dataSource->getSettings();
         $this->adminUser = $admin = $this->dataSource->getAdminUser();
         if (strlen($admin['password']) < 8) {
             throw new Exception('Password must be at least 8 characters.');
         }
         if ($admin['password'] !== $admin['password_confirmation']) {
             throw new Exception('The password did not match its confirmation.');
         }
         if (!filter_var($admin['email'], FILTER_VALIDATE_EMAIL)) {
             throw new Exception('You must enter a valid email.');
         }
         if (!$admin['username'] || preg_match('/[^a-z0-9_-]/i', $admin['username'])) {
             throw new Exception('Username can only contain letters, numbers, underscores, and dashes.');
         }
         $this->storeConfiguration();
         $this->runMigrations();
         $this->writeSettings();
         $this->application->register('Flarum\\Core\\CoreServiceProvider');
         $resolver = $this->application->make('Illuminate\\Database\\ConnectionResolverInterface');
         Model::setConnectionResolver($resolver);
         Model::setEventDispatcher($this->application->make('events'));
         $this->seedGroups();
         $this->seedPermissions();
         $this->createAdminUser();
         $this->enableBundledExtensions();
     } catch (Exception $e) {
         @unlink($this->getConfigFile());
         throw $e;
     }
 }