private function append_nodes(\DomNode $node, $parent)
 {
     if ($node->localName != 'node') {
         return;
     }
     $name = "";
     foreach ($node->attributes as $element) {
         /* The name of each JCR node or property becomes the value of the sv:name */
         if ($element->name != 'name') {
             continue;
         }
         $name = $element->value;
     }
     /* The hierarchy of the content repository nodes and properties is reflected in
      * the hierarchy of the corresponding XML elements. */
     $mvc_node = new midgardmvc_core_node();
     $mvc_node->name = $name;
     $mvc_node->up = $parent->id;
     $mvc_node->create();
     /* If there's duplicate, get it and reuse */
     if (midgard_connection::get_instance()->get_error() == MGD_ERR_DUPLICATE) {
         $q = new \midgard_query_select(new \midgard_query_storage('midgardmvc_core_node'));
         $group = new midgard_query_constraint_group('AND');
         $group->add_constraint(new \midgard_query_constraint(new \midgard_query_property('up'), '=', new \midgard_query_value($parent->id)));
         $group->add_constraint(new \midgard_query_constraint(new \midgard_query_property('name'), '=', new \midgard_query_value($name)));
         $q->set_constraint($group);
         $q->execute();
         $mvc_node = current($q->list_objects());
     }
     foreach ($node->childNodes as $snode) {
         $this->append_nodes($snode, $mvc_node);
     }
 }
Beispiel #2
0
 private static function prepare_node(midgardmvc_core_node $node, array $node_data, $destructive)
 {
     $node->title = $node_data['title'];
     $node->component = $node_data['component'];
     if ($destructive || !$node->content) {
         $node->content = $node_data['content'];
     }
     if ($node->guid) {
         $node->update();
     } else {
         if (isset($node_data['guid'])) {
             $node->set_guid($node_data['guid']);
         }
         $node->create();
     }
     if (isset($node_data['configuration'])) {
         $node->set_parameter('midgardmvc_core', 'configuration', midgardmvc_core::write_yaml($node_data['configuration']));
     }
     self::prepare_node_children($node, $node_data, $destructive);
 }
Beispiel #3
0
foreach ($classes as $refclass) {
    $parent_class = $refclass->getParentClass();
    if (!$parent_class) {
        continue;
    }
    if ($parent_class->getName() != 'midgard_object') {
        continue;
    }
    $type = $refclass->getName();
    midgard_storage::create_class_storage($type);
    echo "  Created storage for {$type}\n";
}
$page = new midgardmvc_core_node();
$page->name = 'midgardmvc_root';
$page->title = 'Midgard MVC root page';
$page->content = 'Welcome to Midgard MVC!';
$page->component = 'midgardmvc_core';
if (!$page->create()) {
    die("Failed to create Midgard MVC root node: " . $midgard->get_error_string() . "\n");
}
echo "Created Midgard MVC root page {$page->guid}\n";
$person = new midgard_person();
$person->set_guid('f6b665f1984503790ed91f39b11b5392');
$person->firstname = 'Midgard';
$person->lastname = 'Administrator';
$person->email = '*****@*****.**';
$person->homepage = 'http://www.midgard-project.org/';
$person->birthdate = new midgard_datetime('1999-05-08');
$person->create();
echo "Create Midgard person {$person->firstname} {$person->lastname}\n";
echo "All set up\n";