Exemplo n.º 1
0
 /**
  * @Request({"config": "array", "option": "array", "tab": "int"}, csrf=true)
  */
 public function saveAction($data, $option, $tab = 0)
 {
     // TODO: validate
     $data['app.debug'] = @$data['app.debug'] ?: '0';
     $data['profiler.enabled'] = @$data['profiler.enabled'] ?: '0';
     $data['app.nocache'] = @$data['app.nocache'] ?: '0';
     $data['cache.cache.storage'] = @$data['cache.cache.storage'] ?: 'auto';
     $option['system:app.site_title'] = @$option['system:app.site_title'] ?: '';
     $option['system:maintenance.enabled'] = @$option['system:maintenance.enabled'] ?: '0';
     foreach ($data as $key => $value) {
         $this->config->set($key, $value);
     }
     file_put_contents($this->configFile, $this->config->dump());
     foreach ($option as $key => $value) {
         $this['option']->set($key, $value, true);
     }
     if ($data['cache.cache.storage'] != $this['config']->get('cache.cache.storage') || $data['app.debug'] != $this['config']->get('app.debug')) {
         $this['system']->clearCache();
     }
     if (function_exists('opcache_invalidate')) {
         opcache_invalidate($this->configFile);
     }
     $this['message']->success(__('Settings saved.'));
     return $this->redirect('@system/settings', compact('tab'));
 }
 /**
  * @Request({"config": "array", "option": "array", "user": "******"})
  * @Response("json")
  */
 public function installAction($config = [], $option = [], $user = [])
 {
     $status = $this->checkAction($config, false);
     $message = '';
     try {
         foreach (['blog', 'page', 'system'] as $extension) {
             $this['extensions']->load($extension);
         }
         if ('no-connection' == $status) {
             throw new Exception(__('No database connection.'));
         }
         if ('tables-exist' == $status) {
             $this['extensions']->get('system')->enable();
         } else {
             $this['option']->set('system:version', $this['migrator']->create('extension://system/migrations')->run());
             $this['option']->set('system:extensions', ['blog', 'page'], true);
             $this['db']->insert('@system_user', ['name' => $user['username'], 'username' => $user['username'], 'password' => $this['auth.password']->hash($user['password']), 'status' => 1, 'email' => $user['email'], 'registered' => new \DateTime()], ['string', 'string', 'string', 'string', 'string', 'datetime']);
             $id = $this['db']->lastInsertId();
             $this['db']->insert('@system_user_role', ['user_id' => $id, 'role_id' => RoleInterface::ROLE_AUTHENTICATED]);
             $this['db']->insert('@system_user_role', ['user_id' => $id, 'role_id' => RoleInterface::ROLE_ADMINISTRATOR]);
             $this['extensions']->get('system')->enable();
             // sample data
             $sql = file_get_contents('extension://installer/sample_data.sql');
             foreach (explode(';', $sql) as $query) {
                 if ($query = trim($query)) {
                     $this['db']->executeUpdate($query);
                 }
             }
         }
         if (!$this->config) {
             $configuration = new Config();
             foreach ($config as $key => $value) {
                 $configuration->set($key, $value);
             }
             $configuration->set('app.key', $this['auth.random']->generateString(64));
             if (!file_put_contents($this->configFile, $configuration->dump())) {
                 $status = 'write-failed';
                 throw new Exception(__('Can\'t write config.'));
             }
         }
         foreach ($option as $key => $value) {
             $this['option']->set($key, $value, true);
         }
         $status = 'success';
     } catch (DBALException $e) {
         $status = 'db-sql-failed';
         $message = __('Database error: %error%', ['%error%' => $e->getMessage()]);
     } catch (\Exception $e) {
         $message = $e->getMessage();
     }
     return ['status' => $status, 'message' => $message];
 }
Exemplo n.º 3
0
 public function testDump()
 {
     $this->config->dump();
 }