deployer/recipe/drupal7.php

92 lines
2.3 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
task('deploy', [
2017-08-12 12:01:27 +03:00
'deploy:info',
2015-07-15 19:57:41 +02:00
'deploy:prepare',
2016-11-05 12:56:53 +07:00
'deploy:lock',
2015-07-15 19:38:50 +02:00
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:writable',
2015-07-15 19:38:50 +02:00
'deploy:symlink',
2016-11-05 12:56:53 +07:00
'deploy:unlock',
2015-07-15 19:38:50 +02:00
'cleanup'
]);
2015-07-15 19:38:50 +02:00
//Set Drupal 7 site. Change if you use different site
2016-11-05 17:50:18 +07:00
set('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?')) {
//Get template
$template = get('settings_template');
//Import secrets
2016-11-05 17:50:18 +07:00
$secrets = get('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($template);
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
2020-04-24 14:53:23 +02:00
writeln('settings.php created successfully');
2015-07-15 19:38:50 +02:00
$tmpFilename = tempnam(sys_get_temp_dir(), 'tmp_settings_');
2015-07-15 19:57:41 +02:00
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
}
});