X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FCore_domain.php;h=89b4587d89ac788db1df77c3e76500b0525ffb08;hp=6420b7f0918bf31873aca6081f8f85a5c3028a03;hb=HEAD;hpb=aeb22fc98d59cce70548b1adf66a8ce21dff8fbe diff --git a/DataObjects/Core_domain.php b/DataObjects/Core_domain.php index 6420b7f0..3c50da42 100644 --- a/DataObjects/Core_domain.php +++ b/DataObjects/Core_domain.php @@ -2,7 +2,7 @@ /** * Table Definition for core_domain */ -require_once 'DB/DataObject.php'; +class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php'; class Pman_Core_DataObjects_Core_domain extends DB_DataObject { @@ -15,5 +15,22 @@ class Pman_Core_DataObjects_Core_domain extends DB_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - + function loadOrCreate($dom) + { + // should we validate domain? + static $cache = array(); + if (isset($cache[$dom])) { + return $cache[$dom]; + } + + $cd = DB_DataObject::Factory($this->tableName()); + if ($cd->get('domain', $dom)) { + $cache[$dom] = $cd; + return $cd; + } + $cd->domain = $dom; + $cd->insert(); + $cache[$dom] = $cd; + return $cd; + } }