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

Legalpad - denormalize a field or two from DocumentBody to Document

Summary: this let's the list controller save a query. Fixes T3488. Note didn't bother denormalizing document body at all since I don't think we want to show a snippet.

Test Plan: viewed a list of legalpad documents - yay. viewed a legalpad document - yay. created a legalpad document - yay. edited a legalpad document - yay. edited with N authors - yay.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T3488

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

+84 -7
+46
resources/sql/patches/20130703.legalpaddocdenorm.php
··· 1 + <?php 2 + 3 + echo "Populating Legalpad Documents with ", 4 + "titles, recentContributorPHIDs, and contributorCounts...\n"; 5 + $table = new LegalpadDocument(); 6 + $table->openTransaction(); 7 + 8 + foreach (new LiskMigrationIterator($table) as $document) { 9 + $updated = false; 10 + $id = $document->getID(); 11 + 12 + echo "Document {$id}: "; 13 + if (!$document->getTitle()) { 14 + $document_body = id(new LegalpadDocumentBody()) 15 + ->loadOneWhere('phid = %s', $document->getDocumentBodyPHID()); 16 + $title = $document_body->getTitle(); 17 + $document->setTitle($title); 18 + $updated = true; 19 + echo "Added title: $title\n"; 20 + } else { 21 + echo "-\n"; 22 + } 23 + 24 + if (!$document->getContributorCount() || 25 + !$document->getRecentContributorPHIDs()) { 26 + $updated = true; 27 + $type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_CONTRIBUTOR; 28 + $contributors = PhabricatorEdgeQuery::loadDestinationPHIDs( 29 + $document->getPHID(), 30 + $type); 31 + $document->setRecentContributorPHIDs(array_slice($contributors, 0, 3)); 32 + echo "Added recent contributor phids.\n"; 33 + $document->setContributorCount(count($contributors)); 34 + echo "Added contributor count.\n"; 35 + } 36 + 37 + if (!$updated) { 38 + echo "-\n"; 39 + continue; 40 + } 41 + 42 + $document->save(); 43 + } 44 + 45 + $table->saveTransaction(); 46 + echo "Done.\n";
+8
resources/sql/patches/20130703.legalpaddocdenorm.sql
··· 1 + ALTER TABLE {$NAMESPACE}_legalpad.legalpad_document 2 + ADD recentContributorPHIDs LONGTEXT NOT NULL COLLATE utf8_bin AFTER phid, 3 + ADD contributorCount INT UNSIGNED NOT NULL DEFAULT 0 AFTER phid, 4 + ADD title VARCHAR(255) NOT NULL COLLATE utf8_general_ci AFTER phid; 5 + 6 + ALTER TABLE {$NAMESPACE}_legalpad.legalpad_document 7 + DROP KEY key_creator, 8 + ADD KEY key_creator (creatorPHID, dateModified);
+2
src/applications/legalpad/controller/LegalpadDocumentEditController.php
··· 21 21 $document = id(new LegalpadDocument()) 22 22 ->setVersions(0) 23 23 ->setCreatorPHID($user->getPHID()) 24 + ->setContributorCount(0) 25 + ->setRecentContributorPHIDs(array()) 24 26 ->setViewPolicy(PhabricatorPolicies::POLICY_USER) 25 27 ->setEditPolicy(PhabricatorPolicies::POLICY_USER); 26 28 $body = id(new LegalpadDocumentBody())
+4 -4
src/applications/legalpad/controller/LegalpadDocumentListController.php
··· 29 29 30 30 $user = $this->getRequest()->getUser(); 31 31 32 - $contributors = array_mergev(mpull($documents, 'getContributors')); 32 + $contributors = array_mergev( 33 + mpull($documents, 'getRecentContributorPHIDs')); 33 34 $this->loadHandles($contributors); 34 35 35 36 $list = new PhabricatorObjectItemListView(); 36 37 $list->setUser($user); 37 38 foreach ($documents as $document) { 38 - $document_body = $document->getDocumentBody(); 39 39 $last_updated = phabricator_date($document->getDateModified(), $user); 40 40 $updater = $this->getHandle( 41 - $document_body->getCreatorPHID())->renderLink(); 41 + reset($document->getRecentContributorPHIDs()))->renderLink(); 42 42 43 - $title = $document_body->getTitle(); 43 + $title = $document->getTitle(); 44 44 45 45 $item = id(new PhabricatorObjectItemView()) 46 46 ->setObjectName('L'.$document->getID())
+10 -1
src/applications/legalpad/editor/LegalpadDocumentEditor.php
··· 56 56 57 57 switch ($xaction->getTransactionType()) { 58 58 case LegalpadTransactionType::TYPE_TITLE: 59 + $object->setTitle($xaction->getNewValue()); 59 60 $body = $object->getDocumentBody(); 60 61 $body->setTitle($xaction->getNewValue()); 61 62 $this->setIsContribution(true); ··· 86 87 $body->save(); 87 88 88 89 $object->setDocumentBodyPHID($body->getPHID()); 89 - $object->save(); 90 90 91 91 $actor = $this->getActor(); 92 92 $type = PhabricatorEdgeConfig::TYPE_CONTRIBUTED_TO_OBJECT; ··· 94 94 ->addEdge($actor->getPHID(), $type, $object->getPHID()) 95 95 ->setActor($actor) 96 96 ->save(); 97 + 98 + $type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_CONTRIBUTOR; 99 + $contributors = PhabricatorEdgeQuery::loadDestinationPHIDs( 100 + $object->getPHID(), 101 + $type); 102 + $object->setRecentContributorPHIDs(array_slice($contributors, 0, 3)); 103 + $object->setContributorCount(count($contributors)); 104 + 105 + $object->save(); 97 106 } 98 107 } 99 108
-2
src/applications/legalpad/query/LegalpadDocumentSearchEngine.php
··· 24 24 25 25 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 26 26 $query = id(new LegalpadDocumentQuery()) 27 - ->needDocumentBodies(true) 28 - ->needContributors(true) 29 27 ->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array())) 30 28 ->withContributorPHIDs($saved->getParameter('contributorPHIDs', array())); 31 29
+6
src/applications/legalpad/storage/LegalpadDocument.php
··· 10 10 PhabricatorApplicationTransactionInterface { 11 11 12 12 protected $phid; 13 + protected $title; 14 + protected $contributorCount; 15 + protected $recentContributorPHIDs = array(); 13 16 protected $creatorPHID; 14 17 protected $versions; 15 18 protected $documentBodyPHID; ··· 23 26 public function getConfiguration() { 24 27 return array( 25 28 self::CONFIG_AUX_PHID => true, 29 + self::CONFIG_SERIALIZATION => array( 30 + 'recentContributorPHIDs' => self::SERIALIZATION_JSON, 31 + ), 26 32 ) + parent::getConfiguration(); 27 33 } 28 34
+8
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1422 1422 'type' => 'php', 1423 1423 'name' => $this->getPatchPath('legalpad-mailkey-populate.php'), 1424 1424 ), 1425 + '20130703.legalpaddocdenorm.sql' => array( 1426 + 'type' => 'sql', 1427 + 'name' => $this->getPatchPath('20130703.legalpaddocdenorm.sql'), 1428 + ), 1429 + '20130703.legalpaddocdenorm.php' => array( 1430 + 'type' => 'php', 1431 + 'name' => $this->getPatchPath('20130703.legalpaddocdenorm.php'), 1432 + ), 1425 1433 ); 1426 1434 } 1427 1435 }