1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

Make Phame Header and Profile Image Transactional

Summary: Ref T9360. This makes these transactional.

Test Plan: Set new header, delete header. Set new profile image, reset profile image.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T9360

Differential Revision: https://secure.phabricator.com/D16217
This commit is contained in:
Chad Little 2016-07-01 11:21:05 -07:00
parent 7b5e84282f
commit f26374241a
4 changed files with 126 additions and 14 deletions

View file

@ -53,12 +53,25 @@ final class PhameBlogHeaderPictureController
if (!$errors) {
if ($delete_header) {
$blog->setHeaderImagePHID(null);
$new_value = null;
} else {
$blog->setHeaderImagePHID($file->getPHID());
$file->attachToObject($blog->getPHID());
$new_value = $file->getPHID();
}
$blog->save();
$xactions = array();
$xactions[] = id(new PhameBlogTransaction())
->setTransactionType(PhameBlogTransaction::TYPE_HEADERIMAGE)
->setNewValue($new_value);
$editor = id(new PhameBlogEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true);
$editor->applyTransactions($blog, $xactions);
return id(new AphrontRedirectResponse())->setURI($blog_uri);
}
}

View file

@ -68,12 +68,25 @@ final class PhameBlogProfilePictureController
if (!$errors) {
if ($is_default) {
$blog->setProfileImagePHID(null);
$new_value = null;
} else {
$blog->setProfileImagePHID($xformed->getPHID());
$xformed->attachToObject($blog->getPHID());
$new_value = $xformed->getPHID();
}
$blog->save();
$xactions = array();
$xactions[] = id(new PhameBlogTransaction())
->setTransactionType(PhameBlogTransaction::TYPE_PROFILEIMAGE)
->setNewValue($new_value);
$editor = id(new PhameBlogEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true);
$editor->applyTransactions($blog, $xactions);
return id(new AphrontRedirectResponse())->setURI($blog_uri);
}
}

View file

@ -21,6 +21,9 @@ final class PhameBlogEditor
$types[] = PhameBlogTransaction::TYPE_PARENTSITE;
$types[] = PhameBlogTransaction::TYPE_PARENTDOMAIN;
$types[] = PhameBlogTransaction::TYPE_STATUS;
$types[] = PhameBlogTransaction::TYPE_HEADERIMAGE;
$types[] = PhameBlogTransaction::TYPE_PROFILEIMAGE;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
@ -44,6 +47,10 @@ final class PhameBlogEditor
return $object->getParentSite();
case PhameBlogTransaction::TYPE_PARENTDOMAIN:
return $object->getParentDomain();
case PhameBlogTransaction::TYPE_PROFILEIMAGE:
return $object->getProfileImagePHID();
case PhameBlogTransaction::TYPE_HEADERIMAGE:
return $object->getHeaderImagePHID();
case PhameBlogTransaction::TYPE_STATUS:
return $object->getStatus();
}
@ -59,7 +66,8 @@ final class PhameBlogEditor
case PhameBlogTransaction::TYPE_DESCRIPTION:
case PhameBlogTransaction::TYPE_STATUS:
case PhameBlogTransaction::TYPE_PARENTSITE:
case PhameBlogTransaction::TYPE_PARENTDOMAIN:
case PhameBlogTransaction::TYPE_PROFILEIMAGE:
case PhameBlogTransaction::TYPE_HEADERIMAGE:
return $xaction->getNewValue();
case PhameBlogTransaction::TYPE_FULLDOMAIN:
$domain = $xaction->getNewValue();
@ -92,6 +100,10 @@ final class PhameBlogEditor
}
$object->setDomainFullURI($new_value);
return;
case PhameBlogTransaction::TYPE_PROFILEIMAGE:
return $object->setProfileImagePHID($xaction->getNewValue());
case PhameBlogTransaction::TYPE_HEADERIMAGE:
return $object->setHeaderImagePHID($xaction->getNewValue());
case PhameBlogTransaction::TYPE_STATUS:
return $object->setStatus($xaction->getNewValue());
case PhameBlogTransaction::TYPE_PARENTSITE:
@ -114,6 +126,8 @@ final class PhameBlogEditor
case PhameBlogTransaction::TYPE_FULLDOMAIN:
case PhameBlogTransaction::TYPE_PARENTSITE:
case PhameBlogTransaction::TYPE_PARENTDOMAIN:
case PhameBlogTransaction::TYPE_HEADERIMAGE:
case PhameBlogTransaction::TYPE_PROFILEIMAGE:
case PhameBlogTransaction::TYPE_STATUS:
return;
}

View file

@ -10,6 +10,8 @@ final class PhameBlogTransaction
const TYPE_STATUS = 'phame.blog.status';
const TYPE_PARENTSITE = 'phame.blog.parent.site';
const TYPE_PARENTDOMAIN = 'phame.blog.parent.domain';
const TYPE_PROFILEIMAGE = 'phame.blog.header.image';
const TYPE_HEADERIMAGE = 'phame.blog.profile.image';
const MAILTAG_DETAILS = 'phame-blog-details';
const MAILTAG_SUBSCRIBERS = 'phame-blog-subscribers';
@ -34,6 +36,22 @@ final class PhameBlogTransaction
return parent::shouldHide();
}
public function getRequiredHandlePHIDs() {
$old = $this->getOldValue();
$new = $this->getNewValue();
$req_phids = array();
switch ($this->getTransactionType()) {
case self::TYPE_PROFILEIMAGE:
case self::TYPE_HEADERIMAGE:
$req_phids[] = $old;
$req_phids[] = $new;
break;
}
return array_merge($req_phids, parent::getRequiredHandlePHIDs());
}
public function getIcon() {
$old = $this->getOldValue();
$new = $this->getNewValue();
@ -48,6 +66,10 @@ final class PhameBlogTransaction
case self::TYPE_DESCRIPTION:
case self::TYPE_FULLDOMAIN:
return 'fa-pencil';
case self::TYPE_HEADERIMAGE:
return 'fa-image';
case self::TYPE_PROFILEIMAGE:
return 'fa-star';
case self::TYPE_STATUS:
if ($new == PhameBlog::STATUS_ARCHIVED) {
return 'fa-ban';
@ -88,6 +110,8 @@ final class PhameBlogTransaction
case self::TYPE_FULLDOMAIN:
case self::TYPE_PARENTSITE:
case self::TYPE_PARENTDOMAIN:
case self::TYPE_PROFILEIMAGE:
case self::TYPE_HEADERIMAGE:
$tags[] = self::MAILTAG_DETAILS;
break;
default:
@ -172,6 +196,42 @@ final class PhameBlogTransaction
$new);
}
break;
case self::TYPE_HEADERIMAGE:
if (!$old) {
return pht(
"%s set this blog's header image to %s.",
$this->renderHandleLink($author_phid),
$this->renderHandleLink($new));
} else if (!$new) {
return pht(
"%s removed this blog's header image.",
$this->renderHandleLink($author_phid));
} else {
return pht(
"%s updated this blog's header image from %s to %s.",
$this->renderHandleLink($author_phid),
$this->renderHandleLink($old),
$this->renderHandleLink($new));
}
break;
case self::TYPE_PROFILEIMAGE:
if (!$old) {
return pht(
"%s set this blog's profile image to %s.",
$this->renderHandleLink($author_phid),
$this->renderHandleLink($new));
} else if (!$new) {
return pht(
"%s removed this blog's profile image.",
$this->renderHandleLink($author_phid));
} else {
return pht(
"%s updated this blog's profile image from %s to %s.",
$this->renderHandleLink($author_phid),
$this->renderHandleLink($old),
$this->renderHandleLink($new));
}
break;
case self::TYPE_STATUS:
switch ($new) {
case PhameBlog::STATUS_ACTIVE:
@ -248,6 +308,18 @@ final class PhameBlogTransaction
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
case self::TYPE_HEADERIMAGE:
return pht(
'%s updated the header image for %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
case self::TYPE_PROFILEIMAGE:
return pht(
'%s updated the profile image for %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
case self::TYPE_STATUS:
switch ($new) {
case PhameBlog::STATUS_ACTIVE: