Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Refactor Installation #2604

Closed
wants to merge 12 commits into from
30 changes: 30 additions & 0 deletions .travis.yml
@@ -0,0 +1,30 @@
language: php
sudo: false

php:
- '5.5'
- '5.6'
- '7.0'
- 'hhvm'

matrix:
allow_failures:
- php: hhvm

services:
- mysql

install:
- composer install -o --no-interaction

before_script:
- mysql -e 'create database symphony_test;'

script:
- symphony/conductor install test/travis_ci_config.php --override --no-interaction -vvv
- ./vendor/bin/phpcs --colors --extensions=php symphony/ install/


cache:
directories:
- $HOME/.composer/cache
2 changes: 1 addition & 1 deletion README.markdown
Expand Up @@ -37,7 +37,7 @@ Useful places:

## Server requirements

- PHP 5.6 or above
- PHP 5.5.9 or above
- PHP’s LibXML module, with the XSLT extension enabled (`--with-xsl`)
- PHP’s built in `json` functions, which are enabled by default in PHP 5.2 and above; if they are missing, ensure PHP wasn’t compiled with `--disable-json`
- [Composer](https://getcomposer.org/)
Expand Down
75 changes: 40 additions & 35 deletions composer.json
@@ -1,39 +1,44 @@
{
"name": "symphonycms/symphony-2",
"version": "3.0.0-alpha.1",
"description": "Symphony is a PHP & MySQL based CMS that utilises XML and XSLT as its core technologies.",
"homepage": "http://www.getsymphony.com",
"license": "MIT",
"authors": [
{
"name": "Symphony Team",
"email": "team@getsymphony.com"
}
"name": "symphonycms/symphony-2",
"version": "3.0.0-alpha.1",
"description": "Symphony is a PHP & MySQL based CMS that utilises XML and XSLT as its core technologies.",
"homepage": "http://www.getsymphony.com",
"license": "MIT",
"authors": [
{
"name": "Symphony Team",
"email": "team@getsymphony.com"
}
],
"support": {
"forum": "http://www.getsymphony.com/discuss/",
"issues": "https://github.com/symphonycms/symphony-2/issues",
"wiki": "https://github.com/symphonycms/symphony-2/wiki"
},
"require": {
"php": ">=5.5.9",
"ext-curl": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-pdo_mysql": "*",
"ext-xsl": "*",
"monolog/monolog": "1.*",
"symfony/console": "^3.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.6"
},
"minimum-stability": "stable",
"autoload": {
"classmap": ["symphony/content", "symphony/lib", "symphony/template"],
"files": [
"symphony/lib/boot/func.utilities.php",
"symphony/lib/boot/defines.php",
"symphony/lib/toolkit/util.validators.php"
],
"support": {
"forum": "http://www.getsymphony.com/discuss/",
"issues": "https://github.com/symphonycms/symphony-2/issues",
"wiki": "https://github.com/symphonycms/symphony-2/wiki"
},
"require": {
"php": ">=5.5",
"ext-curl": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-pdo_mysql": "*",
"ext-xsl": "*",
"monolog/monolog": "1.*"
},
"require-dev": {
"squizlabs/php_codesniffer": "2.*"
},
"minimum-stability": "stable",
"autoload": {
"classmap": ["symphony/content", "symphony/lib", "symphony/template", "install"],
"files": [
"symphony/lib/boot/func.utilities.php",
"symphony/lib/boot/defines.php",
"symphony/lib/toolkit/util.validators.php"
]
"psr-4": {
"SymphonyCms\\": "symphony/",
"SymphonyCms\\Installer\\": "install/"
}
}
}
123 changes: 121 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions install/Steps/CreateDatabase.php
@@ -0,0 +1,88 @@
<?php
namespace SymphonyCms\Installer\Steps;

use Author;
use Configuration;
use Cryptography;
use DatabaseException;
use Exception;
use Symphony;

class CreateDatabase extends DefaultStep
{
/**
* {@inheritdoc}
*/
public function handle(Configuration $config, array $data)
{
// MySQL: Establishing connection
$this->logger->info('MYSQL: Establishing Connection');

try {
Symphony::Database()->connect(
$config->get('host', 'database'),
$config->get('user', 'database'),
$config->get('password', 'database'),
$config->get('port', 'database'),
$config->get('db', 'database')
);
} catch (DatabaseException $e) {
throw new Exception(
'There was a problem while trying to establish a connection to the MySQL server. Please check your settings.'
);
}

if (Symphony::Database()->tableExists($config->get('tbl_prefix', 'database') . '%') && !$this->override) {
$this->logger->error('MYSQL: Database table prefix is already in use. Change prefix or run installation with the `--override` flag.', [
'prefix' => $config->get('tbl_prefix', 'database'),
'db' => $config->get('db', 'database')
]);

return false;
}

// MySQL: Setting prefix & importing schema
Symphony::Database()->setPrefix($config->get('tbl_prefix', 'database'));
$this->logger->info('MYSQL: Importing Table Schema');

try {
Symphony::Database()->import(file_get_contents(INSTALL . '/includes/install.sql'));
} catch (DatabaseException $e) {
throw new Exception(sprintf(
'There was an error while trying to import data to the database. MySQL returned: %s:%s',
$e->getDatabaseErrorCode(),
$e->getDatabaseErrorMessage()
));
}

// MySQL: Creating default author
if (isset($data['user'])) {
$this->logger->info('MYSQL: Creating Default Author');

try {
// Clean all the user data.
$userData = array_map([Symphony::Database(), 'cleanValue'], $data['user']);

$author = new Author;
$author->set('user_type', 'developer');
$author->set('primary', 'yes');
$author->set('username', $userData['username']);
$author->set('password', Cryptography::hash($userData['password']));
$author->set('first_name', $userData['firstname']);
$author->set('last_name', $userData['lastname']);
$author->set('email', $userData['email']);
$author->commit();
} catch (DatabaseException $e) {
throw new Exception(sprintf(
'There was an error while trying create the default author. MySQL returned: %s:%s',
$e->getDatabaseErrorCode(),
$e->getDatabaseErrorMessage()
));
}
} else {
$this->logger->info('MYSQL: Skipping Default Author creation');
}

return true;
}
}
44 changes: 44 additions & 0 deletions install/Steps/CreateHtaccess.php
@@ -0,0 +1,44 @@
<?php
namespace SymphonyCms\Installer\Steps;

use Configuration;
use Exception;
use General;

class CreateHtaccess extends DefaultStep
{
/**
* {@inheritdoc}
*/
public function handle(Configuration $config, array $data)
{
// Writing htaccess file
$this->logger->info('CONFIGURING: Apache Rewrite Rules');

if (APP_MODE === 'console') {
$rewrite_base = basename(DOCROOT);
} else {
$rewrite_base = ltrim(preg_replace('/\/install$/i', null, dirname($_SERVER['PHP_SELF'])), '/');
}

$htaccess = str_replace(
'<!-- REWRITE_BASE -->',
$rewrite_base,
file_get_contents(INSTALL . '/includes/htaccess.txt')
);

// If the step can override, replace the entire .htaccess file.
if (file_exists(DOCROOT . "/.htaccess") && $this->override) {
$this->logger->info('CONFIGURING: Replacing existing .htaccess file');
$file_mode = 'w';
} else {
$file_mode = 'a';
}

if (!General::writeFile(DOCROOT . "/.htaccess", $htaccess, $config->get('write_mode', 'file'), $file_mode)) {
throw new Exception('Could not write ‘.htaccess’ file. Check permission on ' . DOCROOT);
}

return true;
}
}