Subversion Repositories oidplus

Rev

Rev 261 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
190 daniel-mar 1
#!/usr/bin/php
2
<?php
3
 
511 daniel-mar 4
/*
5
 * OIDplus 2.0
6
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
 
190 daniel-mar 21
#
22
# Since OIDplus svn-184, entries in the database need to have a canonical ID
23
# If the ID is not canonical (e.g. GUIDs missing hyphens), the object cannot be opened in OIDplus
24
# This script re-canonizes the object IDs if required.
25
#
26
 
27
require_once __DIR__ . '/../includes/oidplus.inc.php';
28
 
29
OIDplus::init(true);
30
 
31
# ---
32
 
261 daniel-mar 33
$res = OIDplus::db()->query("select * from ###objects where id like ?", array("oid:%"));
236 daniel-mar 34
while ($row = $res->fetch_array()) {
190 daniel-mar 35
	list ($ns, $ida) = explode(':', $row['id']);
36
	$idb = sanitizeOID($ida);
37
	if (!$idb) continue;
38
	if ($ida != $idb) {
39
		echo "$ida -> $idb\n";
261 daniel-mar 40
		OIDplus::db()->query("update ###objects set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
41
		OIDplus::db()->query("update ###log_object set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
190 daniel-mar 42
	}
43
}
44
 
45
# ---
46
 
261 daniel-mar 47
$res = OIDplus::db()->query("select * from ###objects where id like ?", array("ipv4:%"));
236 daniel-mar 48
while ($row = $res->fetch_array()) {
190 daniel-mar 49
	list ($ns, $ida) = explode(':', $row['id']);
50
	$idb = ipv4_normalize($ida);
51
	if (!$idb) continue;
52
	if ($ida != $idb) {
53
		echo "$ida -> $idb\n";
261 daniel-mar 54
		OIDplus::db()->query("update ###objects set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
55
		OIDplus::db()->query("update ###log_object set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
190 daniel-mar 56
	}
57
}
58
 
59
# ---
60
 
261 daniel-mar 61
$res = OIDplus::db()->query("select * from ###objects where id like ?", array("ipv6:%"));
236 daniel-mar 62
while ($row = $res->fetch_array()) {
190 daniel-mar 63
	list ($ns, $ida) = explode(':', $row['id']);
64
	$idb = ipv6_normalize($ida);
65
	if (!$idb) continue;
66
	if ($ida != $idb) {
67
		echo "$ida -> $idb\n";
261 daniel-mar 68
		OIDplus::db()->query("update ###objects set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
69
		OIDplus::db()->query("update ###log_object set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
190 daniel-mar 70
	}
71
}
72
 
73
# ---
74
 
261 daniel-mar 75
$res = OIDplus::db()->query("select * from ###objects where id like ?", array("guid:%"));
236 daniel-mar 76
while ($row = $res->fetch_array()) {
190 daniel-mar 77
	list ($ns, $ida) = explode(':', $row['id']);
78
	$idb = uuid_canonize($ida);
79
	if (!$idb) continue;
80
	if ($ida != $idb) {
81
		echo "$ida -> $idb\n";
261 daniel-mar 82
		OIDplus::db()->query("update ###objects set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
83
		OIDplus::db()->query("update ###log_object set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
84
		OIDplus::db()->query("update ###asn1id set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
85
		OIDplus::db()->query("update ###iri set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
190 daniel-mar 86
	}
87
}
88
 
89
echo "Done.\n";
90