2015-05-15 02:05:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhameBlogEditor
|
|
|
|
extends PhabricatorApplicationTransactionEditor {
|
|
|
|
|
|
|
|
public function getEditorApplicationClass() {
|
|
|
|
return 'PhabricatorPhameApplication';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEditorObjectsDescription() {
|
2015-11-07 02:40:13 +01:00
|
|
|
return pht('Phame Blogs');
|
2015-05-15 02:05:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTransactionTypes() {
|
|
|
|
$types = parent::getTransactionTypes();
|
|
|
|
|
|
|
|
$types[] = PhameBlogTransaction::TYPE_NAME;
|
|
|
|
$types[] = PhameBlogTransaction::TYPE_DESCRIPTION;
|
|
|
|
$types[] = PhameBlogTransaction::TYPE_DOMAIN;
|
2015-11-21 17:51:07 +01:00
|
|
|
$types[] = PhameBlogTransaction::TYPE_STATUS;
|
2015-05-15 02:05:58 +02:00
|
|
|
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
|
|
|
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
|
|
|
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomTransactionOldValue(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case PhameBlogTransaction::TYPE_NAME:
|
|
|
|
return $object->getName();
|
|
|
|
case PhameBlogTransaction::TYPE_DESCRIPTION:
|
|
|
|
return $object->getDescription();
|
|
|
|
case PhameBlogTransaction::TYPE_DOMAIN:
|
|
|
|
return $object->getDomain();
|
2015-11-21 17:51:07 +01:00
|
|
|
case PhameBlogTransaction::TYPE_STATUS:
|
|
|
|
return $object->getStatus();
|
2015-05-15 02:05:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomTransactionNewValue(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case PhameBlogTransaction::TYPE_NAME:
|
|
|
|
case PhameBlogTransaction::TYPE_DESCRIPTION:
|
2015-11-21 17:51:07 +01:00
|
|
|
case PhameBlogTransaction::TYPE_STATUS:
|
2015-05-15 02:05:58 +02:00
|
|
|
return $xaction->getNewValue();
|
2015-12-30 21:52:53 +01:00
|
|
|
case PhameBlogTransaction::TYPE_DOMAIN:
|
|
|
|
$domain = $xaction->getNewValue();
|
|
|
|
if (!strlen($xaction->getNewValue())) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $domain;
|
2015-05-15 02:05:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function applyCustomInternalTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case PhameBlogTransaction::TYPE_NAME:
|
|
|
|
return $object->setName($xaction->getNewValue());
|
|
|
|
case PhameBlogTransaction::TYPE_DESCRIPTION:
|
|
|
|
return $object->setDescription($xaction->getNewValue());
|
|
|
|
case PhameBlogTransaction::TYPE_DOMAIN:
|
|
|
|
return $object->setDomain($xaction->getNewValue());
|
2015-11-21 17:51:07 +01:00
|
|
|
case PhameBlogTransaction::TYPE_STATUS:
|
|
|
|
return $object->setStatus($xaction->getNewValue());
|
2015-05-15 02:05:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::applyCustomInternalTransaction($object, $xaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function applyCustomExternalTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case PhameBlogTransaction::TYPE_NAME:
|
|
|
|
case PhameBlogTransaction::TYPE_DESCRIPTION:
|
|
|
|
case PhameBlogTransaction::TYPE_DOMAIN:
|
2015-11-21 17:51:07 +01:00
|
|
|
case PhameBlogTransaction::TYPE_STATUS:
|
2015-05-15 02:05:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::applyCustomExternalTransaction($object, $xaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function validateTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
$type,
|
|
|
|
array $xactions) {
|
|
|
|
|
|
|
|
$errors = parent::validateTransaction($object, $type, $xactions);
|
|
|
|
|
2015-11-07 20:29:20 +01:00
|
|
|
|
2015-05-15 02:05:58 +02:00
|
|
|
switch ($type) {
|
|
|
|
case PhameBlogTransaction::TYPE_NAME:
|
|
|
|
$missing = $this->validateIsEmptyTextField(
|
|
|
|
$object->getName(),
|
|
|
|
$xactions);
|
|
|
|
|
|
|
|
if ($missing) {
|
|
|
|
$error = new PhabricatorApplicationTransactionValidationError(
|
|
|
|
$type,
|
|
|
|
pht('Required'),
|
|
|
|
pht('Name is required.'),
|
|
|
|
nonempty(last($xactions), null));
|
|
|
|
|
|
|
|
$error->setIsMissingFieldError(true);
|
|
|
|
$errors[] = $error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PhameBlogTransaction::TYPE_DOMAIN:
|
2015-11-07 20:29:20 +01:00
|
|
|
if (!$xactions) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-15 02:05:58 +02:00
|
|
|
$custom_domain = last($xactions)->getNewValue();
|
|
|
|
if (empty($custom_domain)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
list($error_label, $error_text) =
|
|
|
|
$object->validateCustomDomain($custom_domain);
|
|
|
|
if ($error_label) {
|
|
|
|
$error = new PhabricatorApplicationTransactionValidationError(
|
|
|
|
$type,
|
|
|
|
$error_label,
|
|
|
|
$error_text,
|
|
|
|
nonempty(last($xactions), null));
|
|
|
|
$errors[] = $error;
|
|
|
|
}
|
|
|
|
if ($object->getViewPolicy() != PhabricatorPolicies::POLICY_PUBLIC) {
|
|
|
|
$error_text = pht(
|
|
|
|
'For custom domains to work, the blog must have a view policy of '.
|
|
|
|
'public.');
|
|
|
|
$error = new PhabricatorApplicationTransactionValidationError(
|
|
|
|
PhabricatorTransactions::TYPE_VIEW_POLICY,
|
|
|
|
pht('Invalid Policy'),
|
|
|
|
$error_text,
|
|
|
|
nonempty(last($xactions), null));
|
|
|
|
$errors[] = $error;
|
|
|
|
}
|
|
|
|
$duplicate_blog = id(new PhameBlogQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withDomain($custom_domain)
|
|
|
|
->executeOne();
|
|
|
|
if ($duplicate_blog && $duplicate_blog->getID() != $object->getID()) {
|
|
|
|
$error = new PhabricatorApplicationTransactionValidationError(
|
|
|
|
$type,
|
|
|
|
pht('Not Unique'),
|
|
|
|
pht('Domain must be unique; another blog already has this domain.'),
|
|
|
|
nonempty(last($xactions), null));
|
|
|
|
$errors[] = $error;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function shouldSendMail(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
array $xactions) {
|
2015-11-08 16:50:01 +01:00
|
|
|
return true;
|
2015-05-15 02:05:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function shouldPublishFeedStory(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
array $xactions) {
|
2015-11-08 16:50:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getMailTo(PhabricatorLiskDAO $object) {
|
|
|
|
$phids = array();
|
|
|
|
$phids[] = $this->requireActor()->getPHID();
|
|
|
|
$phids[] = $object->getCreatorPHID();
|
|
|
|
|
|
|
|
return $phids;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
|
|
|
|
$phid = $object->getPHID();
|
|
|
|
$name = $object->getName();
|
|
|
|
|
|
|
|
return id(new PhabricatorMetaMTAMail())
|
|
|
|
->setSubject($name)
|
|
|
|
->addHeader('Thread-Topic', $phid);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
|
|
|
|
return id(new PhameBlogReplyHandler())
|
|
|
|
->setMailReceiver($object);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildMailBody(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
array $xactions) {
|
|
|
|
|
|
|
|
$body = parent::buildMailBody($object, $xactions);
|
|
|
|
|
|
|
|
$body->addLinkSection(
|
|
|
|
pht('BLOG DETAIL'),
|
|
|
|
PhabricatorEnv::getProductionURI($object->getViewURI()));
|
|
|
|
|
|
|
|
return $body;
|
2015-05-15 02:05:58 +02:00
|
|
|
}
|
|
|
|
|
2015-11-08 16:50:01 +01:00
|
|
|
public function getMailTagsMap() {
|
|
|
|
return array(
|
|
|
|
PhameBlogTransaction::MAILTAG_DETAILS =>
|
|
|
|
pht("A blog's details change."),
|
|
|
|
PhameBlogTransaction::MAILTAG_SUBSCRIBERS =>
|
|
|
|
pht("A blog's subscribers change."),
|
|
|
|
PhameBlogTransaction::MAILTAG_OTHER =>
|
|
|
|
pht('Other blog activity not listed above occurs.'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getMailSubjectPrefix() {
|
|
|
|
return '[Phame]';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-15 02:05:58 +02:00
|
|
|
protected function supportsSearch() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|