Changeset View
Changeset View
Standalone View
Standalone View
resources/sql/patches/20130703.legalpaddocdenorm.php
| <?php | <?php | ||||
| echo 'Populating Legalpad Documents with ', | echo pht( | ||||
| "titles, recentContributorPHIDs, and contributorCounts...\n"; | "Populating Legalpad Documents with titles, %s, and %s...\n", | ||||
| 'recentContributorPHIDs', | |||||
| 'contributorCounts'); | |||||
| $table = new LegalpadDocument(); | $table = new LegalpadDocument(); | ||||
| $table->openTransaction(); | $table->openTransaction(); | ||||
| foreach (new LiskMigrationIterator($table) as $document) { | foreach (new LiskMigrationIterator($table) as $document) { | ||||
| $updated = false; | $updated = false; | ||||
| $id = $document->getID(); | $id = $document->getID(); | ||||
| echo "Document {$id}: "; | echo pht('Document %d: ', $id); | ||||
| if (!$document->getTitle()) { | if (!$document->getTitle()) { | ||||
| $document_body = id(new LegalpadDocumentBody()) | $document_body = id(new LegalpadDocumentBody()) | ||||
| ->loadOneWhere('phid = %s', $document->getDocumentBodyPHID()); | ->loadOneWhere('phid = %s', $document->getDocumentBodyPHID()); | ||||
| $title = $document_body->getTitle(); | $title = $document_body->getTitle(); | ||||
| $document->setTitle($title); | $document->setTitle($title); | ||||
| $updated = true; | $updated = true; | ||||
| echo "Added title: $title\n"; | echo pht('Added title: %s', $title)."\n"; | ||||
| } else { | } else { | ||||
| echo "-\n"; | echo "-\n"; | ||||
| } | } | ||||
| if (!$document->getContributorCount() || | if (!$document->getContributorCount() || | ||||
| !$document->getRecentContributorPHIDs()) { | !$document->getRecentContributorPHIDs()) { | ||||
| $updated = true; | $updated = true; | ||||
| $type = PhabricatorObjectHasContributorEdgeType::EDGECONST; | $type = PhabricatorObjectHasContributorEdgeType::EDGECONST; | ||||
| $contributors = PhabricatorEdgeQuery::loadDestinationPHIDs( | $contributors = PhabricatorEdgeQuery::loadDestinationPHIDs( | ||||
| $document->getPHID(), | $document->getPHID(), | ||||
| $type); | $type); | ||||
| $document->setRecentContributorPHIDs(array_slice($contributors, 0, 3)); | $document->setRecentContributorPHIDs(array_slice($contributors, 0, 3)); | ||||
| echo "Added recent contributor phids.\n"; | echo pht('Added recent contributor PHIDs.')."\n"; | ||||
| $document->setContributorCount(count($contributors)); | $document->setContributorCount(count($contributors)); | ||||
| echo "Added contributor count.\n"; | echo pht('Added contributor count.')."\n"; | ||||
| } | } | ||||
| if (!$updated) { | if (!$updated) { | ||||
| echo "-\n"; | echo "-\n"; | ||||
| continue; | continue; | ||||
| } | } | ||||
| $document->save(); | $document->save(); | ||||
| } | } | ||||
| $table->saveTransaction(); | $table->saveTransaction(); | ||||
| echo "Done.\n"; | echo pht('Done.')."\n"; | ||||