Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
malte-christian committed Mar 30, 2016
2 parents 3d1882b + 9729f09 commit 453bc0e
Show file tree
Hide file tree
Showing 111 changed files with 444 additions and 276 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Changelog

## 0.11.0 (March 29 2016)
## 0.11.0 (March 30, 2016)

### Added
- Added OpenGraph and Twitter Cards
- Added CLI command to setup Pagekit installation
- Added redirect after login to user settings
- Added view.init event
- Added global params object to view
Expand All @@ -28,7 +29,7 @@
- Fixed password reset link
- Fixed canonical links

## 0.10.4 (March 1 2016)
## 0.10.4 (March 1, 2016)

### Added
- Added filter cache for lists and searches
Expand Down Expand Up @@ -67,7 +68,7 @@
- Fixed package upload zip verification
- Fixed single quote issue by using RFC4627-compliant JSON within embedded script tags (#551)

## 0.10.3 (February 19 2016)
## 0.10.3 (February 19, 2016)

### Changed
- Increased package installation speed by disabling usage of Packagist repository (Pagekit API now provides a subset of required Packagist dependencies)
Expand Down
103 changes: 103 additions & 0 deletions app/console/src/Commands/SetupCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace Pagekit\Console\Commands;

use Pagekit\Application\Console\Command;
use Pagekit\Installer\Installer;
use Pagekit\Application as App;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Pagekit\Module\Loader\ConfigLoader;


class SetupCommand extends Command
{
/**
* {@inheritdoc}
*/
protected $name = 'setup';

/**
* {@inheritdoc}
*/
protected $description = 'Setup a Pagekit installation.';

/**
* {@inheritdoc}
*/
protected function configure()
{
$this->addOption('adminpass', null, InputOption::VALUE_REQUIRED, 'Admin account password.');
$this->addOption('adminmail', null, InputOption::VALUE_OPTIONAL, 'Admin account email.', $default='admin@example.com');
$this->addOption('dbdriver', null, InputOption::VALUE_REQUIRED, 'DB driver (sqlite or mysql). Default: mysql', $default='mysql');
$this->addOption('dbprefix', null, InputOption::VALUE_OPTIONAL, 'DB prefix. Default: pk_', $default='pk_');
$this->addOption('dbhost', null, InputOption::VALUE_OPTIONAL, 'MySQL host.', $default='localhost');
$this->addOption('dbname', null, InputOption::VALUE_OPTIONAL, 'MySQL database name.', $default='pagekit');
$this->addOption('dbuser', null, InputOption::VALUE_OPTIONAL, 'MySQL user. Default: root', $default='root');
$this->addOption('dbpass', null, InputOption::VALUE_OPTIONAL, 'MySQL password. Default: <empty>', $default='');
$this->addOption('locale', null, InputOption::VALUE_OPTIONAL, 'Locale. Default: en_US', $default='en_US');
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {

$this->line("Setting up Pagekit installation...");

$app = $this->container;

App::module('session')->config['storage'] = 'array';

$app->boot();

$app['module']->load('installer');

$installer = new Installer($app);

$dbDriver = $this->option('dbdriver');

$config = [
'locale' => $this->option('locale'),
'database' => [
'default' => $dbDriver,
'connections' => [
$dbDriver => [
'dbname' => $this->option('dbname'),
'host' => $this->option('dbhost'),
'user' => $this->option('dbuser'),
'password' => $this->option('dbpass'),
'prefix' => $this->option('dbprefix')
]
]
]
];

$user = [
'username' => 'admin',
'password' => $this->option('adminpass'),
'email' => $this->option('adminmail'),
];

$options = [
'system' => [
'site' => ['locale' => $this->option('locale')],
'admin' => ['locale' => $this->option('locale')]
],
'system/site' => [
'title' => 'Pagekit'
]
];

$result = $installer->install($config, $options, $user);
$status = $result['status'];
$message = $result['message'];

if($status == 'success') {
$this->line("Done");
} else {
$this->error($message);
}
}
}
166 changes: 7 additions & 159 deletions app/installer/src/Controller/InstallerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,23 @@

namespace Pagekit\Installer\Controller;

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception\ConnectionException;
use Pagekit\Application as App;
use Pagekit\Config\Config;
use Pagekit\Installer\Package\PackageManager;
use Pagekit\Installer\Package\PackageScripts;
use Pagekit\Util\Arr;
use Symfony\Component\Console\Output\NullOutput;
use Pagekit\Installer\Installer;

class InstallerController
{
/**
* @var bool
* @var object
*/
protected $config;

/**
* @var string
*/
protected $configFile = 'config.php';
protected $installer;

/**
* Constructor.
*/
public function __construct()
{
if (function_exists('opcache_reset')) {
opcache_reset();
}

$this->config = file_exists($this->configFile);
$app = App::getInstance();
$this->installer = new Installer($app);
}

public function indexAction()
Expand All @@ -58,152 +43,15 @@ public function indexAction()
*/
public function checkAction($config = [])
{
$status = 'no-connection';
$message = '';

try {

try {

if (!$this->config) {
foreach ($config as $name => $values) {
if ($module = App::module($name)) {
$module->config = Arr::merge($module->config, $values);
}
}
}

App::db()->connect();

if (App::db()->getUtility()->tableExists('@system_config')) {
$status = 'tables-exist';
$message = __('Existing Pagekit installation detected. Choose different table prefix?');
} else {
$status = 'no-tables';
}

} catch (ConnectionException $e) {

if ($e->getPrevious()->getCode() == 1049) {
$this->createDatabase();
$status = 'no-tables';
} else {
throw $e;
}
}

} catch (\Exception $e) {

$message = __('Database connection failed!');

if ($e->getCode() == 1045) {
$message = __('Database access denied!');
}
}

return ['status' => $status, 'message' => $message];
return $this->installer->check($config);
}

/**
* @Request({"config": "array", "option": "array", "user": "array"})
*/
public function installAction($config = [], $option = [], $user = [])
{
$status = $this->checkAction($config);
$message = $status['message'];
$status = $status['status'];

try {

if ('no-connection' == $status) {
App::abort(400, __('No database connection.'));
}

if ('tables-exist' == $status) {
App::abort(400, $message);
}

$scripts = new PackageScripts(App::path().'/app/system/scripts.php');
$scripts->install();

App::db()->insert('@system_user', [
'name' => $user['username'],
'username' => $user['username'],
'password' => 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'] = App::version();

foreach ($option as $name => $values) {
App::config()->set($name, App::config($name)->merge($values));
}

$packageManager = new PackageManager(new NullOutput());
foreach (glob(App::get('path.packages') . '/*/*/composer.json') as $package) {
$package = 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', App::get('auth.random')->generateString(64));

if (!file_put_contents($this->configFile, $configuration->dump())) {

$status = 'write-failed';

App::abort(400, __('Can\'t write config.'));
}
}

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];
return $this->installer->install($config, $option, $user);
}

/**
* @return void
*/
protected function createDatabase()
{
$module = App::module('database');
$params = $module->config('connections')[$module->config('default')];

$name = $params['dbname'];
unset($params['dbname']);

$db = DriverManager::getConnection($params);
$db->getSchemaManager()->createDatabase($db->quoteIdentifier($name));
$db->close();
}
}
Loading

0 comments on commit 453bc0e

Please sign in to comment.