Skip to content

Commit f263742

Browse files
author
Chad Little
committedJul 1, 2016
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
1 parent 7b5e842 commit f263742

File tree

4 files changed

+126
-14
lines changed

4 files changed

+126
-14
lines changed
 

‎src/applications/phame/controller/blog/PhameBlogHeaderPictureController.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,25 @@ public function handleRequest(AphrontRequest $request) {
5353

5454
if (!$errors) {
5555
if ($delete_header) {
56-
$blog->setHeaderImagePHID(null);
56+
$new_value = null;
5757
} else {
58-
$blog->setHeaderImagePHID($file->getPHID());
5958
$file->attachToObject($blog->getPHID());
59+
$new_value = $file->getPHID();
6060
}
61-
$blog->save();
61+
62+
$xactions = array();
63+
$xactions[] = id(new PhameBlogTransaction())
64+
->setTransactionType(PhameBlogTransaction::TYPE_HEADERIMAGE)
65+
->setNewValue($new_value);
66+
67+
$editor = id(new PhameBlogEditor())
68+
->setActor($viewer)
69+
->setContentSourceFromRequest($request)
70+
->setContinueOnMissingFields(true)
71+
->setContinueOnNoEffect(true);
72+
73+
$editor->applyTransactions($blog, $xactions);
74+
6275
return id(new AphrontRedirectResponse())->setURI($blog_uri);
6376
}
6477
}

‎src/applications/phame/controller/blog/PhameBlogProfilePictureController.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,25 @@ public function handleRequest(AphrontRequest $request) {
6868

6969
if (!$errors) {
7070
if ($is_default) {
71-
$blog->setProfileImagePHID(null);
71+
$new_value = null;
7272
} else {
73-
$blog->setProfileImagePHID($xformed->getPHID());
7473
$xformed->attachToObject($blog->getPHID());
74+
$new_value = $xformed->getPHID();
7575
}
76-
$blog->save();
76+
77+
$xactions = array();
78+
$xactions[] = id(new PhameBlogTransaction())
79+
->setTransactionType(PhameBlogTransaction::TYPE_PROFILEIMAGE)
80+
->setNewValue($new_value);
81+
82+
$editor = id(new PhameBlogEditor())
83+
->setActor($viewer)
84+
->setContentSourceFromRequest($request)
85+
->setContinueOnMissingFields(true)
86+
->setContinueOnNoEffect(true);
87+
88+
$editor->applyTransactions($blog, $xactions);
89+
7790
return id(new AphrontRedirectResponse())->setURI($blog_uri);
7891
}
7992
}

‎src/applications/phame/editor/PhameBlogEditor.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public function getTransactionTypes() {
2121
$types[] = PhameBlogTransaction::TYPE_PARENTSITE;
2222
$types[] = PhameBlogTransaction::TYPE_PARENTDOMAIN;
2323
$types[] = PhameBlogTransaction::TYPE_STATUS;
24+
$types[] = PhameBlogTransaction::TYPE_HEADERIMAGE;
25+
$types[] = PhameBlogTransaction::TYPE_PROFILEIMAGE;
26+
2427
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
2528
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
2629

@@ -44,6 +47,10 @@ protected function getCustomTransactionOldValue(
4447
return $object->getParentSite();
4548
case PhameBlogTransaction::TYPE_PARENTDOMAIN:
4649
return $object->getParentDomain();
50+
case PhameBlogTransaction::TYPE_PROFILEIMAGE:
51+
return $object->getProfileImagePHID();
52+
case PhameBlogTransaction::TYPE_HEADERIMAGE:
53+
return $object->getHeaderImagePHID();
4754
case PhameBlogTransaction::TYPE_STATUS:
4855
return $object->getStatus();
4956
}
@@ -59,7 +66,8 @@ protected function getCustomTransactionNewValue(
5966
case PhameBlogTransaction::TYPE_DESCRIPTION:
6067
case PhameBlogTransaction::TYPE_STATUS:
6168
case PhameBlogTransaction::TYPE_PARENTSITE:
62-
case PhameBlogTransaction::TYPE_PARENTDOMAIN:
69+
case PhameBlogTransaction::TYPE_PROFILEIMAGE:
70+
case PhameBlogTransaction::TYPE_HEADERIMAGE:
6371
return $xaction->getNewValue();
6472
case PhameBlogTransaction::TYPE_FULLDOMAIN:
6573
$domain = $xaction->getNewValue();
@@ -92,6 +100,10 @@ protected function applyCustomInternalTransaction(
92100
}
93101
$object->setDomainFullURI($new_value);
94102
return;
103+
case PhameBlogTransaction::TYPE_PROFILEIMAGE:
104+
return $object->setProfileImagePHID($xaction->getNewValue());
105+
case PhameBlogTransaction::TYPE_HEADERIMAGE:
106+
return $object->setHeaderImagePHID($xaction->getNewValue());
95107
case PhameBlogTransaction::TYPE_STATUS:
96108
return $object->setStatus($xaction->getNewValue());
97109
case PhameBlogTransaction::TYPE_PARENTSITE:
@@ -114,6 +126,8 @@ protected function applyCustomExternalTransaction(
114126
case PhameBlogTransaction::TYPE_FULLDOMAIN:
115127
case PhameBlogTransaction::TYPE_PARENTSITE:
116128
case PhameBlogTransaction::TYPE_PARENTDOMAIN:
129+
case PhameBlogTransaction::TYPE_HEADERIMAGE:
130+
case PhameBlogTransaction::TYPE_PROFILEIMAGE:
117131
case PhameBlogTransaction::TYPE_STATUS:
118132
return;
119133
}

‎src/applications/phame/storage/PhameBlogTransaction.php

+79-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
final class PhameBlogTransaction
44
extends PhabricatorApplicationTransaction {
55

6-
const TYPE_NAME = 'phame.blog.name';
7-
const TYPE_SUBTITLE = 'phame.blog.subtitle';
8-
const TYPE_DESCRIPTION = 'phame.blog.description';
9-
const TYPE_FULLDOMAIN = 'phame.blog.full.domain';
10-
const TYPE_STATUS = 'phame.blog.status';
11-
const TYPE_PARENTSITE = 'phame.blog.parent.site';
12-
const TYPE_PARENTDOMAIN = 'phame.blog.parent.domain';
6+
const TYPE_NAME = 'phame.blog.name';
7+
const TYPE_SUBTITLE = 'phame.blog.subtitle';
8+
const TYPE_DESCRIPTION = 'phame.blog.description';
9+
const TYPE_FULLDOMAIN = 'phame.blog.full.domain';
10+
const TYPE_STATUS = 'phame.blog.status';
11+
const TYPE_PARENTSITE = 'phame.blog.parent.site';
12+
const TYPE_PARENTDOMAIN = 'phame.blog.parent.domain';
13+
const TYPE_PROFILEIMAGE = 'phame.blog.header.image';
14+
const TYPE_HEADERIMAGE = 'phame.blog.profile.image';
1315

1416
const MAILTAG_DETAILS = 'phame-blog-details';
1517
const MAILTAG_SUBSCRIBERS = 'phame-blog-subscribers';
@@ -34,6 +36,22 @@ public function shouldHide() {
3436
return parent::shouldHide();
3537
}
3638

39+
public function getRequiredHandlePHIDs() {
40+
$old = $this->getOldValue();
41+
$new = $this->getNewValue();
42+
43+
$req_phids = array();
44+
switch ($this->getTransactionType()) {
45+
case self::TYPE_PROFILEIMAGE:
46+
case self::TYPE_HEADERIMAGE:
47+
$req_phids[] = $old;
48+
$req_phids[] = $new;
49+
break;
50+
}
51+
52+
return array_merge($req_phids, parent::getRequiredHandlePHIDs());
53+
}
54+
3755
public function getIcon() {
3856
$old = $this->getOldValue();
3957
$new = $this->getNewValue();
@@ -48,6 +66,10 @@ public function getIcon() {
4866
case self::TYPE_DESCRIPTION:
4967
case self::TYPE_FULLDOMAIN:
5068
return 'fa-pencil';
69+
case self::TYPE_HEADERIMAGE:
70+
return 'fa-image';
71+
case self::TYPE_PROFILEIMAGE:
72+
return 'fa-star';
5173
case self::TYPE_STATUS:
5274
if ($new == PhameBlog::STATUS_ARCHIVED) {
5375
return 'fa-ban';
@@ -88,6 +110,8 @@ public function getMailTags() {
88110
case self::TYPE_FULLDOMAIN:
89111
case self::TYPE_PARENTSITE:
90112
case self::TYPE_PARENTDOMAIN:
113+
case self::TYPE_PROFILEIMAGE:
114+
case self::TYPE_HEADERIMAGE:
91115
$tags[] = self::MAILTAG_DETAILS;
92116
break;
93117
default:
@@ -172,6 +196,42 @@ public function getTitle() {
172196
$new);
173197
}
174198
break;
199+
case self::TYPE_HEADERIMAGE:
200+
if (!$old) {
201+
return pht(
202+
"%s set this blog's header image to %s.",
203+
$this->renderHandleLink($author_phid),
204+
$this->renderHandleLink($new));
205+
} else if (!$new) {
206+
return pht(
207+
"%s removed this blog's header image.",
208+
$this->renderHandleLink($author_phid));
209+
} else {
210+
return pht(
211+
"%s updated this blog's header image from %s to %s.",
212+
$this->renderHandleLink($author_phid),
213+
$this->renderHandleLink($old),
214+
$this->renderHandleLink($new));
215+
}
216+
break;
217+
case self::TYPE_PROFILEIMAGE:
218+
if (!$old) {
219+
return pht(
220+
"%s set this blog's profile image to %s.",
221+
$this->renderHandleLink($author_phid),
222+
$this->renderHandleLink($new));
223+
} else if (!$new) {
224+
return pht(
225+
"%s removed this blog's profile image.",
226+
$this->renderHandleLink($author_phid));
227+
} else {
228+
return pht(
229+
"%s updated this blog's profile image from %s to %s.",
230+
$this->renderHandleLink($author_phid),
231+
$this->renderHandleLink($old),
232+
$this->renderHandleLink($new));
233+
}
234+
break;
175235
case self::TYPE_STATUS:
176236
switch ($new) {
177237
case PhameBlog::STATUS_ACTIVE:
@@ -248,6 +308,18 @@ public function getTitleForFeed() {
248308
$this->renderHandleLink($author_phid),
249309
$this->renderHandleLink($object_phid));
250310
break;
311+
case self::TYPE_HEADERIMAGE:
312+
return pht(
313+
'%s updated the header image for %s.',
314+
$this->renderHandleLink($author_phid),
315+
$this->renderHandleLink($object_phid));
316+
break;
317+
case self::TYPE_PROFILEIMAGE:
318+
return pht(
319+
'%s updated the profile image for %s.',
320+
$this->renderHandleLink($author_phid),
321+
$this->renderHandleLink($object_phid));
322+
break;
251323
case self::TYPE_STATUS:
252324
switch ($new) {
253325
case PhameBlog::STATUS_ACTIVE:

0 commit comments

Comments
 (0)
Failed to load comments.