2011-11-24 02:15:37 +01:00
< ? php
class Mage_Task_Add
{
2012-01-08 22:11:36 +01:00
public function environment ( $environmentName , $withRelases = false )
2011-11-24 02:15:37 +01:00
{
$environmentName = strtolower ( $environmentName );
2012-02-12 15:43:09 +01:00
$environmentConfigFile = '.mage/config/environment/' . $environmentName . '.yml' ;
2011-11-24 02:15:37 +01:00
Mage_Console :: output ( 'Adding new environment: <dark_gray>' . $environmentName . '</dark_gray>' );
// Check if there is already an environment with the same name
if ( file_exists ( $environmentConfigFile )) {
2011-11-24 02:45:04 +01:00
Mage_Console :: output ( '<light_red>Error!!</light_red> Already exists an environment called <dark_gray>' . $environmentName . '</dark_gray>' , 1 , 2 );
2011-11-24 02:15:37 +01:00
} else {
2012-01-08 22:11:36 +01:00
$releasesConfig = 'releases:' . PHP_EOL
. ' enabled: true' . PHP_EOL
. ' symlink: current' . PHP_EOL
. ' directory: releases' . PHP_EOL ;
2011-11-24 02:15:37 +01:00
$baseConfig = '#' . $environmentName . PHP_EOL
2012-01-08 22:11:36 +01:00
. 'deployment:' . PHP_EOL
2011-11-28 03:41:53 +01:00
. ' user: dummy' . PHP_EOL
. ' from: ./' . PHP_EOL
. ' to: /var/www/vhosts/example.com/www' . PHP_EOL
. ' excludes:' . PHP_EOL
2012-01-08 22:11:36 +01:00
. ( $withRelases ? $releasesConfig : '' )
2011-11-24 02:15:37 +01:00
. 'hosts:' . PHP_EOL
2011-11-28 03:41:53 +01:00
. 'tasks:'
. ' pre-deploy:' . PHP_EOL
. ' on-deploy:' . PHP_EOL
. ' - deployment/rsync' . PHP_EOL
. ' post-deploy:' . PHP_EOL ;
2011-11-24 02:15:37 +01:00
$result = file_put_contents ( $environmentConfigFile , $baseConfig );
if ( $result ) {
Mage_Console :: output ( '<light_green>Success!!</light_green> Environment config file for <dark_gray>' . $environmentName . '</dark_gray> created successfully at <blue>' . $environmentConfigFile . '</blue>' );
2011-11-24 02:45:04 +01:00
Mage_Console :: output ( '<dark_gray>So please! Review and adjust its configuration.</dark_gray>' , 2 , 2 );
2011-11-24 02:15:37 +01:00
} else {
2011-11-24 02:45:04 +01:00
Mage_Console :: output ( '<light_red>Error!!</light_red> Unable to create config file for environment called <dark_gray>' . $environmentName . '</dark_gray>' , 1 , 2 );
2011-11-24 02:15:37 +01:00
}
}
}
}