Page MenuHomePhabricator
Paste P1788

import_issues.php
ActivePublic

Authored by ftdysa on May 22 2015, 12:03 PM.
Tags
None
Referenced Files
F413426: import_issues.php
May 22 2015, 12:03 PM
Subscribers
None
#!/usr/bin/env php
<?php
$root = dirname(dirname(__FILE__));
require_once $root.'/scripts/__init_script__.php';
require_once 'storage.php';
require_once 'phab.php';
class Issue {
public $id,
$key,
$project,
$reporter,
$summary,
$type,
$description,
$priority,
$status,
$created,
$updated,
$votes,
$watches;
}
class Action {
public
$id,
$issue,
$author,
$type,
$body,
$created,
$updatedauthor,
$updated;
}
$tasks = array();
$map = array();
try {
$doc = new DOMDocument();
$doc->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);
}
}
}

Event Timeline

ftdysa changed the title of this paste from untitled to import_issues.php.
ftdysa updated the paste's language from autodetect to php.