@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow Phame Blogs to be archived instead of deleted

Summary: Removes "delete" and uses "archive/activate" instead for Phame Blogs. Ref T9756

Test Plan: Archive a blog, see in search, activate blog, see in other search.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: joshuaspence, Korvin

Maniphest Tasks: T9756

Differential Revision: https://secure.phabricator.com/D14465

+199 -55
+2
resources/sql/autopatches/20151111.phame.blog.archive.1.sql
··· 1 + ALTER TABLE {$NAMESPACE}_phame.phame_blog 2 + ADD status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
+2
resources/sql/autopatches/20151111.phame.blog.archive.2.sql
··· 1 + UPDATE {$NAMESPACE}_phame.phame_blog 2 + SET status = 'active' WHERE status = '';
+2 -2
src/__phutil_library_map__.php
··· 3271 3271 'PhameBasicBlogSkin' => 'applications/phame/skins/PhameBasicBlogSkin.php', 3272 3272 'PhameBasicTemplateBlogSkin' => 'applications/phame/skins/PhameBasicTemplateBlogSkin.php', 3273 3273 'PhameBlog' => 'applications/phame/storage/PhameBlog.php', 3274 + 'PhameBlogArchiveController' => 'applications/phame/controller/blog/PhameBlogArchiveController.php', 3274 3275 'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php', 3275 3276 'PhameBlogCreateCapability' => 'applications/phame/capability/PhameBlogCreateCapability.php', 3276 - 'PhameBlogDeleteController' => 'applications/phame/controller/blog/PhameBlogDeleteController.php', 3277 3277 'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php', 3278 3278 'PhameBlogEditor' => 'applications/phame/editor/PhameBlogEditor.php', 3279 3279 'PhameBlogFeedController' => 'applications/phame/controller/blog/PhameBlogFeedController.php', ··· 7573 7573 'PhabricatorProjectInterface', 7574 7574 'PhabricatorApplicationTransactionInterface', 7575 7575 ), 7576 + 'PhameBlogArchiveController' => 'PhameBlogController', 7576 7577 'PhameBlogController' => 'PhameController', 7577 7578 'PhameBlogCreateCapability' => 'PhabricatorPolicyCapability', 7578 - 'PhameBlogDeleteController' => 'PhameBlogController', 7579 7579 'PhameBlogEditController' => 'PhameBlogController', 7580 7580 'PhameBlogEditor' => 'PhabricatorApplicationTransactionEditor', 7581 7581 'PhameBlogFeedController' => 'PhameBlogController',
+1 -1
src/applications/phame/application/PhabricatorPhameApplication.php
··· 59 59 'blog/' => array( 60 60 '(?:(?P<filter>user|all)/)?' => 'PhameBlogListController', 61 61 '(?:query/(?P<queryKey>[^/]+)/)?' => 'PhameBlogListController', 62 - 'delete/(?P<id>[^/]+)/' => 'PhameBlogDeleteController', 62 + 'archive/(?P<id>[^/]+)/' => 'PhameBlogArchiveController', 63 63 'edit/(?P<id>[^/]+)/' => 'PhameBlogEditController', 64 64 'view/(?P<id>[^/]+)/' => 'PhameBlogViewController', 65 65 'feed/(?P<id>[^/]+)/' => 'PhameBlogFeedController',
+68
src/applications/phame/controller/blog/PhameBlogArchiveController.php
··· 1 + <?php 2 + 3 + final class PhameBlogArchiveController 4 + extends PhameBlogController { 5 + 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $request->getViewer(); 8 + $id = $request->getURIData('id'); 9 + 10 + $blog = id(new PhameBlogQuery()) 11 + ->setViewer($viewer) 12 + ->withIDs(array($id)) 13 + ->requireCapabilities( 14 + array( 15 + PhabricatorPolicyCapability::CAN_VIEW, 16 + PhabricatorPolicyCapability::CAN_EDIT, 17 + )) 18 + ->executeOne(); 19 + if (!$blog) { 20 + return new Aphront404Response(); 21 + } 22 + 23 + $view_uri = $this->getApplicationURI('blog/view/'.$blog->getID().'/'); 24 + 25 + if ($request->isFormPost()) { 26 + if ($blog->isArchived()) { 27 + $new_status = PhameBlog::STATUS_ACTIVE; 28 + } else { 29 + $new_status = PhameBlog::STATUS_ARCHIVED; 30 + } 31 + 32 + $xactions = array(); 33 + 34 + $xactions[] = id(new PhameBlogTransaction()) 35 + ->setTransactionType(PhameBlogTransaction::TYPE_STATUS) 36 + ->setNewValue($new_status); 37 + 38 + id(new PhameBlogEditor()) 39 + ->setActor($viewer) 40 + ->setContentSourceFromRequest($request) 41 + ->setContinueOnNoEffect(true) 42 + ->setContinueOnMissingFields(true) 43 + ->applyTransactions($blog, $xactions); 44 + 45 + return id(new AphrontRedirectResponse())->setURI($view_uri); 46 + } 47 + 48 + if ($blog->isArchived()) { 49 + $title = pht('Activate Blog'); 50 + $body = pht('This blog will become active again.'); 51 + $button = pht('Activate Blog'); 52 + } else { 53 + $title = pht('Archive Blog'); 54 + $body = pht('This blog will be marked as archived.'); 55 + $button = pht('Archive Blog'); 56 + } 57 + 58 + $dialog = id(new AphrontDialogView()) 59 + ->setUser($viewer) 60 + ->setTitle($title) 61 + ->appendChild($body) 62 + ->addCancelButton($view_uri) 63 + ->addSubmitButton($button); 64 + 65 + return id(new AphrontDialogResponse())->setDialog($dialog); 66 + } 67 + 68 + }
-42
src/applications/phame/controller/blog/PhameBlogDeleteController.php
··· 1 - <?php 2 - 3 - final class PhameBlogDeleteController extends PhameBlogController { 4 - 5 - public function handleRequest(AphrontRequest $request) { 6 - $viewer = $request->getViewer(); 7 - $id = $request->getURIData('id'); 8 - 9 - $blog = id(new PhameBlogQuery()) 10 - ->setViewer($viewer) 11 - ->withIDs(array($id)) 12 - ->requireCapabilities( 13 - array( 14 - PhabricatorPolicyCapability::CAN_EDIT, 15 - )) 16 - ->executeOne(); 17 - if (!$blog) { 18 - return new Aphront404Response(); 19 - } 20 - 21 - if ($request->isFormPost()) { 22 - $blog->delete(); 23 - return id(new AphrontRedirectResponse()) 24 - ->setURI($this->getApplicationURI()); 25 - } 26 - 27 - $cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/'); 28 - 29 - $dialog = id(new AphrontDialogView()) 30 - ->setUser($viewer) 31 - ->setTitle(pht('Delete Blog?')) 32 - ->appendChild( 33 - pht( 34 - 'Really delete the blog "%s"? It will be gone forever.', 35 - $blog->getName())) 36 - ->addSubmitButton(pht('Delete')) 37 - ->addCancelButton($cancel_uri); 38 - 39 - return id(new AphrontDialogResponse())->setDialog($dialog); 40 - } 41 - 42 - }
+31 -8
src/applications/phame/controller/blog/PhameBlogViewController.php
··· 22 22 ->withBlogPHIDs(array($blog->getPHID())) 23 23 ->executeWithCursorPager($pager); 24 24 25 + if ($blog->isArchived()) { 26 + $header_icon = 'fa-ban'; 27 + $header_name = pht('Archived'); 28 + $header_color = 'dark'; 29 + } else { 30 + $header_icon = 'fa-check'; 31 + $header_name = pht('Active'); 32 + $header_color = 'bluegrey'; 33 + } 34 + 25 35 $header = id(new PHUIHeaderView()) 26 36 ->setHeader($blog->getName()) 27 37 ->setUser($viewer) 28 - ->setPolicyObject($blog); 38 + ->setPolicyObject($blog) 39 + ->setStatus($header_icon, $header_color, $header_name); 29 40 30 41 $actions = $this->renderActions($blog, $viewer); 31 42 $properties = $this->renderProperties($blog, $viewer, $actions); ··· 158 169 ->setDisabled(!$can_edit) 159 170 ->setWorkflow(!$can_edit)); 160 171 161 - $actions->addAction( 162 - id(new PhabricatorActionView()) 163 - ->setIcon('fa-times') 164 - ->setHref($this->getApplicationURI('blog/delete/'.$blog->getID().'/')) 165 - ->setName(pht('Delete Blog')) 166 - ->setDisabled(!$can_edit) 167 - ->setWorkflow(true)); 172 + if ($blog->isArchived()) { 173 + $actions->addAction( 174 + id(new PhabricatorActionView()) 175 + ->setName(pht('Activate Blog')) 176 + ->setIcon('fa-check') 177 + ->setHref( 178 + $this->getApplicationURI('blog/archive/'.$blog->getID().'/')) 179 + ->setDisabled(!$can_edit) 180 + ->setWorkflow(true)); 181 + } else { 182 + $actions->addAction( 183 + id(new PhabricatorActionView()) 184 + ->setName(pht('Archive Blog')) 185 + ->setIcon('fa-ban') 186 + ->setHref( 187 + $this->getApplicationURI('blog/archive/'.$blog->getID().'/')) 188 + ->setDisabled(!$can_edit) 189 + ->setWorkflow(true)); 190 + } 168 191 169 192 return $actions; 170 193 }
+7
src/applications/phame/editor/PhameBlogEditor.php
··· 18 18 $types[] = PhameBlogTransaction::TYPE_DESCRIPTION; 19 19 $types[] = PhameBlogTransaction::TYPE_DOMAIN; 20 20 $types[] = PhameBlogTransaction::TYPE_SKIN; 21 + $types[] = PhameBlogTransaction::TYPE_STATUS; 21 22 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 22 23 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 23 24 ··· 37 38 return $object->getDomain(); 38 39 case PhameBlogTransaction::TYPE_SKIN: 39 40 return $object->getSkin(); 41 + case PhameBlogTransaction::TYPE_STATUS: 42 + return $object->getStatus(); 40 43 } 41 44 } 42 45 ··· 49 52 case PhameBlogTransaction::TYPE_DESCRIPTION: 50 53 case PhameBlogTransaction::TYPE_DOMAIN: 51 54 case PhameBlogTransaction::TYPE_SKIN: 55 + case PhameBlogTransaction::TYPE_STATUS: 52 56 return $xaction->getNewValue(); 53 57 } 54 58 } ··· 66 70 return $object->setDomain($xaction->getNewValue()); 67 71 case PhameBlogTransaction::TYPE_SKIN: 68 72 return $object->setSkin($xaction->getNewValue()); 73 + case PhameBlogTransaction::TYPE_STATUS: 74 + return $object->setStatus($xaction->getNewValue()); 69 75 } 70 76 71 77 return parent::applyCustomInternalTransaction($object, $xaction); ··· 80 86 case PhameBlogTransaction::TYPE_DESCRIPTION: 81 87 case PhameBlogTransaction::TYPE_DOMAIN: 82 88 case PhameBlogTransaction::TYPE_SKIN: 89 + case PhameBlogTransaction::TYPE_STATUS: 83 90 return; 84 91 } 85 92
+13
src/applications/phame/query/PhameBlogQuery.php
··· 5 5 private $ids; 6 6 private $phids; 7 7 private $domain; 8 + private $statuses; 8 9 private $needBloggers; 9 10 10 11 public function withIDs(array $ids) { ··· 22 23 return $this; 23 24 } 24 25 26 + public function withStatuses(array $status) { 27 + $this->statuses = $status; 28 + return $this; 29 + } 30 + 25 31 public function newResultObject() { 26 32 return new PhameBlog(); 27 33 } ··· 32 38 33 39 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 34 40 $where = parent::buildWhereClauseParts($conn); 41 + 42 + if ($this->statuses !== null) { 43 + $where[] = qsprintf( 44 + $conn, 45 + 'status IN (%Ls)', 46 + $this->statuses); 47 + } 35 48 36 49 if ($this->ids !== null) { 37 50 $where[] = qsprintf(
+29 -2
src/applications/phame/query/PhameBlogSearchEngine.php
··· 17 17 18 18 protected function buildQueryFromParameters(array $map) { 19 19 $query = $this->newQuery(); 20 + if ($map['statuses']) { 21 + $query->withStatuses(array($map['statuses'])); 22 + } 20 23 return $query; 21 24 } 22 25 23 26 protected function buildCustomSearchFields() { 24 - return array(); 27 + return array( 28 + id(new PhabricatorSearchSelectField()) 29 + ->setKey('statuses') 30 + ->setLabel(pht('Status')) 31 + ->setOptions(array( 32 + '' => pht('All'), 33 + PhameBlog::STATUS_ACTIVE => pht('Active'), 34 + PhameBlog::STATUS_ARCHIVED => pht('Archived'), 35 + )), 36 + ); 25 37 } 26 38 27 39 protected function getURI($path) { ··· 30 42 31 43 protected function getBuiltinQueryNames() { 32 44 $names = array( 45 + 'active' => pht('Active Blogs'), 46 + 'archived' => pht('Archived Blogs'), 33 47 'all' => pht('All Blogs'), 34 48 ); 35 49 return $names; ··· 42 56 switch ($query_key) { 43 57 case 'all': 44 58 return $query; 59 + case 'active': 60 + return $query->setParameter( 61 + 'statuses', PhameBlog::STATUS_ACTIVE); 62 + case 'archived': 63 + return $query->setParameter( 64 + 'statuses', PhameBlog::STATUS_ARCHIVED); 45 65 } 46 66 47 67 return parent::buildSavedQueryFromBuiltin($query_key); ··· 58 78 $list->setUser($viewer); 59 79 60 80 foreach ($blogs as $blog) { 81 + $archived = false; 82 + $icon = 'fa-star'; 83 + if ($blog->isArchived()) { 84 + $archived = true; 85 + $icon = 'fa-ban'; 86 + } 61 87 $id = $blog->getID(); 62 88 $item = id(new PHUIObjectItemView()) 63 89 ->setUser($viewer) 64 90 ->setObject($blog) 65 91 ->setHeader($blog->getName()) 66 - ->setStatusIcon('fa-star') 92 + ->setStatusIcon($icon) 93 + ->setDisabled($archived) 67 94 ->setHref($this->getApplicationURI("/blog/view/{$id}/")) 68 95 ->addAttribute($blog->getSkin()) 69 96 ->addAttribute($blog->getDomain());
+16
src/applications/phame/storage/PhameBlog.php
··· 20 20 protected $creatorPHID; 21 21 protected $viewPolicy; 22 22 protected $editPolicy; 23 + protected $status; 23 24 protected $mailKey; 24 25 25 26 private static $requestBlog; 27 + 28 + const STATUS_ACTIVE = 'active'; 29 + const STATUS_ARCHIVED = 'archived'; 26 30 27 31 protected function getConfiguration() { 28 32 return array( ··· 34 38 'name' => 'text64', 35 39 'description' => 'text', 36 40 'domain' => 'text128?', 41 + 'status' => 'text32', 37 42 'mailKey' => 'bytes20', 38 43 39 44 // T6203/NULLABILITY ··· 96 101 $skin->setSpecification($spec); 97 102 98 103 return $skin; 104 + } 105 + 106 + public function isArchived() { 107 + return ($this->getStatus() == self::STATUS_ARCHIVED); 108 + } 109 + 110 + public static function getStatusNameMap() { 111 + return array( 112 + self::STATUS_ACTIVE => pht('Active'), 113 + self::STATUS_ARCHIVED => pht('Archived'), 114 + ); 99 115 } 100 116 101 117 /**
+28
src/applications/phame/storage/PhameBlogTransaction.php
··· 7 7 const TYPE_DESCRIPTION = 'phame.blog.description'; 8 8 const TYPE_DOMAIN = 'phame.blog.domain'; 9 9 const TYPE_SKIN = 'phame.blog.skin'; 10 + const TYPE_STATUS = 'phame.blog.status'; 10 11 11 12 const MAILTAG_DETAILS = 'phame-blog-details'; 12 13 const MAILTAG_SUBSCRIBERS = 'phame-blog-subscribers'; ··· 106 107 $this->renderHandleLink($author_phid), 107 108 $new); 108 109 break; 110 + case self::TYPE_STATUS: 111 + switch ($new) { 112 + case self::STATUS_OPEN: 113 + return pht( 114 + '%s published this blog.', 115 + $this->renderHandleLink($author_phid)); 116 + case self::STATUS_CLOSED: 117 + return pht( 118 + '%s archived this blog.', 119 + $this->renderHandleLink($author_phid)); 120 + } 121 + 109 122 } 110 123 111 124 return parent::getTitle(); ··· 151 164 $this->renderHandleLink($author_phid), 152 165 $this->renderHandleLink($object_phid)); 153 166 break; 167 + case self::TYPE_STATUS: 168 + switch ($new) { 169 + case self::STATUS_OPEN: 170 + return pht( 171 + '%s published the blog %s.', 172 + $this->renderHandleLink($author_phid), 173 + $this->renderHandleLink($object_phid)); 174 + case self::STATUS_CLOSED: 175 + return pht( 176 + '%s archived the blog %s.', 177 + $this->renderHandleLink($author_phid), 178 + $this->renderHandleLink($object_phid)); 179 + } 180 + break; 181 + 154 182 } 155 183 156 184 return parent::getTitleForFeed();