Skip to content

Commit

Permalink
[TASK] First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
langeland committed Jan 15, 2015
0 parents commit 61a917a
Show file tree
Hide file tree
Showing 10 changed files with 546 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Libraries/
41 changes: 41 additions & 0 deletions Classes/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Rosemary\Command;

class AbstractCommand extends \Symfony\Component\Console\Command\Command {

protected $configuration = array();

/**
* @var \Symfony\Component\Console\Input\InputInterface
*/
protected $input;

/**
* @var \Symfony\Component\Console\Output\OutputInterface
*/
protected $output;



public function __construct() {
parent::__construct();
$this->configuration = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__ . '/../../Configuration/Rosemary.yaml'));
}

public function output($text, array $arguments = array()) {
if ($arguments !== array()) {
$text = vsprintf($text, $arguments);
}
$this->output->write($text);
}

public function outputLine($text = '', array $arguments = array()) {
return $this->output($text . PHP_EOL, $arguments);
}

public function quit($exitCode = 0) {
die($exitCode);
}

}
251 changes: 251 additions & 0 deletions Classes/Command/CreateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
<?php

namespace Rosemary\Command;


class CreateCommand extends \Rosemary\Command\AbstractCommand {

private $installationName = NULL;

private $installationType = '';

private $installationSource = '';

public function __construct() {
parent::__construct();
}

protected function configure() {
$this
->setName('create')
->setDescription('Create blank project')
->addArgument('name', \Symfony\Component\Console\Input\InputArgument::REQUIRED, 'Set the name of the installation')
->addArgument('source', \Symfony\Component\Console\Input\InputArgument::REQUIRED, 'Set the source fof the installation. Can be a packagist package "vendor/package" or a git reposirory "[email protected]:user/vendor-package.git"');
}

protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) {
$this->input = $input;
$this->output = $output;

try {
$this->validateArgumentSource($input->getArgument('source'));
$this->validateArgumentName($input->getArgument('name'));
} catch (Exception $e) {
die('Error on validate arguments');
}

try {
$this->task_createDirectories();
$this->task_cloneSource();
$this->task_createDatabase();
$this->task_updateSettings();
$this->task_setfilepermissions();
$this->task_createVhost();
} catch (Exception $e) {

}
}
/*******************************************************************************************************************
*
******************************************************************************************************************/

/**
* @param $source
* @return bool
*/
protected function validateArgumentSource($source) {
$this->installationSource = $source;

if (preg_match('*((git|ssh|http(s)?)|(git@[\w\.]+))(:(//)?)([\w\.@\:/\-~]+)(\.git)(/)?*i', $source)) {
$this->installationType = 'git';
} else {
$this->installationType = 'composer';
}

return TRUE;
}

/**
* @param $name
* @return bool
*/
protected function validateArgumentName($name) {
$this->installationName = $name;
return TRUE;
}


/*******************************************************************************************************************
*
******************************************************************************************************************/

/**
*
*/
private function task_createDirectories() {
$this->output->writeln(vsprintf('Creating directory structure at: %s', array($this->configuration['locations']['document_root'] . strtolower($this->installationName))));

$baseDir = $this->configuration['locations']['document_root'] . strtolower($this->installationName) . '/';

if (!mkdir($baseDir, 0777)) {
$this->outputLine('Failed to create folders...');
$this->quit(1);
}

if (!mkdir($baseDir . 'logs/', 0777, TRUE)) {
$this->outputLine('Failed to create folders...');
$this->quit(1);
}

if (!mkdir($baseDir . 'sync/', 0777, TRUE)) {
$this->outputLine('Failed to create folders...');
$this->quit(1);
}

#if (!mkdir($baseDir . 'flow/Data/Logs/', 0777, TRUE)) {
# die('Failed to create folders...');
#}
}

private function task_cloneSource() {
$this->outputLine('Cloning base package');
if ($this->installationType == 'composer') {
$this->outputLine(' Running composer: php /path/to/composer.phar create-project %s %s', array(
$this->installationSource,
$this->configuration['locations']['document_root'] . $this->installationName
));

chdir($this->configuration['locations']['document_root'] . strtolower($this->installationName) . '/');
system(vsprintf(
'composer --verbose --no-progress --no-interaction --keep-vcs create-project %s flow',
array(
$this->installationSource
)
));

} else {
$this->outputLine(' Running git: git clone %s flow', array(
$this->installationSource,
));

chdir($this->configuration['locations']['document_root'] . strtolower($this->installationName) . '/');
system(vsprintf(
'git clone %s flow',
array(
$this->installationSource
)
));

chdir($this->configuration['locations']['document_root'] . strtolower($this->installationName) . '/flow/');
system(vsprintf(
'composer --verbose --no-progress --no-interaction install',
array()
));
}
}

private function task_createDatabase() {

$this->outputLine('Create database: %s', array(
strtolower($this->installationName)
));

$this->outputLine(' Running: mysql -h %s -u %s %s -e "CREATE DATABASE %s DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"', array(
$this->configuration['database_root']['host'],
$this->configuration['database_root']['username'],
($this->configuration['database_root']['password'] != '') ? '-p' . $this->configuration['database_root']['password'] : '',
strtolower($this->installationName)
));

system(vsprintf(
'mysql -h %s -u %s %s -e "DROP DATABASE IF EXISTS %s; CREATE DATABASE %s DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"',
array(
$this->configuration['database_root']['host'],
$this->configuration['database_root']['username'],
($this->configuration['database_root']['password'] != '') ? '-p' . $this->configuration['database_root']['password'] : '',
strtolower($this->installationName),
strtolower($this->installationName)
)
));
}

private function task_updateSettings() {
$this->outputLine('Updating Configuration/Settings.yaml');
$fileContent = array(
'# #',
'# Example Settings #',
'# #',
'# This file contains settings for various parts of the application. #',
'# Copy this file to Settings.yaml, and adjust as necessary. #',
'# #',
'# Please refer to the default settings file(s) or the manuals for #',
'# possible configuration options. #',
'# #',
'',
'',
'TYPO3:',
' FLOW3:',
' persistence:',
' backendOptions:',
' driver: pdo_mysql',
' host: ' . $this->configuration['database']['host'],
' dbname: ' . strtolower($this->installationName),
' user: ' . $this->configuration['database']['username'],
' password: ' . $this->configuration['database']['password'],
);
file_put_contents($this->configuration['locations']['document_root'] . $this->installationName . '/' . $this->configuration['locations']['flow_dir'] . 'Configuration/Settings.yaml', implode("\n", $fileContent));

}

private function task_setfilepermissions() {
$this->outputLine('Adjust file permissions for CLI and web server access');
$this->outputLine(
'Running: sudo ./flow flow:core:setfilepermissions %s %s %s',
array(
$this->configuration['permissions']['owner'],
$this->configuration['permissions']['group'],
$this->configuration['permissions']['group']
)
);

chdir($this->configuration['locations']['document_root'] . $this->installationName . '/' . $this->configuration['locations']['flow_dir']);
system(vsprintf(
'sudo ./flow flow:core:setfilepermissions %s %s %s',
array(
$this->configuration['permissions']['owner'],
$this->configuration['permissions']['group'],
$this->configuration['permissions']['group']
)
));
}

private function task_createVhost() {
$this->outputLine('Creating virtual host: "%s"', array($this->configuration['locations']['apache_sites'] . '20-' . strtolower($this->installationName) . '.conf'));

$fileContent = array(
'<VirtualHost *:8081>',
' ServerName ' . strtolower($this->installationName) . '.dev',
'',
' ## Vhost docroot',
' DocumentRoot "' . $this->configuration['locations']['document_root'] . $this->installationName . '/' . $this->configuration['locations']['flow_dir'] . '/Web"',
'',
' <Directory "' . $this->configuration['locations']['document_root'] . $this->installationName . '/' . $this->configuration['locations']['flow_dir'] . '/Web">',
' AllowOverride All',
' Order allow,deny',
' Allow from all',
' </Directory>',
'',
' ## Load additional static includes',
'',
' ## Logging',
' ErrorLog "' . $this->configuration['locations']['document_root'] . $this->installationName . '/logs/error.log"',
' ServerSignature Off',
' CustomLog "' . $this->configuration['locations']['document_root'] . $this->installationName . '/logs/access.log" combined',
'</VirtualHost>'
);

file_put_contents($this->configuration['locations']['apache_sites'] . '/20-' . strtolower($this->installationName) . '.conf', implode("\n", $fileContent));

}

}
34 changes: 34 additions & 0 deletions Classes/Command/DeleteCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Rosemary\Command;


class DeleteCommand extends \Rosemary\Command\AbstractCommand {

private $installationName = NULL;


public function __construct() {
parent::__construct();
}

protected function configure() {
$this
->setName('delete')
->setDescription('Delete an existing project')
->addArgument('name', \Symfony\Component\Console\Input\InputArgument::REQUIRED, 'Set the name of the installation');
}

protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) {
$this->input = $input;
$this->output = $output;


}
/*******************************************************************************************************************
*
******************************************************************************************************************/



}
32 changes: 32 additions & 0 deletions Classes/Command/SynchronizeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Rosemary\Command;


class SynchronizeCommand extends \Rosemary\Command\AbstractCommand {

private $installationName = NULL;


public function __construct() {
parent::__construct();
}

protected function configure() {
$this
->setName('sync')
->setDescription('Synchronize data from moc-files to local project')
->addArgument('name', \Symfony\Component\Console\Input\InputArgument::REQUIRED, 'Set the name of the installation');
}

protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) {
$this->input = $input;
$this->output = $output;
}
/*******************************************************************************************************************
*
******************************************************************************************************************/



}
20 changes: 20 additions & 0 deletions Configuration/Rosemary.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

locations:
document_root: /Users/langeland/temp/vanilla-test/document_root/
flow_dir: flow/
apache_sites: /Users/langeland/temp/vanilla-test/apache_sites/

database_root:
host: localhost
username: root

permissions:
file_modes: 766
owner: vagrant
group: www-data

database:
host: localhost
database: typo3_%s
username: typo3
password: joh316
Loading

0 comments on commit 61a917a

Please sign in to comment.