Migration scripts in somewhat better state now, main missing part is that statuses

are not imported correctly, though there's a bunch of details to figure out.
This commit is contained in:
2013-10-22 13:52:53 +02:00
committed by Sergey Sharybin
parent 498842475c
commit aeaf0902e1
5 changed files with 364 additions and 345 deletions

View File

@@ -7,7 +7,7 @@ require_once 'storage.php';
require_once 'adapt.php';
require_once 'phab.php';
for($id = intval($argv[1]); $id < intval($argv[2]); $id+=100) { // XXX quick subset of tasks
for($id = intval($argv[1]); $id < intval($argv[2]); $id+=1) {
/* unserialize */
$fname = "dump/task_" . $id;
if(!file_exists($fname))
@@ -23,14 +23,11 @@ for($id = intval($argv[1]); $id < intval($argv[2]); $id+=100) { // XXX quick sub
$assign = lookup_user(dedup_user($mtask->assign));
$projects = array();
// 100 Unbreak Now!, 90 Needs Triage, 80 High, 50 Normal, 25 Low, 0, Wishlist
// TODO set feature request and todo priorities
$priority = 50;
$status = ManiphestTaskStatus::STATUS_OPEN;
$description = '%%%' . html_entity_decode($mtask->description) . '%%%'; // TODO replace urls
$title = html_entity_decode($mtask->title);
/* spam detection */
// TODO: this only catches a small subet of spam
if(($author == "None" || $author == null) && startsWith($description, "%%%<a href= http://") && strpos($title, " ") == false)
continue;
@@ -43,103 +40,252 @@ for($id = intval($argv[1]); $id < intval($argv[2]); $id+=100) { // XXX quick sub
/* extra fields */
$extra = "";
$extension_type = "None";
$task_type = "Bug";
// TODO this is pretty bad and incomplete
if($active_projects[$mtask->project][1]) {
$projects[] = lookup_project($active_projects[$mtask->project][1])->getPHID();
/* BF Blender tasks */
if($mtask->project == "Blender 2.x BF release") {
$projects[] = lookup_project("BF Blender")->getPHID();
$category = null;
$category_key = null;
$mstatus = null;
$mstatus_key = null;
$resolution = null;
$resolution_key = null;
$old_resolution = null;
$old_resolution_key = null;
$data_type = null;
$date_type_key = null;
foreach($mtask->extra_fields as $key => $field) {
if($field['name'] == "Category") {
$category = $field['value'];
$category_key = $key;
}
else if($field['name'] == "Status") {
$mstatus = $field['value'];
$mstatus_key = $key;
}
else if($field['name'] == "Resolution") {
$resolution = $field['value'];
$resolution_key = $key;
}
else if($field['name'] == "Resolution(Old, use status)") {
$old_resolution = $field['value'];
$old_resolution_key = $key;
}
else if($field['name'] == "Data Type") {
$data_type = $field['value'];
$data_type_key = $key;
}
}
if($mtask->tracker == "Blender 2.6 Bug Tracker") {
$close_as_archived = false;
$task_type = "Bug";
$priority = 50;
if($category) {
if($bf_blender_categories[$category])
$projects[] = lookup_project($bf_blender_categories[$category])->getPHID();
unset($mtask->extra_fields[$category_key]);
}
// TODO: add more statuses or fields
switch($mstatus) {
case "New":
$priority = 90;
break;
case "Reopened":
break;
case "Investigate":
break;
case "Confirmed":
break;
case "Incomplete":
break;
case "Fixed / Closed":
$status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED;
break;
case "Rejected / Closed":
$status = ManiphestTaskStatus::STATUS_CLOSED_INVALID;
break;
case "Closed":
$status = ManiphestTaskStatus::STATUS_CLOSED_ARCHIVED;
break;
case "Todo / Closed":
$status = ManiphestTaskStatus::STATUS_CLOSED_INVALID;
break;
case "Out of scope / Closed":
$status = ManiphestTaskStatus::STATUS_CLOSED_INVALID;
break;
case "Ready":
break;
case "*RELEASE BLOCKER*":
$priority = 80;
break;
default:
echo "ERROR: unkown status \"" . $mstatus . "\" (" . $id . ")\n";
break;
}
unset($mtask->extra_fields[$mstatus_key]);
}
else if($mtask->tracker == "Blender 2.4x Bug Tracker") {
// TODO: handle status
$task_type = "Bug";
$priority = 50;
$close_as_archived = true;
$status = ManiphestTaskStatus::STATUS_CLOSED_ARCHIVED;
}
else if($mtask->tracker == "Game Engine") {
// TODO: add more statuses or fields
switch($mstatus) {
case "None":
case "New":
case "Reopened":
case "Investigate":
case "Ready":
$status = ManiphestTaskStatus::STATUS_OPEN;
break;
case "Fixed":
$status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED;
break;
case "Duplicate":
$status = ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE;
break;
case "Rejected":
$status = ManiphestTaskStatus::STATUS_CLOSED_INVALID;
break;
case "Closed":
$status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED;
break;
default:
echo "ERROR: unkown resolution \"" . $resolution . "\" (" . $id . ")\n";
break;
}
unset($mtask->extra_fields[$mstatus_key]);
$projects[] = lookup_project("Game Engine")->getPHID();
$task_type = "Bug";
$priority = 50;
$close_as_archived = false;
$status = ManiphestTaskStatus::STATUS_OPEN;
}
else if($mtask->tracker == "Todo") {
$task_type = "To Do";
$priority = 0;
$close_as_archived = false;
$status = ManiphestTaskStatus::STATUS_CLOSED_ARCHIVED;
}
else if($mtask->tracker == "OpenGL errors") {
$task_type = "OpenGL Error";
$priority = 25;
$close_as_archived = false;
$status = ManiphestTaskStatus::STATUS_CLOSED_ARCHIVED;
}
else if($mtask->tracker == "Patches") {
$task_type = "Patch";
$priority = 50;
$close_as_archived = false;
if($category) {
if($bf_blender_categories[$category])
$projects[] = lookup_project($bf_blender_categories[$category])->getPHID();
unset($mtask->extra_fields[$category_key]);
}
// TODO: add more statuses or fields
switch($resolution) {
case "None":
$status = ManiphestTaskStatus::STATUS_OPEN;
break;
case "Open":
$status = ManiphestTaskStatus::STATUS_OPEN;
break;
case "Investigate":
$status = ManiphestTaskStatus::STATUS_OPEN;
break;
case "Need updates":
$status = ManiphestTaskStatus::STATUS_OPEN;
break;
case "Applied":
$status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED;
break;
case "Closed":
$status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED;
break;
default:
echo "ERROR: unkown resolution \"" . $resolution . "\" (" . $id . ")\n";
break;
}
unset($mtask->extra_fields[$resolution_key]);
if($old_resolution)
unset($mtask->extra_fields[$old_resolution_key]);
}
else {
echo "ERROR: unknown BF Blender tracker " . $mtask->tracker . " (" . $id . ")\n";
$priority = 50;
$close_as_archived = true;
$status = ManiphestTaskStatus::STATUS_CLOSED_ARCHIVED;
}
}
else if($mtask->project == "Blender Extensions") {
switch($mtask->tracker) {
case "Py Scripts Extern":
$extension_type = "Python Script Extern";
break;
case "dev-tools":
break;
case "test-tracker":
break;
case "Plugins Release":
$extension_type = "Plugin Release";
break;
case "Plugins Contrib":
$extension_type = "Plugin Contrib";
break;
case "Plugins Upload":
$extension_type = "Plugin Upload";
break;
case "Py Scripts Release":
$extension_type = "Pythin Script Release";
break;
case "Py Scripts Contrib":
$extension_type = "Python Script Contrib";
break;
case "Py Scripts Upload":
$extension_type = "Python Script Upload";
break;
case "Bugs":
break;
default:
echo "ERROR: unkown extension tracker \"" . $mtask->tracker . "\" (" . $id . ")\n";
break;
}
// TODO: status!
$projects[] = lookup_project("Extensions")->getPHID();
$task_type = "Extension";
$priority = 50;
$status = ManiphestTaskStatus::STATUS_OPEN;
$close_as_archived = false;
}
else {
$extra .= "**Project**: " . $mtask->project . "\n";
}
if($active_trackers[$mtask->tracker][1]) {
$projects[] = lookup_project($active_trackers[$mtask->tracker][1])->getPHID();
}
$task_type = "Other";
if($active_trackers[$mtask->tracker][2]) {
$task_type = $active_trackers[$mtask->tracker][2];
}
else {
$extra .= "**Tracker**: " . $mtask->tracker . "\n";
$task_type = "Other";
$priority = 50;
$close_as_archived = true;
$status = ManiphestTaskStatus::STATUS_CLOSED_ARCHIVED;
}
/* add remaining extra fields to description */
foreach($mtask->extra_fields as $field) {
if($field['name'] == "Category") {
if($active_categories[$field['value']])
$projects[] = lookup_project($active_categories[$field['value']])->getPHID();
continue;
}
if($field['name'] == "Status") {
switch($field['value']) {
case "None": /*$status = ManiphestTaskStatus::STATUS_OPEN;*/ break;
case "Closed": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "New": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Fixed / Closed": $status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED; break;
case "Rejected": $status = ManiphestTaskStatus::STATUS_CLOSED_INVALID; break;
case "Fixed": $status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED; break;
case "Rejected / Closed": $status = ManiphestTaskStatus::STATUS_CLOSED_INVALID; break;
case "Duplicate": $status = ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE; break;
case "Todo / Closed": $status = ManiphestTaskStatus::STATUS_CLOSED_INVALID; break;
case "Open": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Merged w/ others scripts": $status = ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE; break;
case "Buggy": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "No wiki": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "&gt;Contrib": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Implemented": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Accepted": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Investigate": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Reopened": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "&gt;Release": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "On hold": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Investigating": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Awaiting Response": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Confirmed": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Out of scope / Closed": $status = ManiphestTaskStatus::STATUS_CLOSED_INVALID; break;
case "Ready": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Incomplete": $status = ManiphestTaskStatus::STATUS_OPEN; break;
default:
echo "ERROR: unknown Status " . $field['value'] . "\n";
break;
}
// XXX continue;
}
if($field['name'] == "Resolution") {
switch($field['value']) {
case "Investigate": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "New": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Approved": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Fixed": $status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED; break;
case "Rejected": $status = ManiphestTaskStatus::STATUS_CLOSED_INVALID; break;
case "Postponed": $status = ManiphestTaskStatus::STATUS_CLOSED_INVALID; break;
case "Ready": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "None": /*$status = ManiphestTaskStatus::STATUS_OPEN;*/ break;
case "Ready": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Closed": $status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED; break;
case "Open": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Invalid": $status = ManiphestTaskStatus::STATUS_CLOSED_INVALID; break;
case "Accepted As Bug": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Won't Fix": $status = ManiphestTaskStatus::STATUS_CLOSED_WONTFIX; break;
case "Duplicate": $status = ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE; break;
case "Awaiting Response": $status = ManiphestTaskStatus::STATUS_OPEN; break;
case "Applied": $status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED; break;
case "Accepted": $status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED; break;
case "Need updates": $status = ManiphestTaskStatus::STATUS_OPEN; break;
default:
echo "ERROR: unknown Resolution " . $field['value'] . "\n";
break;
}
}
if($field['name'] == "Resolution(Old, use status)") {
// XXX
}
if($field['value'] == "" || $field['value'] == 'None')
continue;
@@ -198,8 +344,7 @@ for($id = intval($argv[1]); $id < intval($argv[2]); $id+=100) { // XXX quick sub
/* create task */
$task = create_task($author, $mtask->id, $title, $projects,
$description, $assign, $mtask->date, $ccs, $priority, $task_type);
$description, $assign, $mtask->date, $ccs, $priority, $task_type, $extension_type);
/* create array with all operations */
$sorted_dates = array();
@@ -218,21 +363,24 @@ for($id = intval($argv[1]); $id < intval($argv[2]); $id+=100) { // XXX quick sub
}
/* history */
$old_status = $mtask->state;
$old_status = $status;
$found_last_status = false;
foreach ($mtask->history as $mhistory) {
// TODO: these often have the wrong user (e.g. T17501)
// TODO: different types of status fields exist
if($mhistory->field == "Status") {
if($mhistory->field == "Status" || $mhistory->field == "status_id" || $mhistory->field == "Resolution") {
$sorted_dates[] = $mhistory->date + 2; // couldn't find stable sort, so hack
$sorted_actions[] = array($mhistory->user, $mhistory->date, $old_status);
$old_status = $mhistory->old;
$found_last_status = true;
break; // only does last status, too messy to figure out from history
}
}
$sorted_dates[] = $mtask->date;
$sorted_actions[] = array($mtask->author, $mtask->date, $old_status);
if(!$found_last_status) {
$sorted_dates[] = $mtask->date;
$sorted_actions[] = array("None", $mtask->date, $old_status);
}
/* sort and apply in order */
array_multisort($sorted_dates, $sorted_actions);
@@ -246,8 +394,8 @@ for($id = intval($argv[1]); $id < intval($argv[2]); $id+=100) { // XXX quick sub
// TODO skip low file IDS to avoid F1..F12 becoming shortcut key links
// TODO mysql file size limit
if($user)
create_comment($task, $user, "Attach file: " . $mfile->name, $mfile->date);
//create_file($task, $user, $mfile->name, $mfile->contents, $mfile->date);*/
create_file($task, $user, $mfile->name, $mfile->contents, $mfile->date);
//create_comment($task, $user, "Attach file: " . $mfile->name, $mfile->date);
}
else if(is_object($action) && get_class($action) == "MigrateComment") {
/* create comment */
@@ -268,19 +416,15 @@ for($id = intval($argv[1]); $id < intval($argv[2]); $id+=100) { // XXX quick sub
if(!$user)
$user = lookup_user("None");
$status = ManiphestTaskStatus::STATUS_OPEN;
if(strpos($mstatus, "Closed") !== false)
$status = ManiphestTaskStatus::STATUS_CLOSED_RESOLVED;
set_status($task, $user, $status, $mdate);
set_status($task, $user, $mstatus, $mdate);
}
}
/* if me missed the status somehow, close anyway if task is closed */
// TODO
/* final status check */
if($task->getStatus() == ManiphestTaskStatus::STATUS_OPEN && $close_as_archived)
set_status($task, lookup_user("None"), ManiphestTaskStatus::STATUS_CLOSED_ARCHIVED, $mtask->date);
if($task->getStatus() == ManiphestTaskStatus::STATUS_OPEN && $mtask->state == "Closed")
echo "ERROR: status out of sync, task should have been closed\n";
//set_status($task, lookup_user("None"), ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, $mtask->date);
echo "ERROR: status out of sync, task should have been closed (" . $id . ")\n";
}