Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
<?php
|
|
|
|
|
2013-03-01 02:15:09 +01:00
|
|
|
abstract class PackageMail extends PhabricatorMail {
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
|
|
|
|
protected $package;
|
|
|
|
protected $handles;
|
|
|
|
protected $owners;
|
|
|
|
protected $paths;
|
|
|
|
protected $mailTo;
|
|
|
|
|
2012-06-14 05:52:10 +02:00
|
|
|
public function __construct(PhabricatorOwnersPackage $package) {
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
$this->package = $package;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected function getVerb();
|
|
|
|
|
|
|
|
abstract protected function isNewThread();
|
|
|
|
|
|
|
|
final protected function getPackage() {
|
|
|
|
return $this->package;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function getHandles() {
|
|
|
|
return $this->handles;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function getOwners() {
|
|
|
|
return $this->owners;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function getPaths() {
|
|
|
|
return $this->paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function getMailTo() {
|
|
|
|
return $this->mailTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function renderPackageTitle() {
|
|
|
|
return $this->getPackage()->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function renderRepoSubSection($repository_phid, $paths) {
|
|
|
|
$handles = $this->getHandles();
|
|
|
|
$section = array();
|
|
|
|
$section[] = ' In repository '.$handles[$repository_phid]->getName().
|
2014-06-10 01:03:58 +02:00
|
|
|
' - '.PhabricatorEnv::getProductionURI($handles[$repository_phid]
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
->getURI());
|
2012-12-07 02:23:56 +01:00
|
|
|
foreach ($paths as $path => $excluded) {
|
|
|
|
$section[] = ' '.($excluded ? 'Excluded' : 'Included').' '.$path;
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return implode("\n", $section);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function needSend() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadData() {
|
|
|
|
$package = $this->getPackage();
|
|
|
|
$owners = $package->loadOwners();
|
|
|
|
$this->owners = $owners;
|
|
|
|
|
|
|
|
$owner_phids = mpull($owners, 'getUserPHID');
|
|
|
|
$primary_owner_phid = $package->getPrimaryOwnerPHID();
|
|
|
|
$mail_to = $owner_phids;
|
|
|
|
if (!in_array($primary_owner_phid, $owner_phids)) {
|
|
|
|
$mail_to[] = $primary_owner_phid;
|
|
|
|
}
|
|
|
|
$this->mailTo = $mail_to;
|
|
|
|
|
2012-12-07 02:23:56 +01:00
|
|
|
$this->paths = array();
|
|
|
|
$repository_paths = mgroup($package->loadPaths(), 'getRepositoryPHID');
|
|
|
|
foreach ($repository_paths as $repository_phid => $paths) {
|
|
|
|
$this->paths[$repository_phid] = mpull($paths, 'getExcluded', 'getPath');
|
|
|
|
}
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
|
2012-06-02 06:41:56 +02:00
|
|
|
$phids = array_merge(
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
$this->mailTo,
|
|
|
|
array($package->getActorPHID()),
|
2012-06-02 06:41:56 +02:00
|
|
|
array_keys($this->paths));
|
2013-09-11 21:27:28 +02:00
|
|
|
$this->handles = id(new PhabricatorHandleQuery())
|
2013-03-01 02:15:09 +01:00
|
|
|
->setViewer($this->getActor())
|
2013-09-11 21:27:28 +02:00
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
final protected function renderSummarySection() {
|
|
|
|
$package = $this->getPackage();
|
|
|
|
$handles = $this->getHandles();
|
|
|
|
$section = array();
|
|
|
|
$section[] = $handles[$package->getActorPHID()]->getName().' '.
|
|
|
|
strtolower($this->getVerb()).' '.$this->renderPackageTitle().'.';
|
|
|
|
$section[] = '';
|
|
|
|
|
|
|
|
$section[] = 'PACKAGE DETAIL';
|
|
|
|
$section[] = ' '.PhabricatorEnv::getProductionURI(
|
|
|
|
'/owners/package/'.$package->getID().'/');
|
|
|
|
|
|
|
|
return implode("\n", $section);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderDescriptionSection() {
|
|
|
|
return "PACKAGE DESCRIPTION\n".
|
|
|
|
' '.$this->getPackage()->getDescription();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderPrimaryOwnerSection() {
|
|
|
|
$handles = $this->getHandles();
|
|
|
|
return "PRIMARY OWNER\n".
|
|
|
|
' '.$handles[$this->getPackage()->getPrimaryOwnerPHID()]->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderOwnersSection() {
|
|
|
|
$handles = $this->getHandles();
|
|
|
|
$owners = $this->getOwners();
|
|
|
|
if (!$owners) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$owners = mpull($owners, 'getUserPHID');
|
|
|
|
$owners = array_select_keys($handles, $owners);
|
|
|
|
$owners = mpull($owners, 'getName');
|
|
|
|
return "OWNERS\n".
|
|
|
|
' '.implode(', ', $owners);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderAuditingEnabledSection() {
|
|
|
|
return "AUDITING ENABLED STATUS\n".
|
|
|
|
' '.($this->getPackage()->getAuditingEnabled() ? 'Enabled' : 'Disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderPathsSection() {
|
|
|
|
$section = array();
|
|
|
|
$section[] = 'PATHS';
|
|
|
|
foreach ($this->paths as $repository_phid => $paths) {
|
|
|
|
$section[] = $this->renderRepoSubSection($repository_phid, $paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode("\n", $section);
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function renderBody() {
|
|
|
|
$body = array();
|
|
|
|
$body[] = $this->renderSummarySection();
|
|
|
|
$body[] = $this->renderDescriptionSection();
|
|
|
|
$body[] = $this->renderPrimaryOwnerSection();
|
|
|
|
$body[] = $this->renderOwnersSection();
|
|
|
|
$body[] = $this->renderAuditingEnabledSection();
|
|
|
|
$body[] = $this->renderPathsSection();
|
|
|
|
$body = array_filter($body);
|
2012-09-27 23:40:56 +02:00
|
|
|
return implode("\n\n", $body)."\n";
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
final public function send() {
|
|
|
|
$mails = $this->prepareMails();
|
|
|
|
|
|
|
|
foreach ($mails as $mail) {
|
|
|
|
$mail->saveAndSend();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function prepareMails() {
|
|
|
|
if (!$this->needSend()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->loadData();
|
|
|
|
|
|
|
|
$package = $this->getPackage();
|
|
|
|
$prefix = PhabricatorEnv::getEnvConfig('metamta.package.subject-prefix');
|
|
|
|
$verb = $this->getVerb();
|
|
|
|
$threading = $this->getMailThreading();
|
|
|
|
list($thread_id, $thread_topic) = $threading;
|
|
|
|
|
|
|
|
$template = id(new PhabricatorMetaMTAMail())
|
2012-06-11 21:21:37 +02:00
|
|
|
->setSubject($this->renderPackageTitle())
|
|
|
|
->setSubjectPrefix($prefix)
|
|
|
|
->setVarySubjectPrefix("[{$verb}]")
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
->setFrom($package->getActorPHID())
|
|
|
|
->setThreadID($thread_id, $this->isNewThread())
|
|
|
|
->addHeader('Thread-Topic', $thread_topic)
|
|
|
|
->setRelatedPHID($package->getPHID())
|
|
|
|
->setIsBulk(true)
|
|
|
|
->setBody($this->renderBody());
|
|
|
|
|
|
|
|
$reply_handler = $this->newReplyHandler();
|
|
|
|
$mails = $reply_handler->multiplexMail(
|
|
|
|
$template,
|
|
|
|
array_select_keys($this->getHandles(), $this->getMailTo()),
|
|
|
|
array());
|
|
|
|
return $mails;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getMailThreading() {
|
|
|
|
return array(
|
|
|
|
'package-'.$this->getPackage()->getPHID(),
|
2012-06-14 05:52:10 +02:00
|
|
|
'Package '.$this->getPackage()->getOriginalName(),
|
Detect package change and send out email
Summary:
For package creation and deletion, send email to all the owners For
package modification, detect important fields such as owners and paths, and then
send out emails to all owners (including deleted owners and current owners)
Also start using transaction for package creation/deletion/modification.
Test Plan:
- tested mail creation and deletion
- tested modification to auditing enabled, primary owners, owners, paths
Reviewers: epriestley, nh, vrana
Reviewed By: epriestley
CC: prithvi, aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2470
2012-05-07 09:19:44 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function newReplyHandler() {
|
|
|
|
$reply_handler = PhabricatorEnv::newObjectFromConfig(
|
|
|
|
'metamta.package.reply-handler');
|
|
|
|
$reply_handler->setMailReceiver($this->getPackage());
|
|
|
|
return $reply_handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|