-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWordpressContentGenerate.php
174 lines (155 loc) · 5.77 KB
/
WordpressContentGenerate.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* @file
* Contains programmatic creation of Wordpress nodes for use by `drush scr`.
*/
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\user\Entity\User;
$domain_name = getenv("OPENSHIFT_DOMAIN") ?: '192.168.99.100.nip.io';
$openshift_url = getenv("OPENSHIFT_URL") ?: 'https://192.168.99.100:8443';
$example_repository = getenv("DRUPAL_EXAMPLE_REPOSITORY") ?:
'https://github.com/singularo/shepherd-example-wordpress.git';
$database_host = getenv("DB_HOST") ?: 'mysql-myproject.' . $domain_name;
$database_port = getenv("DB_PORT") ?: '31632';
// Check that required variables are actually set.
$token = trim(getenv("TOKEN"));
if (empty($token)) {
echo "To generate default configuration for development, the TOKEN variable is required to be set.\n";
echo "Export your auth TOKEN from your host with.\n";
echo "export TOKEN=some-token\n";
echo "You can then safely re-run `robo dev:drupal-content-generate`\n";
exit(1);
}
// Set deployment database config.
$db_provisioner_config = \Drupal::service('config.factory')->getEditable('shp_database_provisioner.settings');
$db_provisioner_config->set(
'host',
$database_host
);
$db_provisioner_config->set(
'port',
$database_port
);
$db_provisioner_config->save();
$openshift_config = [
'endpoint' => $openshift_url,
'token' => $token,
'namespace' => 'myproject',
'verify_tls' => FALSE,
];
$orchestration_config = \Drupal::service('config.factory')->getEditable('shp_orchestration.settings');
foreach ($openshift_config as $key => $value) {
$orchestration_config->set('connection.' . $key, $value);
}
$orchestration_config->set('selected_provider', 'openshift_orchestration_provider');
$orchestration_config->save();
// Force reload the orchestration plugin to clear the static cache.
Drupal::service('plugin.manager.orchestration_provider')->getProviderInstance(TRUE);
if (!$development = taxonomy_term_load_multiple_by_name('Dev', 'shp_environment_types')) {
$development_env = Term::create([
'vid' => 'shp_environment_types',
'name' => 'Dev',
'field_shp_base_domain' => $domain_name,
]);
$development_env->save();
$production_env = Term::create([
'vid' => 'shp_environment_types',
'name' => 'Prd',
'field_shp_base_domain' => $domain_name,
'field_shp_protect' => TRUE,
'field_shp_update_go_live' => TRUE,
]);
$production_env->save();
}
else {
$development_env = reset($development);
echo "Taxonomy already setup.\n";
}
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties(['title' => 'Wordpress example']);
if (!$project = reset($nodes)) {
$project = Node::create([
'type' => 'shp_project',
'langcode' => 'en',
'uid' => '1',
'status' => 1,
'title' => 'Wordpress example',
'field_shp_git_repository' => [['value' => $example_repository]],
'field_shp_builder_image' => [['value' => 'uofa/s2i-shepherd-wordpress']],
'field_shp_build_secret' => [['value' => 'build-key']],
'field_shp_env_vars' => [
['key' => 'PUBLIC_DIR', 'value' => '/shared/public'],
],
]);
$project->save();
}
else {
echo "Project already setup.\n";
}
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties(['title' => 'Wordpress test site']);
if (!$site = reset($nodes)) {
$site = Node::create([
'type' => 'shp_site',
'langcode' => 'en',
'uid' => '1',
'status' => 1,
'title' => 'Wordpress test Site',
'field_shp_namespace' => 'myproject',
'field_shp_short_name' => 'wordpress-test',
'field_shp_domain' => 'wordpress-test-live.' . $domain_name,
'field_shp_git_default_ref' => 'master',
'field_shp_path' => '/',
'field_shp_project' => [['target_id' => $project->id()]],
]);
$site->moderation_state->value = 'published';
$site->save();
}
else {
echo "Site already setup.\n";
}
$ndoes = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties(['title' => 'wordpress-test-development.' . $domain_name]);
if (!$env = reset($nodes)) {
$env = Node::create([
'type' => 'shp_environment',
'langcode' => 'en',
'uid' => '1',
'status' => 1,
'title' => 'Wordpress test environment',
'field_shp_domain' => 'wordpress-test-development.' . $domain_name,
'field_shp_path' => $site->field_shp_path->value,
'field_shp_environment_type' => [['target_id' => $development_env->id()]],
'field_shp_git_reference' => 'master',
'field_shp_site' => [['target_id' => $site->id()]],
'field_shp_update_on_image_change' => TRUE,
'field_shp_cron_suspended' => 1,
'field_shp_cron_jobs' => [],
'field_cache_backend' => [
'plugin_id' => 'redis',
],
]);
$env->moderation_state->value = 'published';
$env->save();
}
else {
echo "Environment already setup.\n";
}
$oc_user_result = \Drupal::entityTypeManager()->getStorage('user')->loadByProperties(['name' => 'oc']);
/** @var \Drupal\user\Entity\User $oc_user */
$oc_user = $oc_user_result ? reset($oc_user_result) : FALSE;
if (!$oc_user) {
$oc_user = User::create([
'name' => 'oc',
'pass' => 'password',
'status' => 1,
]);
$oc_user->save();
}
/** @var \Drupal\group\Entity\GroupInterface $project_group */
$project_group = \Drupal::service('shp_content_types.group_manager')->load($project);
$project_group->addMember($oc_user, ['group_roles' => ['shp_project-online-consulta']]);