Subversion Repositories oidplus

Rev

Rev 261 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

#!/usr/bin/php
<?php

/*
 * OIDplus 2.0
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#
# Since OIDplus svn-184, entries in the database need to have a canonical ID
# If the ID is not canonical (e.g. GUIDs missing hyphens), the object cannot be opened in OIDplus
# This script re-canonizes the object IDs if required.
#

require_once __DIR__ . '/../includes/oidplus.inc.php';

OIDplus::init(true);

# ---

$res = OIDplus::db()->query("select * from ###objects where id like ?", array("oid:%"));
while ($row = $res->fetch_array()) {
        list ($ns, $ida) = explode(':', $row['id']);
        $idb = sanitizeOID($ida);
        if (!$idb) continue;
        if ($ida != $idb) {
                echo "$ida -> $idb\n";
                OIDplus::db()->query("update ###objects set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
                OIDplus::db()->query("update ###log_object set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
        }
}

# ---

$res = OIDplus::db()->query("select * from ###objects where id like ?", array("ipv4:%"));
while ($row = $res->fetch_array()) {
        list ($ns, $ida) = explode(':', $row['id']);
        $idb = ipv4_normalize($ida);
        if (!$idb) continue;
        if ($ida != $idb) {
                echo "$ida -> $idb\n";
                OIDplus::db()->query("update ###objects set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
                OIDplus::db()->query("update ###log_object set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
        }
}

# ---

$res = OIDplus::db()->query("select * from ###objects where id like ?", array("ipv6:%"));
while ($row = $res->fetch_array()) {
        list ($ns, $ida) = explode(':', $row['id']);
        $idb = ipv6_normalize($ida);
        if (!$idb) continue;
        if ($ida != $idb) {
                echo "$ida -> $idb\n";
                OIDplus::db()->query("update ###objects set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
                OIDplus::db()->query("update ###log_object set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
        }
}

# ---

$res = OIDplus::db()->query("select * from ###objects where id like ?", array("guid:%"));
while ($row = $res->fetch_array()) {
        list ($ns, $ida) = explode(':', $row['id']);
        $idb = uuid_canonize($ida);
        if (!$idb) continue;
        if ($ida != $idb) {
                echo "$ida -> $idb\n";
                OIDplus::db()->query("update ###objects set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
                OIDplus::db()->query("update ###log_object set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
                OIDplus::db()->query("update ###asn1id set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
                OIDplus::db()->query("update ###iri set id = ? where id = ?", array($ns.':'.$idb, $ns.':'.$ida));
        }
}

echo "Done.\n";