1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Make X-Herald-Rules header sticky

Summary:
This isn't terribly elegant but it solves the problem without loss of
generality. We can pursue a more finessed solution later if it seems prudent.

Test Plan:
Created a revision matched by a blanket herald rule, and then commented on it.
Comment email had X-Herald-Rules header in it.

Reviewed By: aran
Reviewers: aran, tuomaspelkonen, jungejason
CC: aran
Differential Revision: 218
This commit is contained in:
epriestley 2011-05-02 21:04:06 -07:00
parent 8c031db32b
commit 8370f93048
7 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,4 @@
CREATE TABLE phabricator_herald.herald_savedheader (
phid varchar(64) binary not null primary key,
header varchar(255) not null
) ENGINE=InnoDB;

View file

@ -304,6 +304,9 @@ class DifferentialCommentEditor {
->loadHandles();
$actor_handle = $handles[$this->actorPHID];
$xherald_header = HeraldTranscript::loadXHeraldRulesHeader(
$revision->getPHID());
id(new DifferentialCommentMail(
$revision,
$actor_handle,
@ -316,6 +319,7 @@ class DifferentialCommentEditor {
array($revision->getAuthorPHID())))
->setCCPHIDs($revision->getCCPHIDs())
->setChangedByCommit($this->getChangedByCommit())
->setXHeraldRulesHeader($xherald_header)
->send();
$event_data = array(

View file

@ -13,6 +13,7 @@ phutil_require_module('phabricator', 'applications/differential/mail/comment');
phutil_require_module('phabricator', 'applications/differential/storage/changeset');
phutil_require_module('phabricator', 'applications/differential/storage/comment');
phutil_require_module('phabricator', 'applications/differential/storage/inlinecomment');
phutil_require_module('phabricator', 'applications/herald/storage/transcript/base');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'infrastructure/daemon/timeline/storage/event');

View file

@ -212,6 +212,10 @@ class DifferentialRevisionEditor {
$xscript_phid = $xscript->getPHID();
$xscript_header = $xscript->getXHeraldRulesHeader();
HeraldTranscript::saveXHeraldRulesHeader(
$revision->getPHID(),
$xscript_header);
$sub = array(
'rev' => array(),
'ccs' => $adapter->getCCsAddedByHerald(),

View file

@ -13,6 +13,7 @@ phutil_require_module('phabricator', 'applications/differential/storage/comment'
phutil_require_module('phabricator', 'applications/differential/storage/revision');
phutil_require_module('phabricator', 'applications/herald/adapter/differential');
phutil_require_module('phabricator', 'applications/herald/engine/engine');
phutil_require_module('phabricator', 'applications/herald/storage/transcript/base');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'applications/search/index/indexer/differential');
phutil_require_module('phabricator', 'infrastructure/env');

View file

@ -33,6 +33,8 @@ class HeraldTranscript extends HeraldDAO {
protected $objectPHID;
protected $dryRun;
const TABLE_SAVED_HEADER = 'herald_savedheader';
public function getXHeraldRulesHeader() {
$ids = array();
foreach ($this->applyTranscripts as $xscript) {
@ -57,6 +59,29 @@ class HeraldTranscript extends HeraldDAO {
return implode(', ', $ids);
}
public static function saveXHeraldRulesHeader($phid, $header) {
queryfx(
id(new HeraldTranscript())->establishConnection('w'),
'INSERT INTO %T (phid, header) VALUES (%s, %s)
ON DUPLICATE KEY UPDATE header = VALUES(header)',
self::TABLE_SAVED_HEADER,
$phid,
$header);
}
public static function loadXHeraldRulesHeader($phid) {
$header = queryfx_one(
id(new HeraldTranscript())->establishConnection('r'),
'SELECT * FROM %T WHERE phid = %s',
self::TABLE_SAVED_HEADER,
$phid);
if ($header) {
return idx($header, 'header');
}
return null;
}
protected function getConfiguration() {
// Ugh. Too much of a mess to deal with.
return array(

View file

@ -8,6 +8,7 @@
phutil_require_module('phabricator', 'applications/herald/storage/base');
phutil_require_module('phabricator', 'applications/phid/storage/phid');
phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phutil', 'utils');