1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

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
This commit is contained in:
Bob Trahan 2013-07-08 17:06:49 -07:00
parent 7456a9bc0c
commit 2d87bb29ac
8 changed files with 84 additions and 7 deletions

View file

@ -0,0 +1,46 @@
<?php
echo "Populating Legalpad Documents with ",
"titles, recentContributorPHIDs, and contributorCounts...\n";
$table = new LegalpadDocument();
$table->openTransaction();
foreach (new LiskMigrationIterator($table) as $document) {
$updated = false;
$id = $document->getID();
echo "Document {$id}: ";
if (!$document->getTitle()) {
$document_body = id(new LegalpadDocumentBody())
->loadOneWhere('phid = %s', $document->getDocumentBodyPHID());
$title = $document_body->getTitle();
$document->setTitle($title);
$updated = true;
echo "Added title: $title\n";
} else {
echo "-\n";
}
if (!$document->getContributorCount() ||
!$document->getRecentContributorPHIDs()) {
$updated = true;
$type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_CONTRIBUTOR;
$contributors = PhabricatorEdgeQuery::loadDestinationPHIDs(
$document->getPHID(),
$type);
$document->setRecentContributorPHIDs(array_slice($contributors, 0, 3));
echo "Added recent contributor phids.\n";
$document->setContributorCount(count($contributors));
echo "Added contributor count.\n";
}
if (!$updated) {
echo "-\n";
continue;
}
$document->save();
}
$table->saveTransaction();
echo "Done.\n";

View file

@ -0,0 +1,8 @@
ALTER TABLE {$NAMESPACE}_legalpad.legalpad_document
ADD recentContributorPHIDs LONGTEXT NOT NULL COLLATE utf8_bin AFTER phid,
ADD contributorCount INT UNSIGNED NOT NULL DEFAULT 0 AFTER phid,
ADD title VARCHAR(255) NOT NULL COLLATE utf8_general_ci AFTER phid;
ALTER TABLE {$NAMESPACE}_legalpad.legalpad_document
DROP KEY key_creator,
ADD KEY key_creator (creatorPHID, dateModified);

View file

@ -21,6 +21,8 @@ final class LegalpadDocumentEditController extends LegalpadController {
$document = id(new LegalpadDocument())
->setVersions(0)
->setCreatorPHID($user->getPHID())
->setContributorCount(0)
->setRecentContributorPHIDs(array())
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
->setEditPolicy(PhabricatorPolicies::POLICY_USER);
$body = id(new LegalpadDocumentBody())

View file

@ -29,18 +29,18 @@ final class LegalpadDocumentListController extends LegalpadController
$user = $this->getRequest()->getUser();
$contributors = array_mergev(mpull($documents, 'getContributors'));
$contributors = array_mergev(
mpull($documents, 'getRecentContributorPHIDs'));
$this->loadHandles($contributors);
$list = new PhabricatorObjectItemListView();
$list->setUser($user);
foreach ($documents as $document) {
$document_body = $document->getDocumentBody();
$last_updated = phabricator_date($document->getDateModified(), $user);
$updater = $this->getHandle(
$document_body->getCreatorPHID())->renderLink();
reset($document->getRecentContributorPHIDs()))->renderLink();
$title = $document_body->getTitle();
$title = $document->getTitle();
$item = id(new PhabricatorObjectItemView())
->setObjectName('L'.$document->getID())

View file

@ -56,6 +56,7 @@ final class LegalpadDocumentEditor
switch ($xaction->getTransactionType()) {
case LegalpadTransactionType::TYPE_TITLE:
$object->setTitle($xaction->getNewValue());
$body = $object->getDocumentBody();
$body->setTitle($xaction->getNewValue());
$this->setIsContribution(true);
@ -86,7 +87,6 @@ final class LegalpadDocumentEditor
$body->save();
$object->setDocumentBodyPHID($body->getPHID());
$object->save();
$actor = $this->getActor();
$type = PhabricatorEdgeConfig::TYPE_CONTRIBUTED_TO_OBJECT;
@ -94,6 +94,15 @@ final class LegalpadDocumentEditor
->addEdge($actor->getPHID(), $type, $object->getPHID())
->setActor($actor)
->save();
$type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_CONTRIBUTOR;
$contributors = PhabricatorEdgeQuery::loadDestinationPHIDs(
$object->getPHID(),
$type);
$object->setRecentContributorPHIDs(array_slice($contributors, 0, 3));
$object->setContributorCount(count($contributors));
$object->save();
}
}

View file

@ -24,8 +24,6 @@ final class LegalpadDocumentSearchEngine
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new LegalpadDocumentQuery())
->needDocumentBodies(true)
->needContributors(true)
->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()))
->withContributorPHIDs($saved->getParameter('contributorPHIDs', array()));

View file

@ -10,6 +10,9 @@ final class LegalpadDocument extends LegalpadDAO
PhabricatorApplicationTransactionInterface {
protected $phid;
protected $title;
protected $contributorCount;
protected $recentContributorPHIDs = array();
protected $creatorPHID;
protected $versions;
protected $documentBodyPHID;
@ -23,6 +26,9 @@ final class LegalpadDocument extends LegalpadDAO
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_SERIALIZATION => array(
'recentContributorPHIDs' => self::SERIALIZATION_JSON,
),
) + parent::getConfiguration();
}

View file

@ -1422,6 +1422,14 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'type' => 'php',
'name' => $this->getPatchPath('legalpad-mailkey-populate.php'),
),
'20130703.legalpaddocdenorm.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('20130703.legalpaddocdenorm.sql'),
),
'20130703.legalpaddocdenorm.php' => array(
'type' => 'php',
'name' => $this->getPatchPath('20130703.legalpaddocdenorm.php'),
),
);
}
}