I am writing a custom script to bulk move tickets between columns on a workboard. Being able to query workboard columns by name would make this a lot easier.
Details
Details
- Reviewers
epriestley - Group Reviewers
Blessed Reviewers
Summary
Test Plan
Tested by running my custom script.
Diff Detail
Diff Detail
- Repository
- rP Phabricator
- Branch
- master
- Lint
Lint Passed - Unit
Tests Passed - Build Status
Buildable 7843 Build 8717: [Placeholder Plan] Wait for 30 Seconds Build 8716: arc lint + arc unit
Event Timeline
joshuaspence updated this object.
Comment Actions
For posterity, here's the script I am using for bulk moving objects on a workboard:
1 | <?php |
---|---|
2 | |
3 | // Depends on https://secure.phabricator.com/D13718 |
4 | |
5 | require_once __DIR__.'/scripts/__init_script__.php'; |
6 | |
7 | $args = new PhutilArgumentParser($argv); |
8 | $args->setSynopsis(<<<EOSYNOPSIS |
9 | **bulk_move_workboard.php** [__options__] |
10 | |
11 | Bulk moves resolved tasks on a workboard. This script will select //all// |
12 | resolved belonging to a specified project and will move all resolved tasks to |
13 | the specified column on the project's workboard. |
14 | EOSYNOPSIS |
15 | ); |
16 | $args->parseStandardArguments(); |
17 | $args->parse( |
18 | array( |
19 | array( |
20 | 'name' => 'user', |
21 | 'param' => 'username', |
22 | 'help' => pht( |
23 | 'The acting user. Transactions will be generated on '. |
24 | 'behalf of this user.'), |
25 | ), |
26 | array( |
27 | 'name' => 'project', |
28 | 'param' => 'slug', |
29 | 'help' => pht('The project slug.'), |
30 | ), |
31 | array( |
32 | 'name' => 'column', |
33 | 'param' => 'name', |
34 | 'help' => pht( |
35 | 'The destination column. All matching tasks will be moved to '. |
36 | 'this column on the project workboard.'), |
37 | ), |
38 | array( |
39 | 'name' => 'dry-run', |
40 | 'help' => pht( |
41 | 'If this flag is specified, the script will not perform any '. |
42 | 'writes but rather will output the intended operations to the '. |
43 | 'console for verification.'), |
44 | ), |
45 | )); |
46 | |
47 | |
48 | $username = $args->getArg('user'); |
49 | if (!$username) { |
50 | echo pht('You must specify an acting user.')."\n"; |
51 | exit(1); |
52 | } |
53 | $viewer = id(new PhabricatorPeopleQuery()) |
54 | ->setViewer(PhabricatorUser::getOmnipotentUser()) |
55 | ->withUsernames(array($args->getArg('user'))) |
56 | ->executeOne(); |
57 | if (!$viewer) { |
58 | throw new Exception(pht("User '%s' not found!", $username)); |
59 | } |
60 | |
61 | $project_slug = $args->getArg('project'); |
62 | if (!$project_slug) { |
63 | echo pht('You must specify a project.')."\n"; |
64 | exit(1); |
65 | } |
66 | $project = id(new PhabricatorProjectQuery()) |
67 | ->setViewer($viewer) |
68 | ->withSlugs(array($project_slug)) |
69 | ->executeOne(); |
70 | if (!$project) { |
71 | throw new Exception(pht("Project '#%s' not found!", $project_slug)); |
72 | } |
73 | |
74 | $column_name = $args->getArg('column'); |
75 | if (!$column_name) { |
76 | echo pht('You must specify a column.')."\n"; |
77 | exit(1); |
78 | } |
79 | $column = id(new PhabricatorProjectColumnQuery()) |
80 | ->setViewer($viewer) |
81 | ->withProjectPHIDs(array($project->getPHID())) |
82 | ->withNames(array($column_name)) |
83 | ->executeOne(); |
84 | if (!$column) { |
85 | throw new Exception(pht("Column '%s' not found!", $column_name)); |
86 | } |
87 | |
88 | $task_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( |
89 | $project->getPHID(), |
90 | PhabricatorProjectProjectHasObjectEdgeType::EDGECONST); |
91 | |
92 | $tasks = id(new ManiphestTaskQuery()) |
93 | ->setViewer($viewer) |
94 | ->withPHIDs($task_phids) |
95 | ->withStatus(ManiphestTaskQuery::STATUS_RESOLVED) |
96 | ->execute(); |
97 | |
98 | $console = PhutilConsole::getConsole(); |
99 | $editor = id(new ManiphestTransactionEditor()) |
100 | ->setActor($viewer) |
101 | ->setContentSource( |
102 | PhabricatorContentSource::newForSource( |
103 | PhabricatorContentSource::SOURCE_UNKNOWN, |
104 | array())); |
105 | |
106 | foreach ($tasks as $task) { |
107 | $position = id(new PhabricatorProjectColumnPositionQuery()) |
108 | ->setViewer($viewer) |
109 | ->withBoardPHIDs(array($column->getProjectPHID())) |
110 | ->withObjectPHIDs(array($task->getPHID())) |
111 | ->executeOne(); |
112 | if (!$position) { |
113 | throw new Exception( |
114 | pht('Position not found for task %s!', $task->getPHID())); |
115 | } |
116 | |
117 | if ($position->getColumnPHID() == $column->getPHID()) { |
118 | $console->writeOut( |
119 | pht( |
120 | "Task %s (%s) does not need to be moved.\n", |
121 | $task->getPHID(), |
122 | $task->getMonogram())); |
123 | continue; |
124 | } |
125 | |
126 | if ($args->getArg('dry-run')) { |
127 | $console->writeOut( |
128 | pht( |
129 | "Task %s (%s) would be moved from %s to %s.\n", |
130 | $task->getPHID(), |
131 | $task->getMonogram(), |
132 | $position->getColumnPHID(), |
133 | $column->getPHID())); |
134 | continue; |
135 | } |
136 | |
137 | $xactions = array(); |
138 | $xactions[] = id(new ManiphestTransaction()) |
139 | ->setTransactionType(ManiphestTransaction::TYPE_PROJECT_COLUMN) |
140 | ->setOldValue( |
141 | array( |
142 | 'columnPHIDs' => array($position->getColumnPHID()), |
143 | 'projectPHID' => $position->getBoardPHID(), |
144 | )) |
145 | ->setNewValue( |
146 | array( |
147 | 'columnPHIDs' => array($column->getPHID()), |
148 | 'projectPHID' => $column->getProjectPHID(), |
149 | )); |
150 | |
151 | $editor->applyTransactions($task, $xactions); |
152 | $console->writeOut( |
153 | pht( |
154 | "Task %s (%s) moved from %s to %s.\n", |
155 | $task->getPHID(), |
156 | $task->getMonogram(), |
157 | $position->getColumnPHID(), |
158 | $column->getPHID())); |
159 | } |
160 | |
161 | $console->writeOut(pht('Done!')."\n"); |