Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F413426
import_issues.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
ftdysa
May 22 2015, 12:03 PM
2015-05-22 12:03:38 (UTC+0)
Size
3 KB
Referenced Files
None
Subscribers
None
import_issues.php
View Options
#!/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
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/cg/fy/5ldxgkuhnlfpdm53
Default Alt Text
import_issues.php (3 KB)
Attached To
Mode
P1788 import_issues.php
Attached
Detach File
Event Timeline
Log In to Comment