Example #1
0
 private function _list_revised($since, $review_by = null, $type = null, $only_mine = false)
 {
     $classes = array();
     $revised = array();
     // List installed MgdSchema types and convert to DBA classes
     foreach ($this->_request_data['schema_types'] as $schema_type) {
         if (!is_null($type) && $schema_type != $type) {
             // Skip
             continue;
         }
         $mgdschema_class = midcom_helper_reflector::class_rewrite($schema_type);
         $dummy_object = new $mgdschema_class();
         $midcom_dba_classname = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($dummy_object);
         if (empty($midcom_dba_classname)) {
             continue;
         }
         $classes[] = $midcom_dba_classname;
     }
     // List all revised objects
     foreach ($classes as $class) {
         if (!midcom::get('dbclassloader')->load_mgdschema_class_handler($class)) {
             // Failed to load handling component, skip
             continue;
         }
         $qb_callback = array($class, 'new_query_builder');
         if (!is_callable($qb_callback)) {
             continue;
         }
         $qb = call_user_func($qb_callback);
         if ($since != 'any') {
             $qb->add_constraint('metadata.revised', '>=', $since);
         }
         if ($only_mine && midcom::get('auth')->user) {
             $qb->add_constraint('metadata.authors', 'LIKE', '|' . midcom::get('auth')->user->guid . '|');
         }
         $qb->add_order('metadata.revision', 'DESC');
         $objects = $qb->execute();
         if (count($objects) > 0) {
             if (!isset($this->_reflectors[$class])) {
                 $this->_reflectors[$class] = new midcom_helper_reflector($objects[0]);
             }
         }
         foreach ($objects as $object) {
             if (!is_null($review_by)) {
                 $object_review_by = (int) $object->get_parameter('midcom.helper.metadata', 'review_date');
                 if ($object_review_by > $review_by) {
                     // Skip
                     continue;
                 }
             }
             $revised["{$object->metadata->revised}_{$object->guid}_{$object->metadata->revision}"] = $object;
         }
     }
     krsort($revised);
     return $revised;
 }
Example #2
0
 /**
  * @dataProvider providerClass_rewrite
  */
 public function testClass_rewrite($classname, $result)
 {
     $this->assertEquals($result, midcom_helper_reflector::class_rewrite($classname));
 }
Example #3
0
 private function _find_linking_property($new_type)
 {
     // Figure out the linking property
     $new_type_reflector = midcom_helper_reflector::get($new_type);
     $link_properties = $new_type_reflector->get_link_properties();
     $type_to_link_to = midcom_helper_reflector::class_rewrite(get_class($this->_object));
     foreach ($link_properties as $new_type_property => $link) {
         $linked_type = midcom_helper_reflector::class_rewrite($link['class']);
         if (midcom_helper_reflector::is_same_class($linked_type, $type_to_link_to) || $link['type'] == MGD_TYPE_GUID && is_null($link['class'])) {
             $parent_property = $link['target'];
             return array($new_type_property, $parent_property);
         }
     }
     return false;
 }
Example #4
0
 /**
  * Resolves the "root level" classes, used by get_root_classes()
  *
  * @return array of classnames (or false on critical failure)
  */
 private static function _resolve_root_classes()
 {
     $root_exceptions_notroot = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config')->get('root_class_exceptions_notroot');
     // Safety against misconfiguration
     if (!is_array($root_exceptions_notroot)) {
         debug_add("config->get('root_class_exceptions_notroot') did not return array, invalid configuration ??", MIDCOM_LOG_ERROR);
         $root_exceptions_notroot = array();
     }
     $root_classes = array();
     foreach (midcom_connection::get_schema_types() as $schema_type) {
         if (substr($schema_type, 0, 2) == '__') {
             continue;
         }
         if (in_array($schema_type, $root_exceptions_notroot)) {
             // Explicitly specified to not be root class, skip all heuristics
             continue;
         }
         // Class extensions mapping
         $schema_type = midcom_helper_reflector::class_rewrite($schema_type);
         // Make sure we only add classes once
         if (in_array($schema_type, $root_classes)) {
             // Already listed
             continue;
         }
         $parent = midgard_object_class::get_property_parent($schema_type);
         if (!empty($parent)) {
             // type has parent set, thus cannot be root type
             continue;
         }
         $dba_class = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($schema_type);
         if (!$dba_class) {
             // Not a MidCOM DBA object, skip
             continue;
         }
         $root_classes[] = $schema_type;
     }
     unset($root_exceptions_notroot);
     $root_exceptions_forceroot = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config')->get('root_class_exceptions_forceroot');
     // Safety against misconfiguration
     if (!is_array($root_exceptions_forceroot)) {
         debug_add("config->get('root_class_exceptions_forceroot') did not return array, invalid configuration ??", MIDCOM_LOG_ERROR);
         $root_exceptions_forceroot = array();
     }
     if (!empty($root_exceptions_forceroot)) {
         foreach ($root_exceptions_forceroot as $schema_type) {
             if (!class_exists($schema_type)) {
                 // Not a valid class
                 debug_add("Type {$schema_type} has been listed to always be root class, but the class does not exist", MIDCOM_LOG_WARN);
                 continue;
             }
             if (in_array($schema_type, $root_classes)) {
                 // Already listed
                 continue;
             }
             $root_classes[] = $schema_type;
         }
     }
     usort($root_classes, 'strnatcmp');
     return $root_classes;
 }