Changeset 11966

Show
Ignore:
Timestamp:
09/03/07 11:59:38 (1 year ago)
Author:
bergie
Message:

Some bulletproofing and Midgard 1.8 compatibility

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/MidCOM_2_8/midcom.core/midcom/baseclasses/core/dbobject.php

    r11474 r11966  
    426426 
    427427        // Delete all extensions: 
    428         $list = $object->list_attachments(); 
    429         foreach ($list as $attachment) 
    430         { 
    431             if (! $attachment->delete()) 
    432             { 
    433                 debug_add("Failed to delete attachment ID {$attachment->id}", MIDCOM_LOG_ERROR); 
    434                 // debug_print_r('Full record:', $attachment); 
    435                 debug_pop(); 
    436                 return false; 
     428        // Attachments can't have attachments so no need to query those 
     429        if (!is_a($object, 'midcom_baseclasses_database_attachment')) 
     430        { 
     431            $list = $object->list_attachments(); 
     432            foreach ($list as $attachment) 
     433            { 
     434                if (! $attachment->delete()) 
     435                { 
     436                    debug_add("Failed to delete attachment ID {$attachment->id}", MIDCOM_LOG_ERROR); 
     437                    // debug_print_r('Full record:', $attachment); 
     438                    debug_pop(); 
     439                    return false; 
     440                } 
    437441            } 
    438442        } 
     
    18841888 
    18851889        $qb = $_MIDCOM->dbfactory->new_query_builder('midcom_baseclasses_database_attachment'); 
    1886         $qb->add_constraint('ptable', '=', $object->__table__); 
    1887         $qb->add_constraint('pid', '=', $object->id); 
     1890        $qb->add_constraint('parentguid', '=', $object->guid); 
    18881891 
    18891892        debug_pop(); 
     
    19061909            debug_add('Cannot retrieve attachments on a non-persistant object.', MIDCOM_LOG_WARN); 
    19071910            debug_pop(); 
    1908             return false
     1911            return array()
    19091912        } 
    19101913 
    19111914        $qb = $object->get_attachment_qb(); 
    19121915        $result = $_MIDCOM->dbfactory->exec_query_builder($qb); 
     1916        if (   !$result 
     1917            || !is_array($result)) 
     1918        { 
     1919            return array(); 
     1920        } 
    19131921 
    19141922        debug_pop(); 
  • branches/MidCOM_2_8/midcom.core/midcom/baseclasses/database/attachment.php

    r5787 r11966  
    4949    function get_parent_guid_uncached() 
    5050    { 
    51         $possible_parent_classes = $_MIDCOM->dbclassloader->get_classes_for_table($this->ptable); 
    52         if (count($possible_parent_classes) == 0) 
    53         { 
    54             debug_push_class(__CLASS__, __FUNCTION__); 
    55             debug_add("Failed to retrieve the parent object for Attachment {$this->id}, parent table {$this->ptable} is unknown to the class loader.", MIDCOM_LOG_WARN); 
    56             debug_pop(); 
     51        if (!$this->parentguid) 
     52        { 
    5753            return null; 
    5854        } 
    5955 
    60         $classname = $possible_parent_classes[0]['midcom_class_name']; 
    61         $_MIDCOM->dbclassloader->load_mgdschema_class_handler($classname); 
    62         $parent = new $classname($this->pid); 
    63  
    64         if (   ! $parent 
    65             || $parent->id != $this->pid) 
    66         { 
    67             debug_push_class(__CLASS__, __FUNCTION__); 
    68             debug_add("Failed to retrieve the parent object for Attachment {$this->id}, could not retrieve parent object.", MIDCOM_LOG_WARN); 
    69             debug_print_r('Retrieved object was:', $parent); 
     56        $parent = $_MIDCOM->dbfactory->get_object_by_guid($this->parentguid); 
     57        if (! $parent) 
     58        { 
     59            debug_push_class(__CLASS__, __FUNCTION__); 
     60            debug_add("Could not load Parameter parent {$this->parentguid} from the database, aborting.", 
     61                MIDCOM_LOG_INFO); 
    7062            debug_pop(); 
    7163            return null; 
  • branches/MidCOM_2_8/midcom.core/midcom/baseclasses/database/parameter.php

    r4994 r11966  
    4747        { 
    4848            debug_push_class(__CLASS__, __FUNCTION__); 
    49             debug_add("Could not load Parameter ID {$this->up} from the database, aborting.", 
     49            debug_add("Could not load Parameter parent {$this->parentguid} from the database, aborting.", 
    5050                MIDCOM_LOG_INFO); 
    5151            debug_pop(); 
  • branches/MidCOM_2_8/midcom.helper.datamanager2/type/blobs.php

    r11014 r11966  
    563563        if (! $this->update_attachment_by_handle($identifier, $filename, $title, $mimetype, $handle, true, $tmpname)) 
    564564        { 
    565             fclose($handle); 
     565            @fclose($handle); 
    566566            debug_push_class(__CLASS__, __FUNCTION__); 
    567567            debug_add('Failed to create attachment, see above for details.');