mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Add a basic view count to Phame
Summary: This adds a very very basic view count to Phame, so bloggers can get some idea which posts are more popular than others. Anything more than this I think should be Facts or Google Analytics. Test Plan: Write a new post, see post count. Reload page, post count goes up. Archive post, post count stays the same. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D18446
This commit is contained in:
parent
39d19c33ec
commit
e40c002a6d
7 changed files with 58 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_phame.phame_post
|
||||
ADD views INTEGER NOT NULL;
|
|
@ -0,0 +1,2 @@
|
|||
UPDATE {$NAMESPACE}_phame.phame_post
|
||||
SET views = 0;
|
|
@ -4417,6 +4417,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php',
|
||||
'PhamePostTransactionType' => 'applications/phame/xaction/PhamePostTransactionType.php',
|
||||
'PhamePostViewController' => 'applications/phame/controller/post/PhamePostViewController.php',
|
||||
'PhamePostViewsTransaction' => 'applications/phame/xaction/PhamePostViewsTransaction.php',
|
||||
'PhamePostVisibilityTransaction' => 'applications/phame/xaction/PhamePostVisibilityTransaction.php',
|
||||
'PhameSchemaSpec' => 'applications/phame/storage/PhameSchemaSpec.php',
|
||||
'PhameSite' => 'applications/phame/site/PhameSite.php',
|
||||
|
@ -10041,6 +10042,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'PhamePostTransactionType' => 'PhabricatorModularTransactionType',
|
||||
'PhamePostViewController' => 'PhameLiveController',
|
||||
'PhamePostViewsTransaction' => 'PhamePostTransactionType',
|
||||
'PhamePostVisibilityTransaction' => 'PhamePostTransactionType',
|
||||
'PhameSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||
'PhameSite' => 'PhabricatorSite',
|
||||
|
|
|
@ -18,6 +18,25 @@ final class PhamePostViewController
|
|||
$is_live = $this->getIsLive();
|
||||
$is_external = $this->getIsExternal();
|
||||
|
||||
// Register a blog "view" count
|
||||
//
|
||||
if (!$post->isDraft() && !$post->isArchived()) {
|
||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PhamePostTransaction())
|
||||
->setTransactionType(PhamePostViewsTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue(null);
|
||||
|
||||
$editor = id(new PhamePostEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnMissingFields(true)
|
||||
->setContinueOnNoEffect(true);
|
||||
|
||||
$editor->applyTransactions($post, $xactions);
|
||||
unset($unguarded);
|
||||
}
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->addClass('phame-header-bar')
|
||||
->setUser($viewer);
|
||||
|
@ -151,6 +170,11 @@ final class PhamePostViewController
|
|||
->setUser($viewer)
|
||||
->setObject($post);
|
||||
|
||||
$views = id(new PhutilNumber($post->getViews()));
|
||||
$properties->addProperty(
|
||||
pht('Views'),
|
||||
pht('%s', $views));
|
||||
|
||||
$is_live = $this->getIsLive();
|
||||
$is_external = $this->getIsExternal();
|
||||
$next_view = new PhameNextPostView();
|
||||
|
|
|
@ -41,6 +41,12 @@ final class PhamePostEditor
|
|||
if ($object->isDraft() || $object->isArchived()) {
|
||||
return false;
|
||||
}
|
||||
foreach ($xactions as $xaction) {
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhamePostViewsTransaction::TRANSACTIONTYPE:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhamePost extends PhameDAO
|
|||
protected $phameTitle;
|
||||
protected $body;
|
||||
protected $visibility;
|
||||
protected $views;
|
||||
protected $configData;
|
||||
protected $datePublished;
|
||||
protected $blogPHID;
|
||||
|
@ -40,7 +41,8 @@ final class PhamePost extends PhameDAO
|
|||
->setBlogPHID($blog->getPHID())
|
||||
->attachBlog($blog)
|
||||
->setDatePublished(PhabricatorTime::getNow())
|
||||
->setVisibility(PhameConstants::VISIBILITY_PUBLISHED);
|
||||
->setVisibility(PhameConstants::VISIBILITY_PUBLISHED)
|
||||
->setViews(0);
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
@ -128,6 +130,7 @@ final class PhamePost extends PhameDAO
|
|||
'subtitle' => 'text64',
|
||||
'phameTitle' => 'sort64?',
|
||||
'visibility' => 'uint32',
|
||||
'views' => 'uint32',
|
||||
'mailKey' => 'bytes20',
|
||||
'headerImagePHID' => 'phid?',
|
||||
|
||||
|
|
18
src/applications/phame/xaction/PhamePostViewsTransaction.php
Normal file
18
src/applications/phame/xaction/PhamePostViewsTransaction.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
final class PhamePostViewsTransaction
|
||||
extends PhamePostTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'phame.post.views';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getViews();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$views = $object->getViews();
|
||||
$views++;
|
||||
$object->setViews($views);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue