forked from deployphp/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrupal7.php
79 lines (58 loc) · 1.98 KB
/
drupal7.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Deployer;
require_once __DIR__ . '/common.php';
add('recipes', ['drupal7']);
task('deploy', [
'deploy:prepare',
'deploy:publish',
]);
//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 successfully');
$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');
}
});