Skip to content

Commit

Permalink
Modularize content sources
Browse files Browse the repository at this point in the history
Summary:
Ref T10537. For Nuance, I want to introduce new sources (like "GitHub" or "GitHub via Nuance" or something) but this needs to modularize eventually.

Split ContentSource apart so applications can add new content sources.

Test Plan:
This change has huge surface area, so I'll hold it until post-release. I think it's fairly safe (and if it does break anything, the breaks should be fatals, not anything subtle or difficult to fix), there's just no reason not to hold it for a few hours.

- Viewed new module page.
- Grepped for all removed functions/constants.
- Viewed some transactions.
- Hovered over timestamps to get content source details.
- Added a comment via Conduit.
- Added a comment via web.
- Ran `bin/storage upgrade --namespace XXXXX --no-quickstart -f` to re-run all historic migrations.
- Generated some objects with `bin/lipsum`.
- Ran a bulk job on some tasks.
- Ran unit tests.

{F1190182}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10537

Differential Revision: https://secure.phabricator.com/D15521
  • Loading branch information
epriestley committed Mar 26, 2016
1 parent d784d9c commit 601aaa5
Show file tree
Hide file tree
Showing 83 changed files with 495 additions and 265 deletions.
3 changes: 1 addition & 2 deletions resources/sql/autopatches/20140211.dx.2.migcommenttext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
$rows = new LiskRawMigrationIterator($conn_w, 'differential_comment');

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize();
PhabricatorOldWorldContentSource::SOURCECONST)->serialize();

echo pht('Migrating Differential comment text to modern storage...')."\n";
foreach ($rows as $row) {
Expand Down
3 changes: 1 addition & 2 deletions resources/sql/autopatches/20140212.dx.1.armageddon.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
$rows = new LiskRawMigrationIterator($conn_w, 'differential_comment');

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize();
PhabricatorOldWorldContentSource::SOURCECONST)->serialize();

echo pht('Migrating Differential comments to modern storage...')."\n";
foreach ($rows as $row) {
Expand Down
3 changes: 1 addition & 2 deletions resources/sql/autopatches/20140722.audit.3.miginlines.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
echo pht('Migrating Audit inline comments to new format...')."\n";

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize();
PhabricatorOldWorldContentSource::SOURCECONST)->serialize();

$rows = new LiskRawMigrationIterator($conn_w, $src_table);
foreach ($rows as $row) {
Expand Down
3 changes: 1 addition & 2 deletions resources/sql/autopatches/20140722.audit.4.migtext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
$rows = new LiskRawMigrationIterator($conn_w, 'audit_comment');

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize();
PhabricatorOldWorldContentSource::SOURCECONST)->serialize();

echo pht('Migrating Audit comment text to modern storage...')."\n";
foreach ($rows as $row) {
Expand Down
3 changes: 1 addition & 2 deletions resources/sql/autopatches/20140725.audit.1.migxactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
$rows = new LiskRawMigrationIterator($conn_w, 'audit_comment');

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize();
PhabricatorOldWorldContentSource::SOURCECONST)->serialize();

echo pht('Migrating Audit comments to modern storage...')."\n";
foreach ($rows as $row) {
Expand Down
5 changes: 2 additions & 3 deletions resources/sql/patches/20130715.votecomments.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@
PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST,
PhabricatorSlowvotePollPHIDType::TYPECONST);

$source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize();
$content_source = PhabricatorContentSource::newForSource(
PhabricatorOldWorldContentSource::SOURCECONST)->serialize();

queryfx(
$conn_w,
Expand Down
6 changes: 2 additions & 4 deletions resources/sql/patches/20130728.ponderxcomment.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
1,
$row['content'],
PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize(),
PhabricatorOldWorldContentSource::SOURCECONST)->serialize(),
0,
$row['dateCreated'],
$row['dateModified']);
Expand All @@ -73,8 +72,7 @@
'null',
'null',
PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize(),
PhabricatorOldWorldContentSource::SOURCECONST)->serialize(),
'[]',
$row['dateCreated'],
$row['dateModified']);
Expand Down
3 changes: 1 addition & 2 deletions resources/sql/patches/20130801.pastexactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
'null',
$row['filePHID'],
PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize(),
PhabricatorOldWorldContentSource::SOURCECONST)->serialize(),
'[]',
$row['dateCreated'],
$row['dateCreated'],
Expand Down
3 changes: 1 addition & 2 deletions resources/sql/patches/20130926.dinline.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
echo pht('Migrating Differential inline comments to new format...')."\n";

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize();
PhabricatorOldWorldContentSource::SOURCECONST)->serialize();

$rows = new LiskRawMigrationIterator($conn_w, $src_table);
foreach ($rows as $row) {
Expand Down
3 changes: 1 addition & 2 deletions resources/sql/patches/20131020.pxactionmig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
echo pht('Migrating Project transactions to new format...')."\n";

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array())->serialize();
PhabricatorOldWorldContentSource::SOURCECONST)->serialize();

$rows = new LiskRawMigrationIterator($conn_w, $src_table);
foreach ($rows as $row) {
Expand Down
32 changes: 30 additions & 2 deletions src/__phutil_library_map__.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
abstract class AlmanacManagementWorkflow
extends PhabricatorManagementWorkflow {


protected function loadServices(array $names) {
if (!$names) {
return array();
Expand Down Expand Up @@ -37,7 +36,7 @@ protected function updateServiceLock(AlmanacService $service, $lock) {
$editor = id(new AlmanacServiceEditor())
->setActor($this->getViewer())
->setActingAsPHID($almanac_phid)
->setContentSource(PhabricatorContentSource::newConsoleSource())
->setContentSource($this->newContentSource())
->setContinueOnMissingFields(true);

$editor->applyTransactions($service, array($xaction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function isHidden() {

public function getTransactionCommentForSave() {
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array());
PhabricatorOldWorldContentSource::SOURCECONST);

$this->proxy
->setViewPolicy('public')
Expand Down
5 changes: 5 additions & 0 deletions src/applications/conduit/protocol/ConduitAPIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public function getIsClusterRequest() {
return $this->isClusterRequest;
}

public function newContentSource() {
return PhabricatorContentSource::newForSource(
PhabricatorConduitContentSource::SOURCECONST);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function createRoom(

id(new ConpherenceEditor())
->setActor($creator)
->setContentSource(PhabricatorContentSource::newConsoleSource())
->setContentSource($this->newContentSource())
->setContinueOnNoEffect(true)
->applyTransactions($conpherence, $xactions);

Expand All @@ -166,7 +166,7 @@ private function changeEditPolicy(

id(new ConpherenceEditor())
->setActor($actor)
->setContentSource(PhabricatorContentSource::newConsoleSource())
->setContentSource($this->newContentSource())
->setContinueOnNoEffect(true)
->applyTransactions($room, $xactions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected function addParticipants(
);
$editor = id(new ConpherenceEditor())
->setActor($actor)
->setContentSource(PhabricatorContentSource::newConsoleSource())
->setContentSource($this->newContentSource())
->applyTransactions($conpherence, $xactions);

}
Expand All @@ -31,7 +31,7 @@ protected function removeParticipants(
);
$editor = id(new ConpherenceEditor())
->setActor($actor)
->setContentSource(PhabricatorContentSource::newConsoleSource())
->setContentSource($this->newContentSource())
->applyTransactions($conpherence, $xactions);
}

Expand All @@ -45,7 +45,7 @@ protected function addMessageWithFile(

$editor = id(new ConpherenceEditor())
->setActor($actor)
->setContentSource(PhabricatorContentSource::newConsoleSource());
->setContentSource($this->newContentSource());

$xactions = $editor->generateTransactionsFromText(
$actor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function execute(ConduitAPIRequest $request) {
$participant_phids,
$title,
$message,
PhabricatorContentSource::newFromConduitRequest($request));
$request->newContentSource());

if ($errors) {
foreach ($errors as $error_code) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function execute(ConduitAPIRequest $request) {
throw new ConduitException('ERR_USAGE_ROOM_NOT_FOUND');
}

$source = PhabricatorContentSource::newFromConduitRequest($request);
$source = $request->newContentSource();
$editor = id(new ConpherenceEditor())
->setContentSource($source)
->setActor($user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) {
$conpherence->attachParticipants($participants);
}

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_EMAIL,
array(
'id' => $mail->getID(),
));
$content_source = $mail->newContentSource();

$editor = id(new ConpherenceEditor())
->setActor($user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ protected function execute(ConduitAPIRequest $request) {
->setTransactionType(DifferentialTransaction::TYPE_ACTION)
->setNewValue(DifferentialAction::ACTION_CLOSE);

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_CONDUIT,
array());
$content_source = $request->newContentSource();

$editor = id(new DifferentialTransactionEditor())
->setActor($viewer)
->setContentSourceFromConduitRequest($request)
->setContentSource($request->newContentSource())
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function applyFieldEdit(

$editor = id(new DifferentialTransactionEditor())
->setActor($viewer)
->setContentSourceFromConduitRequest($request)
->setContentSource($request->newContentSource())
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function execute(ConduitAPIRequest $request) {
$editor = id(new DifferentialTransactionEditor())
->setActor($viewer)
->setDisableEmail($request->getValue('silent'))
->setContentSourceFromConduitRequest($request)
->setContentSource($request->newContentSource())
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function execute(ConduitAPIRequest $request) {

id(new DifferentialDiffEditor())
->setActor($viewer)
->setContentSourceFromConduitRequest($request)
->setContentSource($request->newContentSource())
->setContinueOnNoEffect(true)
->applyTransactions($diff, $xactions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function execute(ConduitAPIRequest $request) {

id(new DifferentialDiffEditor())
->setActor($viewer)
->setContentSourceFromConduitRequest($request)
->setContentSource($request->newContentSource())
->setContinueOnNoEffect(true)
->setLookupRepository(false) // respect user choice
->applyTransactions($diff, $xactions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ public function execute(PhutilArgumentParser $args) {
->setViewer($viewer)
->setAuthorPHID($differential_phid);

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_CONSOLE,
array());
$content_source = $this->newContentSource();

$extraction_engine->updateRevisionWithCommit(
$revision,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public function __clone() {

public function getTransactionCommentForSave() {
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LEGACY,
array());
PhabricatorOldWorldContentSource::SOURCECONST);

$this->proxy
->setViewPolicy('public')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function execute(ConduitAPIRequest $request) {

id(new PhabricatorAuditEditor())
->setActor($request->getUser())
->setContentSourceFromConduitRequest($request)
->setContentSource($request->newContentSource())
->setDisableEmail($request->getValue('silent'))
->setContinueOnMissingFields(true)
->applyTransactions($commit, $xactions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,7 @@ private function updateBuildable(HarbormasterBuildable $buildable) {
->getPHID();

$daemon_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_DAEMON,
array());
PhabricatorDaemonContentSource::SOURCECONST);

$editor = $object->getApplicationTransactionEditor()
->setActor($viewer)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

final class PhabricatorHeraldContentSource
extends PhabricatorContentSource {

const SOURCECONST = 'herald';

public function getSourceName() {
return pht('Herald');
}

public function getSourceDescription() {
return pht('Changes triggered by Herald rules.');
}

}
5 changes: 3 additions & 2 deletions src/applications/herald/field/HeraldContentSourceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ public function getHeraldFieldConditions() {
}

public function getHeraldFieldValueType($condition) {
$map = PhabricatorContentSource::getSourceNameMap();
$map = PhabricatorContentSource::getAllContentSources();
$map = mpull($map, 'getSourceName');
asort($map);

return id(new HeraldSelectFieldValue())
->setKey(self::FIELDCONST)
->setDefault(PhabricatorContentSource::SOURCE_WEB)
->setDefault(PhabricatorWebContentSource::SOURCECONST)
->setOptions($map);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ protected function loadRandomUser() {

protected function getLipsumContentSource() {
return PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_LIPSUM,
array());
PhabricatorLipsumContentSource::SOURCECONST);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private function applyTaskTransactions(
ManiphestTask $task,
array $xactions) {

$content_source = PhabricatorContentSource::newConsoleSource();
$content_source = $this->newContentSource();

$editor = id(new ManiphestTransactionEditor())
->setActor($viewer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ protected function applyRequest(
return;
}

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_CONDUIT,
array());
$content_source = $request->newContentSource();

$editor = id(new ManiphestTransactionEditor())
->setActor($request->getUser())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public function generateObject() {
->setSubPriority($this->generateTaskSubPriority())
->setTitle($this->generateTitle());

$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_UNKNOWN,
array());
$content_source = $this->getLipsumContentSource();

$template = new ManiphestTransaction();
// Accumulate Transactions
Expand Down
Loading

0 comments on commit 601aaa5

Please sign in to comment.