-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrewrite-base64-instructions-in-assignments.php
More file actions
41 lines (36 loc) · 1.12 KB
/
rewrite-base64-instructions-in-assignments.php
File metadata and controls
41 lines (36 loc) · 1.12 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
<?php
$conn = new mysqli('10.4.100.105', 'sakai28_client', 'password', 'sakai28_client');
if (!$conn->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
}
$res = $conn->query("SELECT * FROM ASSIGNMENT_CONTENT");
while ($row = $res->fetch_object()) {
$oldb64 = null;
$newb64 = null;
$xml = simplexml_load_string($row->XML);
if (!$xml) {
var_dump($row);die();
}
foreach ($xml->attributes() AS $k => $v) {
if (strpos($k, 'instructions') !== FALSE) {
$oldb64 = $v;
$d = base64_decode($v);
if (strpos ($d, 'sakai.oldhost.com')) {
$r = str_replace ('sakai.oldhost.com', 'sakai.client.com', $d);
$newb64 = base64_encode($r);
}
}
}
if ($newb64) {
$newxml = str_replace ($oldb64, $newb64, $row->XML);
$stmt = $conn->prepare("UPDATE ASSIGNMENT_CONTENT set XML=? WHERE CONTENT_ID=?");
$stmt->bind_param('ss', $newxml, $row->CONTENT_ID);
if ($result = $stmt->execute()){
echo "success: " . $row->CONTENT_ID . "\n";
$stmt->free_result();
}
else {
echo "error: " . $row->CONTENT_ID . "\n";
}
}
}