deployer/recipe/drupal7.php

88 lines
2.2 KiB
PHP
Raw Normal View History

2015-07-15 19:38:50 +02:00
<?php
/* (c) Sergio Carracedo <info@sergiocarraedo.es>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2015-07-15 19:38:50 +02:00
2016-01-11 14:00:45 +07:00
namespace Deployer;
require_once __DIR__ . '/common.php';
2015-07-15 19:38:50 +02:00
taskGroup('deploy', [
2015-07-15 19:57:41 +02:00
'deploy:prepare',
2015-07-15 19:38:50 +02:00
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:symlink',
'cleanup'
]);
2015-07-15 19:38:50 +02:00
//Set Drupal 7 site. Change if you use different site
env('drupal_site', 'default');
2015-07-15 19:38:50 +02:00
//Drupal 7 shared dirs
set('shared_dirs', [
2015-07-15 19:38:50 +02:00
'sites/{{drupal_site}}/files',
]);
2015-07-15 19:38:50 +02:00
//Drupal 7 shared files
set('shared_files', [
2015-07-15 19:38:50 +02:00
'sites/{{drupal_site}}/settings.php',
]);
2015-07-15 19:38:50 +02:00
//Drupal 7 writable dirs
set('writable_dirs', [
2015-07-15 19:57:41 +02:00
'sites/{{drupal_site}}/files',
]);
2015-07-15 19:38:50 +02:00
//Create and upload Drupal 7 settings.php using values from secrets
task('drupal:settings', function () {
2015-07-15 19:38:50 +02:00
if (askConfirmation('Are you sure to generate and upload settings.php file?')) {
$basepath = dirname(__FILE__) . '/drupal7';
//Import secrets
$secrets = env('settings');
//Prepare replacement variables
2016-01-11 14:36:42 +07:00
$iterator = new \RecursiveIteratorIterator(
new \RecursiveArrayIterator($secrets)
);
2015-07-15 19:38:50 +02:00
2015-07-15 19:57:41 +02:00
$replacements = [];
foreach ($iterator as $key => $value) {
$keys = [];
for ($i = $iterator->getDepth(); $i > 0; $i --) {
$keys[] = $iterator->getSubIterator($i - 1)->key();
}
$keys[] = $key;
2015-07-15 19:38:50 +02:00
2015-07-15 19:57:41 +02:00
$replacements['{{' . implode('.', $keys) . '}}'] = $value;
}
2015-07-15 19:38:50 +02:00
//Create settings from template
$settings = file_get_contents($basepath . '/settings.php');
2015-07-15 19:38:50 +02:00
2015-07-15 19:57:41 +02:00
$settings = strtr($settings, $replacements);
2015-07-15 19:38:50 +02:00
2015-07-15 19:57:41 +02:00
writeln('settings.php created succesfuly');
2015-07-15 19:38:50 +02:00
2015-07-15 19:57:41 +02:00
$tmpFilename = tempnam($basepath, 'tmp_settings_');
file_put_contents($tmpFilename, $settings);
upload($tmpFilename, '{{deploy_path}}/shared/sites/{{drupal_site}}/settings.php');
2015-07-15 19:38:50 +02:00
2015-07-15 19:57:41 +02:00
unlink($tmpFilename);
2015-07-15 19:38:50 +02:00
}
});
2015-07-15 19:38:50 +02:00
//Upload Drupal 7 files folder
task('drupal:upload_files', function () {
2015-07-15 19:38:50 +02:00
if (askConfirmation('Are you sure?')) {
upload('sites/{{drupal_site}}/files', '{{deploy_path}}/shared/sites/{{drupal_site}}/files');
2015-07-15 19:38:50 +02:00
}
});