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

Store authors on image macros

Summary:
Currently, the author of an image macro is read from the attached file. This is messy and necessitates a join, and is not always correct. Instead, store the data when the macro is created.

This lays the groundwork for generalizing ApplicationSearch here. Ref T2625.

Test Plan: Migrated existing macros, created a new macro, checked web UI.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

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

+72 -34
+2
resources/sql/patches/20130529.macroauthor.sql
··· 1 + ALTER TABLE {$NAMESPACE}_file.file_imagemacro 2 + ADD authorPHID VARCHAR(64) COLLATE utf8_bin AFTER phid;
+39
resources/sql/patches/20130529.macroauthormig.php
··· 1 + <?php 2 + 3 + echo "Migrating macro authors...\n"; 4 + foreach (new LiskMigrationIterator(new PhabricatorFileImageMacro()) as $macro) { 5 + echo "Macro #".$macro->getID()."\n"; 6 + 7 + if ($macro->getAuthorPHID()) { 8 + // Already have an author; skip it. 9 + continue; 10 + } 11 + 12 + if (!$macro->getFilePHID()) { 13 + // No valid file; skip it. 14 + continue; 15 + } 16 + 17 + $file = id(new PhabricatorFile())->loadOneWhere( 18 + 'phid = %s', 19 + $macro->getFilePHID()); 20 + 21 + if (!$file) { 22 + // Couldn't load the file; skip it. 23 + continue; 24 + } 25 + 26 + if (!$file->getAuthorPHID()) { 27 + // File has no author; skip it. 28 + continue; 29 + } 30 + 31 + queryfx( 32 + $macro->establishConnection('w'), 33 + 'UPDATE %T SET authorPHID = %s WHERE id = %d', 34 + $macro->getTableName(), 35 + $file->getAuthorPHID(), 36 + $macro->getID()); 37 + } 38 + 39 + echo "Done.\n";
+8 -7
src/applications/macro/controller/PhabricatorMacroEditController.php
··· 29 29 } 30 30 } else { 31 31 $macro = new PhabricatorFileImageMacro(); 32 + $macro->setAuthorPHID($user->getPHID()); 32 33 } 33 34 34 35 $errors = array(); 35 36 $e_name = true; 36 - $e_file = pht('Provide a URL or a file'); 37 + $e_file = null; 37 38 $file = null; 38 39 $can_fetch = PhabricatorEnv::getEnvConfig('security.allow-outbound-http'); 39 40 ··· 97 98 98 99 if (!$macro->getID() && !$file) { 99 100 $errors[] = pht('You must upload an image to create a macro.'); 101 + $e_file = pht('Required'); 100 102 } 101 103 102 104 if (!$errors) { ··· 242 244 ->setUser($request->getUser()); 243 245 244 246 if ($can_fetch) { 245 - $upload_form 246 - ->appendChild( 247 - id(new AphrontFormTextControl()) 248 - ->setLabel(pht('URL')) 249 - ->setName('url') 250 - ->setValue($request->getStr('url'))); 247 + $upload_form->appendChild( 248 + id(new AphrontFormTextControl()) 249 + ->setLabel(pht('URL')) 250 + ->setName('url') 251 + ->setValue($request->getStr('url'))); 251 252 } 252 253 253 254 $upload_form
+12 -10
src/applications/macro/controller/PhabricatorMacroListController.php
··· 56 56 $author_phids = array(); 57 57 } 58 58 59 - $files = mpull($macros, 'getFile'); 60 - if ($files) { 61 - $author_phids += mpull($files, 'getAuthorPHID', 'getAuthorPHID'); 62 - } 59 + $author_phids += mpull($macros, 'getAuthorPHID', 'getAuthorPHID'); 63 60 64 61 $this->loadHandles($author_phids); 65 62 $author_handles = array_select_keys($this->getLoadedHandles(), $authors); ··· 102 99 if ($file) { 103 100 $item->setImageURI($file->getThumb280x210URI()); 104 101 $item->setImageSize(280, 210); 105 - if ($file->getAuthorPHID()) { 106 - $author_handle = $this->getHandle($file->getAuthorPHID()); 107 - $item->appendChild( 108 - pht('Created by %s', $author_handle->renderLink())); 109 - } 110 - $datetime = phabricator_date($file->getDateCreated(), $viewer); 102 + } 103 + 104 + if ($macro->getDateCreated()) { 105 + $datetime = phabricator_date($macro->getDateCreated(), $viewer); 111 106 $item->appendChild( 112 107 phutil_tag( 113 108 'div', 114 109 array(), 115 110 pht('Created on %s', $datetime))); 116 111 } 112 + 113 + if ($macro->getAuthorPHID()) { 114 + $author_handle = $this->getHandle($macro->getAuthorPHID()); 115 + $item->appendChild( 116 + pht('Created by %s', $author_handle->renderLink())); 117 + } 118 + 117 119 $item->setURI($this->getApplicationURI('/view/'.$macro->getID().'/')); 118 120 $item->setHeader($macro->getName()); 119 121
+2 -17
src/applications/macro/query/PhabricatorMacroQuery.php
··· 52 52 53 53 $rows = queryfx_all( 54 54 $conn, 55 - 'SELECT m.* FROM %T m %Q %Q %Q %Q', 55 + 'SELECT m.* FROM %T m %Q %Q %Q', 56 56 $macro_table->getTableName(), 57 - $this->buildJoinClause($conn), 58 57 $this->buildWhereClause($conn), 59 58 $this->buildOrderClause($conn), 60 59 $this->buildLimitClause($conn)); ··· 62 61 return $macro_table->loadAllFromArray($rows); 63 62 } 64 63 65 - protected function buildJoinClause(AphrontDatabaseConnection $conn) { 66 - $joins = array(); 67 - 68 - if ($this->authors) { 69 - $file_table = new PhabricatorFile(); 70 - $joins[] = qsprintf( 71 - $conn, 72 - 'JOIN %T f ON m.filePHID = f.phid', 73 - $file_table->getTableName()); 74 - } 75 - 76 - return implode(' ', $joins); 77 - } 78 - 79 64 protected function buildWhereClause(AphrontDatabaseConnection $conn) { 80 65 $where = array(); 81 66 ··· 96 81 if ($this->authors) { 97 82 $where[] = qsprintf( 98 83 $conn, 99 - 'f.authorPHID IN (%Ls)', 84 + 'm.authorPHID IN (%Ls)', 100 85 $this->authors); 101 86 } 102 87
+1
src/applications/macro/storage/PhabricatorFileImageMacro.php
··· 6 6 PhabricatorApplicationTransactionInterface, 7 7 PhabricatorPolicyInterface { 8 8 9 + protected $authorPHID; 9 10 protected $filePHID; 10 11 protected $phid; 11 12 protected $name;
+8
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1318 1318 'type' => 'sql', 1319 1319 'name' => $this->getPatchPath('20130524.repoxactions.sql'), 1320 1320 ), 1321 + '20130529.macroauthor.sql' => array( 1322 + 'type' => 'sql', 1323 + 'name' => $this->getPatchPath('20130529.macroauthor.sql'), 1324 + ), 1325 + '20130529.macroauthormig.php' => array( 1326 + 'type' => 'php', 1327 + 'name' => $this->getPatchPath('20130529.macroauthormig.php'), 1328 + ), 1321 1329 ); 1322 1330 } 1323 1331 }