-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateSite.php
More file actions
212 lines (193 loc) · 5.52 KB
/
createSite.php
File metadata and controls
212 lines (193 loc) · 5.52 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
require_once __DIR__ . '/vendor/autoload.php';
use BaseKit\Api\ClientFactory;
use RandomLib\Factory;
$dotenv = Dotenv\Dotenv::createMutable(__DIR__);
$dotenv->load();
$client = ClientFactory::create(
[
'base_uri' => $_ENV['REST_API_URL'],
'username' => $_ENV['REST_API_USERNAME'],
'password' => $_ENV['REST_API_PASSWORD'],
],
);
echo "Creating account and site\n";
$generator = (new Factory)->getMediumStrengthGenerator();
$password = $generator->generateString(15);
$username = 'user' . time();
$createAccountHolder = $client->getCommand(
'CreateUser',
[
'brandRef' => 1,
'firstName' => 'first',
'lastName' => 'lastname',
'username' => $username,
'email' => $username . '@example.com',
'password' => $password,
'languageCode' => 'en',
'entryFlowComplete' => 1, //This skips site onboarding which would reset all site content on first login
]
);
$response = $client->execute($createAccountHolder);
// accountHolderRef and userId/Ref are used interchangeably in our documentation and api endpoints
$accountHolderRef = $response['response']['accountHolder']['ref'];
echo " Created account holder $accountHolderRef\n";
$createPackage = $client->getCommand(
'AddPackage',
[
'billingFrequency' => 1,
'packageRef' => 19,
'userRef' => $accountHolderRef,
]
);
$response = $client->execute($createPackage);
echo " Added package to account holder\n";
$createSite = $client->getCommand(
'CreateSite',
[
'accountHolderRef' => $accountHolderRef,
'brandRef' => 1,
'domain' => "$username.dev.basekit.technology",
'siteType' => 'responsive',
]
);
$response = $client->execute($createSite);
$siteRef = $response['response']['site']['ref'];
echo " Created site $siteRef\n";
$getProfiles = $client->getCommand(
'GetUsersProfiles',
[
'userRef' => $accountHolderRef,
]
);
$response = $client->execute($getProfiles);
$profileRef = $response['response']['profiles'][0]['ref'];
$fields = [
[
'name' => 'business',
'value' => 'The Coffee Hut',
],
[
'name' => 'strapline',
'value' => 'Serving the best coffee across Bristol',
],
];
$updateProfile = $client->getCommand(
'UpdateProfile',
[
'userRef' => $accountHolderRef,
'profileRef' => $profileRef,
'fields' => $fields,
]
);
$response = $client->execute($updateProfile);
$getPages = $client->getCommand(
'GetSitesPages',
[
'siteRef' => $siteRef,
],
);
$response = $client->execute($getPages);
$pageRef = $response['response']['pages'][0]['ref'];
echo " Found home page ref $pageRef\n";
$getSections = $client->getCommand(
'GetSections',
[
'siteRef' => $siteRef,
'pageRef' => $pageRef,
],
);
$response = $client->execute($getSections);
$sections = $response['response']['sections'];
//Delete the default sections from home page
foreach($sections as $section) {
$deleteSection = $client->getCommand(
'DeleteSection',
[
'siteRef' => $siteRef,
'pageRef' => $pageRef,
'sectionRef' => $section['ref'],
]
);
$response = $client->execute($deleteSection);
}
//Add the image_text_2a section
echo " Adding section image_text_2a\n";
$addSection = $client->getCommand(
'AddSection',
[
'siteRef' => $siteRef,
'pageRef' => $pageRef,
'template' => 'image_text_2a',
],
);
$response = $client->execute($addSection)['response']['section'];
$sectionRef = $response['ref'];
$widgetsAdded = $response['widgets'];
//Upload an image for use in the new section
$getUploadToken = $client->getCommand(
'CreateUploadToken',
[
'userRef' => $accountHolderRef,
]
);
$response = $client->execute($getUploadToken);
$uploadToken = $response['response']['token'];
echo " Got upload token $uploadToken\n";
$file = fopen('./press.jpeg', 'r');
$uploadAsset = $client->getCommand(
'CreateAsset',
[
'userRef' => $accountHolderRef,
'siteRef' => $siteRef,
'token' => $uploadToken,
'file' => $file,
]
);
$response = $client->execute($uploadAsset);
$url = $response['response']['result']['url'];
echo " Got new asset url $url\n";
//Update the widget text & images in the newly added section
foreach ($widgetsAdded as $widgetAdded) {
echo " Updating widget ref {$widgetAdded['ref']}\n";
$updateSectionWidget = $client->getCommand(
'UpdateSectionWidget',
[
'siteRef' => $siteRef,
'pageRef' => $pageRef,
'sectionRef' => $sectionRef,
'widgetRef' => $widgetAdded['ref'],
'headingContent' => 'My New Widget Content',
'imageSrc' => $url,
],
);
$client->execute($updateSectionWidget);
}
//Add a contact_3a section above the first section we added
echo " Adding section contact_3a\n";
$addSection = $client->getCommand(
'AddSection',
[
'siteRef' => $siteRef,
'pageRef' => $pageRef,
'template' => 'contact_3a',
'siblingRef' => $sectionRef,
'position' => 'above',
],
);
$client->execute($addSection);
echo " Adding a new page\n";
$addPage = $client->getCommand(
'CreateSitePage',
[
'siteRef' => $siteRef,
'pageUrl' => 'about',
'type' => 'page',
'title' => 'About Us',
'status' => 'active',
'menu' => 1,
'seo_title' => 'About Us',
],
);
$response = $client->execute($addPage);
echo "Done\n";