danielmarschall / oidplus

OIDplus 2.0 - An OpenSource online Registration Authority for OIDs and other Object Types
https://www.oidplus.com
Apache License 2.0
10 stars 6 forks source link

Update question #10

Closed wehowski closed 1 year ago

wehowski commented 1 year ago

Hello Daniel, after updating to svn-1149 I got Call to undefined method ViaThinkSoft\OIDplus\OIDplusDatabaseConnectionMySQLi::natOrder() in my freeweid Plugin.

So I changed

    protected static function freeoid_max_id() {
        $res = OIDplus::db()->query("select id from ###objects where id like ? order by ".OIDplus::db()->natOrder('id'), array(self::getFreeRootOid(true).'.%'));
        $highest_id = 0;
        while ($row = $res->fetch_array()) {
            $arc = substr_count(self::getFreeRootOid(false), '.')+1;
            $highest_id = explode('.',$row['id'])[$arc];
        }
        return $highest_id;
    }

to:

    protected static function freeoid_max_id(): int {
        $res = OIDplus::db()->query("select id from ###objects where id like ?", array(self::getFreeRootOid(true).'.%'));
        $res = new OIDplusNaturalSortedQueryResult($res, 'id');
        $highest_id = 0;
        while ($row = $res->fetch_array()) {
            $arc = substr_count(self::getFreeRootOid(false), '.')+1;
            $highest_id = explode('.',$row['id'])[$arc];
        }
        return (int)$highest_id;
    }

So far so well.

But I am not really sure how to change this method correctly:

    public function raHasFreeWeid($email, $getId = false){
        $res = OIDplus::db()->query("select id from ###objects where ra_email = ? and id like ? order by ".OIDplus::db()->natOrder('id'), array($email, self::getFreeRootOid(true).'.%'));
        while ($row = $res->fetch_array()) {
           return (true === $getId) ? $row['id'] : true;    
        }

      return false; 
    }

Can you give me a hint how to replace OIDplus::db()->natOrder('id') the right way?

Thank you!!!

danielmarschall commented 1 year ago

Hello,

this is the replacement of the natOrder() functionality: (Example)

$res = OIDplus::db()->query("select * from ###objects where parent = ?", array($obj->nodeId()));
$res = new OIDplusNaturalSortedQueryResult($res, 'id');
while ($row = $res->fetch_array()) {
wehowski commented 1 year ago

Danke!!! I changed it to:

    public function raHasFreeWeid($email, $getId = false){
        $res = OIDplus::db()->query("select id from ###objects where ra_email = ? and id like ?", 
                                    array($email, self::getFreeRootOid(true).'.%'));
        $res = new OIDplusNaturalSortedQueryResult($res, 'id');
        while ($row = $res->fetch_array()) {            
           return (true === $getId) ? $row['id'] : true;    
        }

      return false; 
    }
danielmarschall commented 1 year ago

@wehowski Sorry, there will be yet another major update to the database handling which changes $res = new OIDplusNaturalSortedQueryResult($res, 'id'); to $res->naturalSortByField('id');

wehowski commented 1 year ago

Works! Thank you!