-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSiteCloneCustomTrait.php.default
136 lines (104 loc) · 5.1 KB
/
SiteCloneCustomTrait.php.default
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespace SiteClone\Custom;
trait SiteCloneCustomTrait {
// Use this file to add custom code. See README.md for details.
/*
//// The following functions are EXAMPLES and may need to be edited before they work for your use case. ////
public function transformContent_001(\Terminus\Models\Site $site, $environment, $assoc_args) {
// This is NOT a foolproof way to disable mail on your site!
// http://drupal.stackexchange.com/questions/38255/how-can-i-stop-drupal-from-sending-e-mails-of-any-kind
$this->log()
->info("Removing user emails in target environment {env}.", ['env' => $environment]);
// Now there's no way a user could get an auto-generated email.
$result = $this->doFrameworkCommand($site, $environment, "drush sqlq \"update users set mail = '' where uid <> 0\"");
if ($result['exit_code'] != 0) {
$this->log()
->error("Failed to remove user emails in target environment {env}.", ['env' => $environment]);
return FALSE;
}
}
public function transformContent_002(\Terminus\Models\Site $site, $environment, $assoc_args) {
// This is NOT a foolproof way to disable mail on your site!
// http://drupal.stackexchange.com/questions/38255/how-can-i-stop-drupal-from-sending-e-mails-of-any-kind
$this->log()
->info("Disabling smtp_host in target environment {env}.", ['env' => $environment]);
// smtp_host is used by smtp module. lazily not checking if that module exists.
// not sure if there is a fallback to localhost smtp if smtp_host is unset or null...
$result = $this->doFrameworkCommand($site, $environment, "drush vset smtp_host 'NOEMAIL-FROM-CLONED-SITE.example.com'");
if ($result['exit_code'] != 0) {
$this->log()
->error("Failed to disable smtp_host in target environment {env}.", ['env' => $environment]);
return FALSE;
}
}
public function transformContent_003(\Terminus\Models\Site $site, $env, $assoc_args) {
// A pathologic solution.
$target_site_name = $site->get("name");
$new_paths = "http://dev-$target_site_name.pantheonsite.io/\nhttp://test-$target_site_name.pantheonsite.io/\nhttp://live-$target_site_name.pantheonsite.io/\nhttp://dev-$target_site_name.pantheonsite.io/\nhttp://test-$target_site_name.pantheonsite.io/\nhttp://live-$target_site_name.pantheonsite.io/\nhttp://$target_site_name.berkeley.edu\nhttp://$target_site_name.localhost";
// This site variable is a customization for our distro
$result = $this->doFrameworkCommand($site, $env, "drush vget ourdistro_wysiwyg_override_pathologic_paths");
if ($result['exit_code'] != 0) {
$this->log()
->error("Failed to get Pathologic paths for {site} {env}", [
'site' => $target_site_name,
'env' => $env
]);
return FALSE;
}
$old_paths = str_replace("ourdistro_wysiwyg_override_pathologic_paths: ", "", $result['output']);
$old_paths = str_replace('"', '', $old_paths);
// some sites have crufty data. attempt to clean it up.
$old_paths = str_replace('\nhttp', "\nhttp", $old_paths);
$old_paths = str_replace('\r\nhttp', "\nhttp", $old_paths);
//$old_paths = str_replace("\r\nhttp", "\nhttp", $old_paths);
// prepend new paths to old with new line.
$paths = "$new_paths\n$old_paths";
$result = [];
$result = $this->doFrameworkCommand($site, $env, "drush vset ourdistro_wysiwyg_override_pathologic_paths '$paths'");
if ($result['exit_code'] != 0) {
$this->log()
->error("Failed to set Pathologic paths for {site} {env}", [
'site' => $target_site_name,
'env' => $env
]);
return FALSE;
}
public function transformCode_001(\Terminus\Models\Site $site, $env, $assoc_args) {
$site_name = $site->get('name');
$clone_path = $this->clone_path . DIRECTORY_SEPARATOR . $site_name;
$path_to_settings_dns = $clone_path . DIRECTORY_SEPARATOR . "sites" . DIRECTORY_SEPARATOR . "default" . DIRECTORY_SEPARATOR . "settings.php";
$this->log()
->info("{function}: Correct settings_dns.php", [
'function' => __FUNCTION__,
]);
if (!is_file($path_to_settings_dns) || !is_readable($path_to_settings_dns)) {
$this->log()
->error("{function}: Doesn't exist or not readable: {file}", [
'function' => __FUNCTION__,
'file' => $path_to_settings_dns
]);
return FALSE;
}
$replacement = "\$conf['special_thing'] = 'unspecial'";
$data = file_get_contents($path_to_settings_dns);
$new_code = preg_replace("/\$conf['special_thing'] = [^;]+/", $replacement, $data);
if (!file_put_contents($path_to_settings_dns, $new_code)) {
$this->log()
->error("{function}: Failed to write to {file}", [
'function' => __FUNCTION__,
'file' => $path_to_settings_dns
]);
return FALSE;
}
if (!$this->gitAddCommitPush($clone_path, "Revised settings.php for cloned site.")) {
$this->log()
->error("{function}: Failed commit new {file}.", [
'function' => __FUNCTION__,
'file' => $path_to_settings_dns
]);
return FALSE;
}
return TRUE;
}
*/
}