-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
285 lines (253 loc) · 9.04 KB
/
functions.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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php
date_default_timezone_set('America/Indiana/Indianapolis'); # Set timezone to make sure everything is accurate.
function loadPotato($xml)
{
$PotatoXML = simplexml_load_file($xml);
$timeLine = array();
foreach ($PotatoXML->timeline->segment as $segment) {
$timeLine[] = new Segment($segment->team, $segment->step, $segment->startDate, $segment->endDate, $segment->notes);
}
return new Potato($PotatoXML->name, $PotatoXML->status, $PotatoXML->startDate,
$PotatoXML->goalLaunchDate, $timeLine, $PotatoXML->done, $PotatoXML->office, $PotatoXML->targetEnvironment, $PotatoXML->applications);
}
function getCurrentPotato($potatoName, $potatoes)
{
foreach ($potatoes as $potato) {
if ($potato->name == "$potatoName") {
return $potato;
}
}
}
function getPotatoes()
{
$releaseDirectoryScan = array_diff(scandir(RELEASEDIRECTORY), array('..', '.'));
foreach ($releaseDirectoryScan as $file) {
$potatoes[] = loadPotato("potatoes/" . $file);
}
return $potatoes;
}
function getActivePotatoes($potatoes)
{
$activePotatoes = array();
foreach ($potatoes as $potato) {
if ($potato->done == "no") {
$activePotatoes[] = $potato;
}
}
return $activePotatoes;
}
function getInactivePotatoes($potatoes)
{
$inactivePotatoes = array();
foreach ($potatoes as $potato) {
if ($potato->done == "yes") {
$inactivePotatoes[] = $potato;
}
}
return $inactivePotatoes;
}
function getSelectedPotato($activePotatoes)
{
if (isset($_GET['selectedPotato'])) {
return getCurrentPotato($_GET['selectedPotato'], $activePotatoes);
} else {
return false;
}
}
function loadSteps($xml)
{
$stepXML = simplexml_load_file($xml);
foreach ($stepXML->step as $step) {
foreach ($step->tasks->task as $task) {
$taskList[] = new Task($task->description, $task->url);
}
$stepArray[] = new Step($step->id, $step->name, $taskList);
}
return $stepArray;
}
function getFullDescription($number)
{
if ($number == "1") {
return '1. Release Manager Provides Pull Request List';
} else if ($number == "2") {
return '2. Build & Release Pulling/Merging';
} else if ($number == "P") {
return '(Optional) B & R Pending Approval from RM';
} else if ($number == "3") {
return '3. Build & Release Building Package';
} else if ($number == "4") {
return '4. SiteOps Deploying Package';
} else if ($number == "5") {
return '5. Release Manager Notified';
} else if ($number == "6") {
return '6. QA - Ready for Testing';
} else if ($number == "T") {
return '(OPTIONAL) SiteOps troubleshooting QA Issue';
} else if ($number == "7") {
return '7. SiteOps Given Greenlight, Prodstaging';
} else if ($number == "8") {
return '8. SiteOps Prodstage Complete, WAITING';
} else if ($number == "9") {
return '9. SiteOps Deploying Package';
} else if ($number == "10") {
return '10. DONE';
}
}
function generateEmail($potato, $template, $to)
{
$message = file_get_contents("templates/" . $template . ".html");
$XML = simplexml_load_file("templates/" . $template . ".html");
$subject = (string)$XML->head->title;
$message = populateData($potato, $message);
$subject = populateData($potato, $subject);
$smtpserver = 'alemail.angieslist.com';
$port = 25;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: Release Notifier <[email protected]>' . "\r\n";
ini_set('SMTP', $smtpserver);
ini_set('smtp_port', $port);
$wordwrappedmessage = wordwrap($message, 70);
$success = mail($to, $subject, $wordwrappedmessage, $headers);
}
// Populates string with information from Potato
function populateData($potato, $string)
{
$string = str_replace("%RELEASENAME%", $potato->name, $string);
$string = str_replace("%TEAMHOLDING%", $potato->getTeamHolding(), $string);
$string = str_replace("%NOTES%", $potato->getLastSegment()->notes, $string);
return $string;
}
function getInformation($potato)
{
$XML = simplexml_load_file("templates/" . $potato->step . ".html");
print_r($XML);
}
function getStep($step)
{
switch ($step) {
case 1:
echo "1. Release Manager Provides Pull Request List";
break;
case 2:
echo '2. Build & Release Pulling/Merging';
break;
case 'P':
echo '(Optional) B & R Pending Approval from RM';
break;
case 3:
echo '3. Build & Release Building Package';
break;
case 4:
echo '4. SiteOps Deploying Package';
break;
case 5:
echo '5. Release Manager Notified';
break;
case 6:
echo '6. QA - Ready for Testing';
break;
case 'T':
echo '(OPTIONAL) SiteOps troubleshooting QA Issue';
break;
case 7:
echo '7. SiteOps Given Greenlight, Prodstaging';
break;
case 8:
echo '8. SiteOps Prodstage Complete, WAITING';
break;
case 9:
echo '9. SiteOps Deploying Package';
break;
case 10:
echo '10. DONE';
break;
}
}
function timeDifference($firstDate, $secondDate)
{
$firstDateExplode = explode(",", $firstDate);
$secondDateExplode = explode(",", $secondDate);
$firstDate1 = strtotime($firstDateExplode[1]);
$secondDate1 = strtotime($secondDateExplode[1]);
$timePassed = $firstDate1 - $secondDate1;
return $timePassed;
}
function roundTime($seconds)
{
$t = round($seconds);
return sprintf('%02d:%02d:%02d', ($t / 3600), ($t / 60 % 60), $t % 60);
}
function secondsToTime($seconds)
{
$dtF = new DateTime('UTC');
$dtT = clone $dtF;
$dtT->modify("+$seconds seconds");
return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');
}
function savePotato($potato)
{
$selectedPotatoFileName = "potatoes/potato-" . $potato->name . ".xml";
$donePotatoFileName = "potatoes/potato-" . $potato->name . "-DONE.xml";
if ($potato->done == "yes") {
rename($selectedPotatoFileName, $donePotatoFileName);
echo "THIS RELEASE HAS BEEN COMPLETED, REDIRECTING TO MAIN INDEX in 5 SECONDS!";
$selectedPotatoFileName = $donePotatoFileName;
}
$writer = new XMLWriter();
$writer->openURI($selectedPotatoFileName);
$writer->setIndent(true);
$writer->setIndentString(" ");
$writer->startElement('xml');
$writer->writeElement('name', $potato->name);
$writer->writeElement('startDate', $potato->startDate);
$writer->writeElement('goalLaunchDate', $potato->goalLaunchDate);
$writer->writeElement('done', $potato->done);
$writer->writeElement('status', $potato->status);
$writer->writeElement('office', $potato->office);
$writer->writeElement('targetEnvironment', $potato->targetEnvironment);
$writer->writeElement('applications', $potato->applications);
$writer->startElement('timeline');
foreach ($potato->timeLine as $Segment) {
$writer->startElement('segment');
$writer->writeElement('team', $Segment->team);
$writer->writeElement('step', $Segment->step);
$writer->writeElement('startDate', $Segment->startDate);
$writer->writeElement('endDate', $Segment->endDate);
$writer->writeElement('notes', $Segment->notes);
$writer->endElement();
}
$writer->endElement();
$writer->endElement();
$writer->endDocument();
$writer->flush();
}
function processPOST($POST, $selectedPotato)
{
if (!empty($POST['submit'])) {
if ($POST['page'] == 'index') {
$TheLastSegment = $selectedPotato->getLastSegment();
$TheLastSegment->endDate = CURRENTDATE;
$SegmentObj = new Segment($POST['Team'], $POST['Step'], CURRENTDATE, 'N/A', $POST['notes']);
$CurrentTeam = $_POST['Team'];
$selectedPotato->timeLine[] = $SegmentObj;
generateEmail($selectedPotato, ("Step-" . $POST['Step']), '[email protected]');
# If Potato on last step, complete it!
if ($POST['Step'] == "10") {
$selectedPotato->done = TRUE;
}
} else if ($POST['page'] == 'create') {
$timeLine[] = new Segment('BuildAndRelease', '1', CURRENTDATE, 'N/A', 'Package Created');
$dateExplode = explode("/", $POST['date']);
$goalLaunchDate = date('l, m/d/Y g:i:s a', mktime(23, 59, 0, $dateExplode[0], $dateExplode[1], $dateExplode[2]));
$selectedPotato = new Potato($POST['name'], 'cold', date('l, m/d/Y g:i:s a'),
$goalLaunchDate, $timeLine, 'no', $POST['office'], $POST['targetEnvironment'], 'noapps');
}
# Save Potato
savePotato($selectedPotato);
}
return $selectedPotato;
}
?>