@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Migrate old Maniphest custom queries to new query infrastructure

Summary: Ref T2625. EVERYONE LOVES MIGRATIONS!!!

Test Plan:
- Created and migrated a query with every field, verified results were preserved.
- Created and migrated a query using "noproject" and "upforgrabs" magic, verified results were preserved.

Here's the pre-migration "everything" query:

{F58110}

Here it is after migration:

{F58111}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

Differential Revision: https://secure.phabricator.com/D6977

+212
+208
resources/sql/patches/20130913.maniphest.1.migratesearch.php
··· 1 + <?php 2 + 3 + // NOTE: If you need to make any significant updates to this to deal with 4 + // future changes to objects, it's probably better to just wipe the whole 5 + // migration. This feature doesn't see overwhelming amounts of use, and users 6 + // who do use it can recreate their queries fairly easily with the new 7 + // interface. By the time this needs to be updated, the vast majority of 8 + // users who it impacts will likely have migrated their data already. 9 + 10 + $table = new ManiphestTask(); 11 + $conn_w = $table->establishConnection('w'); 12 + 13 + $search_table = new PhabricatorSearchQuery(); 14 + $search_conn_w = $search_table->establishConnection('w'); 15 + 16 + echo "Updating saved Maniphest queries...\n"; 17 + $rows = new LiskRawMigrationIterator($conn_w, 'maniphest_savedquery'); 18 + foreach ($rows as $row) { 19 + $id = $row['id']; 20 + echo "Updating query {$id}...\n"; 21 + 22 + $data = queryfx_one( 23 + $search_conn_w, 24 + 'SELECT parameters FROM %T WHERE queryKey = %s', 25 + $search_table->getTableName(), 26 + $row['queryKey']); 27 + if (!$data) { 28 + echo "Unable to locate query data.\n"; 29 + continue; 30 + } 31 + 32 + $data = json_decode($data['parameters'], true); 33 + if (!is_array($data)) { 34 + echo "Unable to decode query data.\n"; 35 + continue; 36 + } 37 + 38 + if (idx($data, 'view') != 'custom') { 39 + echo "Query is not a custom query.\n"; 40 + continue; 41 + } 42 + 43 + $new_data = array( 44 + 'limit' => 1000, 45 + ); 46 + 47 + if (isset($data['lowPriority']) || isset($data['highPriority'])) { 48 + $lo = idx($data, 'lowPriority'); 49 + $hi = idx($data, 'highPriority'); 50 + 51 + $priorities = array(); 52 + $all = ManiphestTaskPriority::getTaskPriorityMap(); 53 + foreach ($all as $pri => $name) { 54 + if (($lo !== null) && ($pri < $lo)) { 55 + continue; 56 + } 57 + if (($hi !== null) && ($pri > $hi)) { 58 + continue; 59 + } 60 + $priorities[] = $pri; 61 + } 62 + 63 + if (count($priorities) != count($all)) { 64 + $new_data['priorities'] = $priorities; 65 + } 66 + } 67 + 68 + foreach ($data as $key => $value) { 69 + switch ($key) { 70 + case 'fullTextSearch': 71 + if (strlen($value)) { 72 + $new_data['fulltext'] = $value; 73 + } 74 + break; 75 + case 'userPHIDs': 76 + // This was (I think?) one-off data provied to specific hard-coded 77 + // queries. 78 + break; 79 + case 'projectPHIDs': 80 + foreach ($value as $k => $v) { 81 + if ($v === null || $v === ManiphestTaskOwner::PROJECT_NO_PROJECT) { 82 + $new_data['withNoProject'] = true; 83 + unset($value[$k]); 84 + break; 85 + } 86 + } 87 + if ($value) { 88 + $new_data['allProjectPHIDs'] = $value; 89 + } 90 + break; 91 + case 'anyProjectPHIDs': 92 + if ($value) { 93 + $new_data['anyProjectPHIDs'] = $value; 94 + } 95 + break; 96 + case 'anyUserProjectPHIDs': 97 + if ($value) { 98 + $new_data['userProjectPHIDs'] = $value; 99 + } 100 + break; 101 + case 'excludeProjectPHIDs': 102 + if ($value) { 103 + $new_data['excludeProjectPHIDs'] = $value; 104 + } 105 + break; 106 + case 'ownerPHIDs': 107 + foreach ($value as $k => $v) { 108 + if ($v === null || $v === ManiphestTaskOwner::OWNER_UP_FOR_GRABS) { 109 + $new_data['withUnassigned'] = true; 110 + unset($value[$k]); 111 + break; 112 + } 113 + } 114 + if ($value) { 115 + $new_data['assignedPHIDs'] = $value; 116 + } 117 + break; 118 + case 'authorPHIDs': 119 + if ($value) { 120 + $new_data['authorPHIDs'] = $value; 121 + } 122 + break; 123 + case 'taskIDs': 124 + if ($value) { 125 + $new_data['ids'] = $value; 126 + } 127 + break; 128 + case 'status': 129 + $include_open = !empty($value['open']); 130 + $include_closed = !empty($value['closed']); 131 + 132 + if ($include_open xor $include_closed) { 133 + if ($include_open) { 134 + $new_data['statuses'] = array( 135 + ManiphestTaskStatus::STATUS_OPEN, 136 + ); 137 + } else { 138 + $statuses = array(); 139 + foreach (ManiphestTaskStatus::getTaskStatusMap() as $status => $n) { 140 + if ($status != ManiphestTaskStatus::STATUS_OPEN) { 141 + $statuses[] = $status; 142 + } 143 + } 144 + $new_data['statuses'] = $statuses; 145 + } 146 + } 147 + break; 148 + case 'order': 149 + $map = array( 150 + 'priority' => 'priority', 151 + 'created' => 'created', 152 + 'title' => 'title', 153 + ); 154 + if (isset($map[$value])) { 155 + $new_data['order'] = $map[$value]; 156 + } else { 157 + $new_data['order'] = 'priority'; 158 + } 159 + break; 160 + case 'group': 161 + $map = array( 162 + 'priority' => 'priority', 163 + 'owner' => 'assigned', 164 + 'status' => 'status', 165 + 'project' => 'project', 166 + 'none' => 'none', 167 + ); 168 + if (isset($map[$value])) { 169 + $new_data['group'] = $map[$value]; 170 + } else { 171 + $new_data['group'] = 'priority'; 172 + } 173 + break; 174 + } 175 + } 176 + 177 + $saved = id(new PhabricatorSavedQuery()) 178 + ->setEngineClassName('ManiphestTaskSearchEngine'); 179 + 180 + foreach ($new_data as $key => $value) { 181 + $saved->setParameter($key, $value); 182 + } 183 + 184 + try { 185 + $saved->save(); 186 + } catch (AphrontQueryDuplicateKeyException $ex) { 187 + // Ignore this, we just have duplicate saved queries. 188 + } 189 + 190 + $named = id(new PhabricatorNamedQuery()) 191 + ->setEngineClassName('ManiphestTaskSearchEngine') 192 + ->setQueryKey($saved->getQueryKey()) 193 + ->setQueryName($row['name']) 194 + ->setUserPHID($row['userPHID']); 195 + 196 + try { 197 + $named->save(); 198 + } catch (Exception $ex) { 199 + // The user already has this query under another name. This can occur if 200 + // the migration runs twice. 201 + echo "Failed to save named query.\n"; 202 + continue; 203 + } 204 + 205 + echo "OK.\n"; 206 + } 207 + 208 + echo "Done.\n";
+4
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1588 1588 'type' => 'php', 1589 1589 'name' => $this->getPatchPath('20130912.maniphest.4.fillindex.php'), 1590 1590 ), 1591 + '20130913.maniphest.1.migratesearch.php' => array( 1592 + 'type' => 'php', 1593 + 'name' => $this->getPatchPath('20130913.maniphest.1.migratesearch.php'), 1594 + ), 1591 1595 ); 1592 1596 } 1593 1597 }