#!/usr/bin/env php load('entities.xml'); $xpath = new DOMXPath($doc); $issues = $xpath->query('/entity-engine-xml/Issue'); foreach ($issues as $issue_node) { $issue = new Issue(); // Extract the attributes foreach ($issue_node->attributes as $index => $attr) { if (property_exists('Issue', $attr->name)) { $issue->{$attr->name} = $attr->value; } } if ($issue_node->hasChildNodes()) { foreach ($issue_node->childNodes as $child) $issue->description .= $child->nodeValue; } $map[$issue->id]['issue'] = $issue; } $comments = $xpath->query('/entity-engine-xml/Action'); foreach ($comments as $comment) { $action = new Action(); // Extract the attributes foreach ($comment->attributes as $index => $attr) { if (property_exists('Action', $attr->name)) { $action->{$attr->name} = $attr->value; } } if ($comment->hasChildNodes()) { foreach ($comment->childNodes as $child) $comment->body .= $child->nodeValue; } $map[$action->issue]['comments'] = $action; } convert_issues($map); } catch (Exception $e){ echo $e->getMessage(); exit(); } function convert_issues(array $issues) { foreach ($issues as $issue_id => $issue_data) { $issue = $issue_data['issue']; $comments = $issue_data['comments']; $author = lookup_user($issue->reporter); $status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED; $description = str_replace("\r\n", "\n", $issue->description); $title = $issue->summary; $created = $issue->created; switch ($issue->status) { case 6: case 3: $status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED; break; case 1: $status = ManiphestTaskStatus::STATUS_OPEN; break; } /* create task */ $task = create_task($author, $issue->id, $title, array(), $description, null, $created, null, 0); $last_date = null; foreach ($comments as $comment) { $comment_author = lookup_user($comment->author); create_comment($task, $comment_author, $comment->description, $comment->created); $last_date = $comment->created; } if ($status === ManiphestTaskStatus::STATUS_CLOSED_RESOLVED) { set_status($task, $author, $status, $last_date === null ? $created : $last_date); } } }