Rev 1454 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1454 | Rev 1461 | ||
---|---|---|---|
Line 760... | Line 760... | ||
760 | * @param OIDplusObject|string $obj |
760 | * @param OIDplusObject|string $obj |
761 | * @return bool |
761 | * @return bool |
762 | */ |
762 | */ |
763 | public function equals($obj): bool { |
763 | public function equals($obj): bool { |
764 | if (!$obj) return false; |
764 | if (!$obj) return false; |
- | 765 | if (!is_object($obj)) { |
|
- | 766 | if ($this->nodeId(true) === $obj) return true; // simplest case |
|
765 | if (!is_object($obj)) $obj = OIDplusObject::parse($obj); |
767 | $obj = OIDplusObject::parse($obj); |
766 | if (!$obj) return false; |
768 | if (!$obj) return false; |
- | 769 | } else { |
|
- | 770 | if ($this->nodeId(true) === $obj->nodeId(true)) return true; // simplest case |
|
- | 771 | } |
|
767 | if (!($obj instanceof $this)) return false; |
772 | if (!($obj instanceof $this)) return false; |
768 | 773 | ||
769 | $distance = $this->distance($obj); |
774 | $distance = $this->distance($obj); |
770 | if (is_numeric($distance)) return $distance === 0; // if the distance function is implemented, use it |
775 | if (is_numeric($distance)) return $distance === 0; // if the distance function is implemented, use it |
771 | 776 | ||
Line 779... | Line 784... | ||
779 | */ |
784 | */ |
780 | public static function findFitting(string $search_id) { |
785 | public static function findFitting(string $search_id) { |
781 | $obj = OIDplusObject::parse($search_id); |
786 | $obj = OIDplusObject::parse($search_id); |
782 | if (!$obj) return false; // e.g. if ObjectType plugin is disabled |
787 | if (!$obj) return false; // e.g. if ObjectType plugin is disabled |
783 | 788 | ||
- | 789 | if ($obj->nodeId(false) == '') return false; // speed optimization. "oid:" is not equal to any object in the database |
|
- | 790 | ||
784 | if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) { |
791 | if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) { |
785 | $res = OIDplus::db()->query("select id from ###objects where id like ?", array($obj->ns().':%')); |
792 | $res = OIDplus::db()->query("select id from ###objects where id like ?", array($obj->ns().':%')); |
786 | while ($row = $res->fetch_object()) { |
793 | while ($row = $res->fetch_object()) { |
787 | $test = OIDplusObject::parse($row->id); |
794 | $test = OIDplusObject::parse($row->id); |
788 | if ($obj->equals($test)) return $test; |
795 | if ($test && $obj->equals($test)) return $test; |
789 | } |
796 | } |
790 | return false; |
797 | return false; |
791 | } else { |
798 | } else { |
792 | self::buildObjectInformationCache(); |
799 | self::buildObjectInformationCache(); |
793 | foreach (self::$object_info_cache as $id => $cacheitem) { |
800 | foreach (self::$object_info_cache as $id => $cacheitem) { |
794 | if (strpos($id, $obj->ns().':') === 0) { |
801 | if (strpos($id, $obj->ns().':') === 0) { |
795 | $test = OIDplusObject::parse($id); |
802 | $test = OIDplusObject::parse($id); |
796 | if ($obj->equals($test)) return $test; |
803 | if ($test && $obj->equals($test)) return $test; |
797 | } |
804 | } |
798 | } |
805 | } |
799 | return false; |
806 | return false; |
800 | } |
807 | } |
801 | } |
808 | } |