mirror of
https://github.com/deployphp/deployer.git
synced 2025-02-23 00:32:25 +01:00
* Change drupal:settings task to drupal:configure * Drupal 7 recipe - Set template file path * Changelog
91 lines
2.3 KiB
PHP
91 lines
2.3 KiB
PHP
<?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.
|
|
*/
|
|
|
|
namespace Deployer;
|
|
|
|
require_once __DIR__ . '/common.php';
|
|
|
|
task('deploy', [
|
|
'deploy:info',
|
|
'deploy:prepare',
|
|
'deploy:lock',
|
|
'deploy:release',
|
|
'deploy:update_code',
|
|
'deploy:shared',
|
|
'deploy:symlink',
|
|
'deploy:unlock',
|
|
'cleanup'
|
|
]);
|
|
|
|
//Set Drupal 7 site. Change if you use different site
|
|
set('drupal_site', 'default');
|
|
|
|
//Drupal 7 shared dirs
|
|
set('shared_dirs', [
|
|
'sites/{{drupal_site}}/files',
|
|
]);
|
|
|
|
//Drupal 7 shared files
|
|
set('shared_files', [
|
|
'sites/{{drupal_site}}/settings.php',
|
|
]);
|
|
|
|
//Drupal 7 writable dirs
|
|
set('writable_dirs', [
|
|
'sites/{{drupal_site}}/files',
|
|
]);
|
|
|
|
|
|
//Create and upload Drupal 7 settings.php using values from secrets
|
|
task('drupal:settings', function () {
|
|
if (askConfirmation('Are you sure to generate and upload settings.php file?')) {
|
|
|
|
//Get template
|
|
$template = get('settings_template');
|
|
|
|
//Import secrets
|
|
$secrets = get('settings');
|
|
|
|
//Prepare replacement variables
|
|
$iterator = new \RecursiveIteratorIterator(
|
|
new \RecursiveArrayIterator($secrets)
|
|
);
|
|
|
|
$replacements = [];
|
|
foreach ($iterator as $key => $value) {
|
|
$keys = [];
|
|
for ($i = $iterator->getDepth(); $i > 0; $i --) {
|
|
$keys[] = $iterator->getSubIterator($i - 1)->key();
|
|
}
|
|
$keys[] = $key;
|
|
|
|
$replacements['{{' . implode('.', $keys) . '}}'] = $value;
|
|
}
|
|
|
|
//Create settings from template
|
|
$settings = file_get_contents($template);
|
|
|
|
$settings = strtr($settings, $replacements);
|
|
|
|
writeln('settings.php created succesfuly');
|
|
|
|
$tmpFilename = tempnam(sys_get_temp_dir(), 'tmp_settings_');
|
|
file_put_contents($tmpFilename, $settings);
|
|
|
|
upload($tmpFilename, '{{deploy_path}}/shared/sites/{{drupal_site}}/settings.php');
|
|
|
|
unlink($tmpFilename);
|
|
}
|
|
});
|
|
|
|
//Upload Drupal 7 files folder
|
|
task('drupal:upload_files', function () {
|
|
if (askConfirmation('Are you sure?')) {
|
|
upload('sites/{{drupal_site}}/files', '{{deploy_path}}/shared/sites/{{drupal_site}}/files');
|
|
}
|
|
});
|