enable() public method

public enable ( $packages )
$packages
 /**
  * @Request({"name"}, csrf=true)
  */
 public function enableAction($name)
 {
     $handler = $this->errorHandler($name);
     if (!($package = App::package($name))) {
         App::abort(400, __('Unable to find "%name%".', ['%name%' => $name]));
     }
     App::module()->load($package->get('module'));
     if (!($module = App::module($package->get('module')))) {
         App::abort(400, __('Unable to enable "%name%".', ['%name%' => $package->get('title')]));
     }
     $this->manager->enable($package);
     App::exception()->setHandler($handler);
     return ['message' => 'success'];
 }
Ejemplo n.º 2
0
 public function install($config = [], $option = [], $user = [])
 {
     $status = $this->check($config);
     $message = $status['message'];
     $status = $status['status'];
     try {
         if ('no-connection' == $status) {
             $this->app->abort(400, __('No database connection.'));
         }
         if ('tables-exist' == $status) {
             $this->app->abort(400, $message);
         }
         $scripts = new PackageScripts($this->app->path() . '/app/system/scripts.php');
         $scripts->install();
         $this->app->db()->insert('@system_user', ['name' => $user['username'], 'username' => $user['username'], 'password' => $this->app->get('auth.password')->hash($user['password']), 'status' => 1, 'email' => $user['email'], 'registered' => date('Y-m-d H:i:s'), 'roles' => '2,3']);
         $option['system']['version'] = $this->app->version();
         foreach ($option as $name => $values) {
             $this->app->config()->set($name, $this->app->config($name)->merge($values));
         }
         $packageManager = new PackageManager(new NullOutput());
         foreach (glob($this->app->get('path.packages') . '/*/*/composer.json') as $package) {
             $package = $this->app->package()->load($package);
             if ($package->get('type') === 'pagekit-extension' || $package->get('type') === 'pagekit-theme') {
                 $packageManager->enable($package);
             }
         }
         if (file_exists(__DIR__ . '/../install.php')) {
             require_once __DIR__ . '/../install.php';
         }
         if (!$this->config) {
             $configuration = new Config();
             $configuration->set('application.debug', false);
             foreach ($config as $key => $value) {
                 $configuration->set($key, $value);
             }
             $configuration->set('system.secret', $this->app->get('auth.random')->generateString(64));
             if (!file_put_contents($this->configFile, $configuration->dump())) {
                 $status = 'write-failed';
                 $this->app->abort(400, __('Can\'t write config.'));
             }
         }
         $this->app->module('system/cache')->clearCache();
         $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];
 }