Beispiel #1
0
 /**
  * Constructor. Creates an abstraction layer for an MgdSchema object.
  */
 public function __construct($id = null)
 {
     if (is_object($id)) {
         $this->__object = midcom::get('dbfactory')->convert_midcom_to_midgard($id);
     } else {
         if (is_string($id) && strlen($id) == 1) {
             debug_add('Constructing ' . $this->__mgdschema_class_name__ . ' object ' . $id . ' with ID typecast to string. Changing typecast.', MIDCOM_LOG_INFO);
             $id = (int) $id;
         }
         if (is_int($id) && $id < 1) {
             throw new midcom_error($id . ' is not a valid database ID');
         }
         try {
             $mgdschemaclass = $this->__mgdschema_class_name__;
             $this->__object = new $mgdschemaclass($id);
         } catch (midgard_error_exception $e) {
             debug_add('Constructing ' . $this->__mgdschema_class_name__ . ' object ' . $id . ' failed, reason: ' . $e->getMessage(), MIDCOM_LOG_WARN);
             throw new midcom_error_midgard($e, $id);
         }
         //Some useful information for performance tuning
         if ($GLOBALS['midcom_config']['log_level'] >= MIDCOM_LOG_DEBUG && $this->__object->guid) {
             static $guids = array();
             static $total = 0;
             $total++;
             //If the GUID was loaded already, write the appropriate log entry
             if (array_key_exists($this->__object->guid, $guids)) {
                 $guids[$this->__object->guid]++;
                 $message = $this->__mgdschema_class_name__ . ' ' . $this->__object->guid;
                 $message .= ' loaded from db ' . $guids[$this->__object->guid] . ' times.';
                 $stats = 'Objects loaded (Total/Unique): ' . $total . '/' . sizeof($guids);
                 debug_add($message);
                 debug_add($stats);
             } else {
                 $guids[$this->__object->guid] = 1;
             }
         }
     }
     if ($this->__object->guid && mgd_is_guid($this->__object->guid)) {
         midcom_baseclasses_core_dbobject::post_db_load_checks($this);
     }
 }