Example #1
0
 public function testGet_object()
 {
     $object = $this->create_object('midcom_db_person');
     $object->delete();
     $object2 = midcom_helper_reflector::get_object($object->guid, 'midgard_person');
     $this->assertEquals($object->guid, $object2->guid);
 }
Example #2
0
 /**
  * Helper method for purging objects
  *
  * @param Array $guids
  * @param string $type
  * @return boolean Indicating success
  */
 public static function purge($guids, $type)
 {
     $purged_size = 0;
     foreach ($guids as $guid) {
         $object = midcom_helper_reflector::get_object($guid, $type);
         if (is_null($object)) {
             debug_add("Failed to get object {$type} {$guid}", MIDCOM_LOG_ERROR);
             // Something wrong
             continue;
         }
         // first kill your children
         $children_types = midcom_helper_reflector_tree::get_child_objects($object, true);
         if (is_array($children_types)) {
             foreach ($children_types as $child_type => $children) {
                 $child_guids = array();
                 foreach ($children as $child) {
                     if (!$child->metadata->deleted) {
                         $child->delete();
                     }
                     $child_guids[] = $child->guid;
                 }
                 self::purge($child_guids, $child_type);
             }
         }
         // then shoot your dogs
         $purged_size += self::purge_parameters($guid);
         $purged_size += self::purge_attachments($guid);
         // now shoot yourself
         if (!$object->purge()) {
             debug_add("Failed to purge object " . get_class($object) . " {$object->guid}", MIDCOM_LOG_INFO);
         } else {
             $purged_size += $object->metadata->size;
         }
     }
     return $purged_size;
 }