@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.

Generate expected schemata for Search

Summary:
Ref T1191. Notable:

- Drops a very old saved query table. See comments inline: plan was to remove it after a year. It's been ~a year and two weeks.
- This has our only fulltext index. I'm not supporting that formally for now, but left a note.
- This has our only MyISAM table. I'm not supporting that explicitly for now, but it shouldn't affect anything. I may deal with this in the future.
- These tables don't actually write directly via Lisk, so there's some fiddling to get the schemata right.

Test Plan: Down to ~250 warnings. No more surplus databases or tables.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T1191

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

+103 -262
+1
resources/sql/autopatches/20140927.schema.01.dropsearchq.sql
··· 1 + DROP TABLE {$NAMESPACE}_search.search_query;
+3 -210
resources/sql/patches/20130913.maniphest.1.migratesearch.php
··· 1 1 <?php 2 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 - // See T1812. This is an old status constant from the time of this migration. 17 - $old_open_status = 0; 18 - 19 - echo "Updating saved Maniphest queries...\n"; 20 - $rows = new LiskRawMigrationIterator($conn_w, 'maniphest_savedquery'); 21 - foreach ($rows as $row) { 22 - $id = $row['id']; 23 - echo "Updating query {$id}...\n"; 24 - 25 - $data = queryfx_one( 26 - $search_conn_w, 27 - 'SELECT parameters FROM %T WHERE queryKey = %s', 28 - $search_table->getTableName(), 29 - $row['queryKey']); 30 - if (!$data) { 31 - echo "Unable to locate query data.\n"; 32 - continue; 33 - } 34 - 35 - $data = json_decode($data['parameters'], true); 36 - if (!is_array($data)) { 37 - echo "Unable to decode query data.\n"; 38 - continue; 39 - } 40 - 41 - if (idx($data, 'view') != 'custom') { 42 - echo "Query is not a custom query.\n"; 43 - continue; 44 - } 45 - 46 - $new_data = array( 47 - 'limit' => 1000, 48 - ); 49 - 50 - if (isset($data['lowPriority']) || isset($data['highPriority'])) { 51 - $lo = idx($data, 'lowPriority'); 52 - $hi = idx($data, 'highPriority'); 53 - 54 - $priorities = array(); 55 - $all = ManiphestTaskPriority::getTaskPriorityMap(); 56 - foreach ($all as $pri => $name) { 57 - if (($lo !== null) && ($pri < $lo)) { 58 - continue; 59 - } 60 - if (($hi !== null) && ($pri > $hi)) { 61 - continue; 62 - } 63 - $priorities[] = $pri; 64 - } 65 - 66 - if (count($priorities) != count($all)) { 67 - $new_data['priorities'] = $priorities; 68 - } 69 - } 70 - 71 - foreach ($data as $key => $value) { 72 - switch ($key) { 73 - case 'fullTextSearch': 74 - if (strlen($value)) { 75 - $new_data['fulltext'] = $value; 76 - } 77 - break; 78 - case 'userPHIDs': 79 - // This was (I think?) one-off data provied to specific hard-coded 80 - // queries. 81 - break; 82 - case 'projectPHIDs': 83 - foreach ($value as $k => $v) { 84 - if ($v === null || $v === ManiphestTaskOwner::PROJECT_NO_PROJECT) { 85 - $new_data['withNoProject'] = true; 86 - unset($value[$k]); 87 - break; 88 - } 89 - } 90 - if ($value) { 91 - $new_data['allProjectPHIDs'] = $value; 92 - } 93 - break; 94 - case 'anyProjectPHIDs': 95 - if ($value) { 96 - $new_data['anyProjectPHIDs'] = $value; 97 - } 98 - break; 99 - case 'anyUserProjectPHIDs': 100 - if ($value) { 101 - $new_data['userProjectPHIDs'] = $value; 102 - } 103 - break; 104 - case 'excludeProjectPHIDs': 105 - if ($value) { 106 - $new_data['excludeProjectPHIDs'] = $value; 107 - } 108 - break; 109 - case 'ownerPHIDs': 110 - foreach ($value as $k => $v) { 111 - if ($v === null || $v === ManiphestTaskOwner::OWNER_UP_FOR_GRABS) { 112 - $new_data['withUnassigned'] = true; 113 - unset($value[$k]); 114 - break; 115 - } 116 - } 117 - if ($value) { 118 - $new_data['assignedPHIDs'] = $value; 119 - } 120 - break; 121 - case 'authorPHIDs': 122 - if ($value) { 123 - $new_data['authorPHIDs'] = $value; 124 - } 125 - break; 126 - case 'taskIDs': 127 - if ($value) { 128 - $new_data['ids'] = $value; 129 - } 130 - break; 131 - case 'status': 132 - $include_open = !empty($value['open']); 133 - $include_closed = !empty($value['closed']); 134 - 135 - if ($include_open xor $include_closed) { 136 - if ($include_open) { 137 - $new_data['statuses'] = array( 138 - $old_open_status, 139 - ); 140 - } else { 141 - $statuses = array(); 142 - foreach (ManiphestTaskStatus::getTaskStatusMap() as $status => $n) { 143 - if ($status != $old_open_status) { 144 - $statuses[] = $status; 145 - } 146 - } 147 - $new_data['statuses'] = $statuses; 148 - } 149 - } 150 - break; 151 - case 'order': 152 - $map = array( 153 - 'priority' => 'priority', 154 - 'updated' => 'updated', 155 - 'created' => 'created', 156 - 'title' => 'title', 157 - ); 158 - if (isset($map[$value])) { 159 - $new_data['order'] = $map[$value]; 160 - } else { 161 - $new_data['order'] = 'priority'; 162 - } 163 - break; 164 - case 'group': 165 - $map = array( 166 - 'priority' => 'priority', 167 - 'owner' => 'assigned', 168 - 'status' => 'status', 169 - 'project' => 'project', 170 - 'none' => 'none', 171 - ); 172 - if (isset($map[$value])) { 173 - $new_data['group'] = $map[$value]; 174 - } else { 175 - $new_data['group'] = 'priority'; 176 - } 177 - break; 178 - } 179 - } 180 - 181 - $saved = id(new PhabricatorSavedQuery()) 182 - ->setEngineClassName('ManiphestTaskSearchEngine'); 183 - 184 - foreach ($new_data as $key => $value) { 185 - $saved->setParameter($key, $value); 186 - } 187 - 188 - try { 189 - $saved->save(); 190 - } catch (AphrontDuplicateKeyQueryException $ex) { 191 - // Ignore this, we just have duplicate saved queries. 192 - } 193 - 194 - $named = id(new PhabricatorNamedQuery()) 195 - ->setEngineClassName('ManiphestTaskSearchEngine') 196 - ->setQueryKey($saved->getQueryKey()) 197 - ->setQueryName($row['name']) 198 - ->setUserPHID($row['userPHID']); 199 - 200 - try { 201 - $named->save(); 202 - } catch (Exception $ex) { 203 - // The user already has this query under another name. This can occur if 204 - // the migration runs twice. 205 - echo "Failed to save named query.\n"; 206 - continue; 207 - } 208 - 209 - echo "OK.\n"; 210 - } 211 - 212 - echo "Done.\n"; 3 + // This was a complex migration that modernized old search queries. It was 4 + // removed after giving installs a year to perform it because it would be 5 + // unreasonably complex to maintain and users can easily recreate queries.
+2 -2
src/__phutil_library_map__.php
··· 2213 2213 'PhabricatorSearchManagementIndexWorkflow' => 'applications/search/management/PhabricatorSearchManagementIndexWorkflow.php', 2214 2214 'PhabricatorSearchManagementWorkflow' => 'applications/search/management/PhabricatorSearchManagementWorkflow.php', 2215 2215 'PhabricatorSearchOrderController' => 'applications/search/controller/PhabricatorSearchOrderController.php', 2216 - 'PhabricatorSearchQuery' => 'applications/search/storage/PhabricatorSearchQuery.php', 2217 2216 'PhabricatorSearchRelationship' => 'applications/search/constants/PhabricatorSearchRelationship.php', 2218 2217 'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php', 2218 + 'PhabricatorSearchSchemaSpec' => 'applications/search/storage/PhabricatorSearchSchemaSpec.php', 2219 2219 'PhabricatorSearchSelectController' => 'applications/search/controller/PhabricatorSearchSelectController.php', 2220 2220 'PhabricatorSearchWorker' => 'applications/search/worker/PhabricatorSearchWorker.php', 2221 2221 'PhabricatorSecurityConfigOptions' => 'applications/config/option/PhabricatorSecurityConfigOptions.php', ··· 5216 5216 'PhabricatorSearchManagementIndexWorkflow' => 'PhabricatorSearchManagementWorkflow', 5217 5217 'PhabricatorSearchManagementWorkflow' => 'PhabricatorManagementWorkflow', 5218 5218 'PhabricatorSearchOrderController' => 'PhabricatorSearchBaseController', 5219 - 'PhabricatorSearchQuery' => 'PhabricatorSearchDAO', 5220 5219 'PhabricatorSearchResultView' => 'AphrontView', 5220 + 'PhabricatorSearchSchemaSpec' => 'PhabricatorConfigSchemaSpec', 5221 5221 'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController', 5222 5222 'PhabricatorSearchWorker' => 'PhabricatorWorker', 5223 5223 'PhabricatorSecurityConfigOptions' => 'PhabricatorApplicationConfigOptions',
+19
src/applications/search/storage/PhabricatorNamedQuery.php
··· 12 12 protected $isDisabled = 0; 13 13 protected $sequence = 0; 14 14 15 + public function getConfiguration() { 16 + return array( 17 + self::CONFIG_COLUMN_SCHEMA => array( 18 + 'engineClassName' => 'text128', 19 + 'queryName' => 'text255', 20 + 'queryKey' => 'bytes12', 21 + 'isBuiltin' => 'bool', 22 + 'isDisabled' => 'bool', 23 + 'sequence' => 'uint32', 24 + ), 25 + self::CONFIG_KEY_SCHEMA => array( 26 + 'key_userquery' => array( 27 + 'columns' => array('userPHID', 'engineClassName', 'queryKey'), 28 + 'unique' => true, 29 + ), 30 + ), 31 + ) + parent::getConfiguration(); 32 + } 33 + 15 34 public function getSortKey() { 16 35 return sprintf('~%010d%010d', $this->sequence, $this->getID()); 17 36 }
+10
src/applications/search/storage/PhabricatorSavedQuery.php
··· 12 12 self::CONFIG_SERIALIZATION => array( 13 13 'parameters' => self::SERIALIZATION_JSON, 14 14 ), 15 + self::CONFIG_COLUMN_SCHEMA => array( 16 + 'engineClassName' => 'text255', 17 + 'queryKey' => 'bytes12', 18 + ), 19 + self::CONFIG_KEY_SCHEMA => array( 20 + 'key_queryKey' => array( 21 + 'columns' => array('queryKey'), 22 + 'unique' => true, 23 + ), 24 + ), 15 25 ) + parent::getConfiguration(); 16 26 } 17 27
-47
src/applications/search/storage/PhabricatorSearchQuery.php
··· 1 - <?php 2 - 3 - /** 4 - * Obsolete storage for saved search parameters. This class is no longer used; 5 - * it was obsoleted by the introduction of {@class:PhabricatorSavedQuery}. 6 - * 7 - * This class is retained only because one of the migrations 8 - * (`20130913.maniphest.1.migratesearch.php`) relies on it to migrate old saved 9 - * Maniphest searches to new infrastructure. We can remove this class and the 10 - * corresponding migration after installs have had a reasonable amount of time 11 - * to perform it. 12 - * 13 - * TODO: Remove this class after 2014-09-13, roughly. 14 - * 15 - * @deprecated 16 - */ 17 - final class PhabricatorSearchQuery extends PhabricatorSearchDAO { 18 - 19 - protected $query; 20 - protected $parameters = array(); 21 - protected $queryKey; 22 - 23 - public function getConfiguration() { 24 - return array( 25 - self::CONFIG_SERIALIZATION => array( 26 - 'parameters' => self::SERIALIZATION_JSON, 27 - ), 28 - ) + parent::getConfiguration(); 29 - } 30 - 31 - public function setParameter($parameter, $value) { 32 - $this->parameters[$parameter] = $value; 33 - return $this; 34 - } 35 - 36 - public function getParameter($parameter, $default = null) { 37 - return idx($this->parameters, $parameter, $default); 38 - } 39 - 40 - public function save() { 41 - if (!$this->getQueryKey()) { 42 - $this->setQueryKey(Filesystem::readRandomCharacters(12)); 43 - } 44 - return parent::save(); 45 - } 46 - 47 - }
+9
src/applications/search/storage/PhabricatorSearchSchemaSpec.php
··· 1 + <?php 2 + 3 + final class PhabricatorSearchSchemaSpec extends PhabricatorConfigSchemaSpec { 4 + 5 + public function buildSchemata() { 6 + $this->buildLiskSchemata('PhabricatorSearchDAO'); 7 + } 8 + 9 + }
+16 -1
src/applications/search/storage/document/PhabricatorSearchDocument.php
··· 2 2 3 3 final class PhabricatorSearchDocument extends PhabricatorSearchDAO { 4 4 5 - protected $phid; 6 5 protected $documentType; 7 6 protected $documentTitle; 8 7 protected $documentCreated; ··· 12 11 return array( 13 12 self::CONFIG_TIMESTAMPS => false, 14 13 self::CONFIG_IDS => self::IDS_MANUAL, 14 + self::CONFIG_COLUMN_SCHEMA => array( 15 + 'documentType' => 'text4', 16 + 'documentTitle' => 'text255', 17 + 'documentCreated' => 'epoch', 18 + 'documentModified' => 'epoch', 19 + ), 20 + self::CONFIG_KEY_SCHEMA => array( 21 + 'key_phid' => null, 22 + 'PRIMARY' => array( 23 + 'columns' => array('phid'), 24 + 'unique' => true, 25 + ), 26 + 'documentCreated' => array( 27 + 'columns' => array('documentCreated'), 28 + ), 29 + ), 15 30 ) + parent::getConfiguration(); 16 31 } 17 32
+22 -1
src/applications/search/storage/document/PhabricatorSearchDocumentField.php
··· 2 2 3 3 final class PhabricatorSearchDocumentField extends PhabricatorSearchDAO { 4 4 5 - protected $phid; 5 + protected $phidType; 6 6 protected $field; 7 7 protected $auxPHID; 8 8 protected $corpus; ··· 11 11 return array( 12 12 self::CONFIG_TIMESTAMPS => false, 13 13 self::CONFIG_IDS => self::IDS_MANUAL, 14 + self::CONFIG_COLUMN_SCHEMA => array( 15 + 'phidType' => 'text4', 16 + 'field' => 'text4', 17 + 'auxPHID' => 'phid?', 18 + 'corpus' => 'text?', 19 + ), 20 + self::CONFIG_KEY_SCHEMA => array( 21 + 'key_phid' => null, 22 + 'phid' => array( 23 + 'columns' => array('phid'), 24 + ), 25 + 26 + // NOTE: This is a fulltext index! Be careful! 27 + 'corpus' => array( 28 + 'columns' => array('corpus'), 29 + ), 30 + ), 14 31 ) + parent::getConfiguration(); 32 + } 33 + 34 + public function getIDKey() { 35 + return 'phid'; 15 36 } 16 37 17 38 }
+21 -1
src/applications/search/storage/document/PhabricatorSearchDocumentRelationship.php
··· 2 2 3 3 final class PhabricatorSearchDocumentRelationship extends PhabricatorSearchDAO { 4 4 5 - protected $phid; 6 5 protected $relatedPHID; 7 6 protected $relation; 8 7 protected $relatedType; ··· 12 11 return array( 13 12 self::CONFIG_TIMESTAMPS => false, 14 13 self::CONFIG_IDS => self::IDS_MANUAL, 14 + self::CONFIG_COLUMN_SCHEMA => array( 15 + 'relation' => 'text4', 16 + 'relatedType' => 'text4', 17 + 'relatedTime' => 'epoch', 18 + ), 19 + self::CONFIG_KEY_SCHEMA => array( 20 + 'key_phid' => null, 21 + 'phid' => array( 22 + 'columns' => array('phid'), 23 + ), 24 + 'relatedPHID' => array( 25 + 'columns' => array('relatedPHID', 'relation'), 26 + ), 27 + 'relation' => array( 28 + 'columns' => array('relation', 'relatedPHID'), 29 + ), 30 + ), 15 31 ) + parent::getConfiguration(); 32 + } 33 + 34 + public function getIDKey() { 35 + return 'phid'; 16 36 } 17 37 18 38 }