1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 06:42:42 +01:00

Added subscriber view to Maniphest.

Summary:
People want to see all the tasks they have subscribed to in one
view. A new table was added for this to make queries faster.

Test Plan:
Tested that the view was initially empty. After running the
reindex_maniphest.php script, I saw the correct tasks there. Added
myself as a subscriber to one task and made sure the view was
updated. Removed myself as a subscriber from one task and made sure
the view was updated again.

Reviewed By: epriestley
Reviewers: epriestley, jungejason, codeblock
CC: aran, rm, epriestley
Differential Revision: 603
This commit is contained in:
tuomaspelkonen 2011-07-07 10:24:49 -07:00
parent b5f1faf34f
commit 49310391e0
10 changed files with 149 additions and 3 deletions

View file

@ -0,0 +1,6 @@
CREATE TABLE phabricator_maniphest.maniphest_tasksubscriber (
taskPHID varchar(64) BINARY NOT NULL,
subscriberPHID varchar(64) BINARY NOT NULL,
PRIMARY KEY (subscriberPHID, taskPHID),
UNIQUE KEY (taskPHID, subscriberPHID)
);

View file

@ -26,6 +26,7 @@ $tasks = id(new ManiphestTask())->loadAll();
echo "Updating relationships for ".count($tasks)." tasks";
foreach ($tasks as $task) {
ManiphestTaskProject::updateTaskProjects($task);
ManiphestTaskSubscriber::updateTaskSubscribers($task);
echo '.';
}
echo "\nDone.\n";

View file

@ -277,6 +277,7 @@ phutil_register_library_map(array(
'ManiphestTaskProject' => 'applications/maniphest/storage/taskproject',
'ManiphestTaskQuery' => 'applications/maniphest/query',
'ManiphestTaskStatus' => 'applications/maniphest/constants/status',
'ManiphestTaskSubscriber' => 'applications/maniphest/storage/subscriber',
'ManiphestTaskSummaryView' => 'applications/maniphest/view/tasksummary',
'ManiphestTransaction' => 'applications/maniphest/storage/transaction',
'ManiphestTransactionDetailView' => 'applications/maniphest/view/transactiondetail',
@ -788,6 +789,7 @@ phutil_register_library_map(array(
'ManiphestTaskPriority' => 'ManiphestConstants',
'ManiphestTaskProject' => 'ManiphestDAO',
'ManiphestTaskStatus' => 'ManiphestConstants',
'ManiphestTaskSubscriber' => 'ManiphestDAO',
'ManiphestTaskSummaryView' => 'ManiphestView',
'ManiphestTransaction' => 'ManiphestDAO',
'ManiphestTransactionDetailView' => 'ManiphestView',

View file

@ -54,9 +54,10 @@ class ManiphestTaskListController extends ManiphestController {
$views = array(
'User Tasks',
'action' => 'Assigned',
'created' => 'Created',
'triage' => 'Need Triage',
'action' => 'Assigned',
'created' => 'Created',
'subscribed' => 'Subscribed',
'triage' => 'Need Triage',
'<hr />',
'All Tasks',
'alltriage' => 'Need Triage',
@ -70,6 +71,7 @@ class ManiphestTaskListController extends ManiphestController {
$has_filter = array(
'action' => true,
'created' => true,
'subscribed' => true,
'triage' => true,
);
@ -270,6 +272,9 @@ class ManiphestTaskListController extends ManiphestController {
case 'created':
$query->withAuthors($user_phids);
break;
case 'subscribed':
$query->withSubscribers($user_phids);
break;
case 'triage':
$query->withOwners($user_phids);
$query->withPriority(ManiphestTaskPriority::PRIORITY_TRIAGE);

View file

@ -28,6 +28,7 @@ final class ManiphestTaskQuery {
private $ownerPHIDs = array();
private $includeUnowned = null;
private $projectPHIDs = array();
private $subscriberPHIDs = array();
private $status = 'status-any';
const STATUS_ANY = 'status-any';
@ -89,6 +90,11 @@ final class ManiphestTaskQuery {
return $this;
}
public function withSubscribers(array $subscribers) {
$this->subscriberPHIDs = $subscribers;
return $this;
}
public function setGroupBy($group) {
$this->groupBy = $group;
return $this;
@ -139,6 +145,7 @@ final class ManiphestTaskQuery {
$where[] = $this->buildPriorityWhereClause($conn);
$where[] = $this->buildAuthorWhereClause($conn);
$where[] = $this->buildOwnerWhereClause($conn);
$where[] = $this->buildSubscriberWhereClause($conn);
$where[] = $this->buildProjectWhereClause($conn);
$where = array_filter($where);
@ -150,6 +157,7 @@ final class ManiphestTaskQuery {
$join = array();
$join[] = $this->buildProjectJoinClause($conn);
$join[] = $this->buildSubscriberJoinClause($conn);
$join = array_filter($join);
if ($join) {
@ -272,6 +280,17 @@ final class ManiphestTaskQuery {
}
}
private function buildSubscriberWhereClause($conn) {
if (!$this->subscriberPHIDs) {
return null;
}
return qsprintf(
$conn,
'subscriber.subscriberPHID IN (%Ls)',
$this->subscriberPHIDs);
}
private function buildProjectWhereClause($conn) {
if (!$this->projectPHIDs) {
return null;
@ -295,6 +314,18 @@ final class ManiphestTaskQuery {
$project_dao->getTableName());
}
private function buildSubscriberJoinClause($conn) {
if (!$this->subscriberPHIDs) {
return null;
}
$subscriber_dao = new ManiphestTaskSubscriber();
return qsprintf(
$conn,
'JOIN %T subscriber ON subscriber.taskPHID = task.phid',
$subscriber_dao->getTableName());
}
private function buildOrderClause($conn) {
$order = array();

View file

@ -7,6 +7,7 @@
phutil_require_module('phabricator', 'applications/maniphest/constants/owner');
phutil_require_module('phabricator', 'applications/maniphest/storage/subscriber');
phutil_require_module('phabricator', 'applications/maniphest/storage/task');
phutil_require_module('phabricator', 'applications/maniphest/storage/taskproject');
phutil_require_module('phabricator', 'storage/qsprintf');

View file

@ -0,0 +1,65 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group maniphest
*/
final class ManiphestTaskSubscriber extends ManiphestDAO {
protected $taskPHID;
protected $subscriberPHID;
public function getConfiguration() {
return array(
self::CONFIG_IDS => self::IDS_MANUAL,
self::CONFIG_TIMESTAMPS => false,
);
}
public static function updateTaskSubscribers(ManiphestTask $task) {
$dao = new ManiphestTaskSubscriber();
$conn = $dao->establishConnection('w');
$sql = array();
$subscribers = $task->getCCPHIDs();
$subscribers[] = $task->getOwnerPHID();
$subscribers = array_unique($subscribers);
foreach ($subscribers as $subscriber_phid) {
$sql[] = qsprintf(
$conn,
'(%s, %s)',
$task->getPHID(),
$subscriber_phid);
}
queryfx(
$conn,
'DELETE FROM %T WHERE taskPHID = %s',
$dao->getTableName(),
$task->getPHID());
if ($sql) {
queryfx(
$conn,
'INSERT INTO %T (taskPHID, subscriberPHID) VALUES %Q',
$dao->getTableName(),
implode(', ', $sql));
}
}
}

View file

@ -0,0 +1,14 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/maniphest/storage/base');
phutil_require_module('phabricator', 'storage/qsprintf');
phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_source('ManiphestTaskSubscriber.php');

View file

@ -37,6 +37,7 @@ class ManiphestTask extends ManiphestDAO {
protected $attached = array();
protected $projectPHIDs = array();
private $projectsNeedUpdate;
private $subscribersNeedUpdate;
protected $ownerOrdering;
@ -70,6 +71,18 @@ class ManiphestTask extends ManiphestDAO {
return $this;
}
public function setCCPHIDs(array $phids) {
$this->ccPHIDs = $phids;
$this->subscribersNeedUpdate = true;
return $this;
}
public function setOwnerPHID($phid) {
$this->ownerPHID = $phid;
$this->subscribersNeedUpdate = true;
return $this;
}
public function save() {
if (!$this->mailKey) {
$this->mailKey = sha1(Filesystem::readRandomBytes(20));
@ -84,6 +97,13 @@ class ManiphestTask extends ManiphestDAO {
$this->projectsNeedUpdate = false;
}
if ($this->subscribersNeedUpdate) {
// If we've changed the subscriber PHIDs for this task, update the link
// table.
ManiphestTaskSubscriber::updateTaskSubscribers($this);
$this->subscribersNeedUpdate = false;
}
return $result;
}

View file

@ -7,6 +7,7 @@
phutil_require_module('phabricator', 'applications/maniphest/storage/base');
phutil_require_module('phabricator', 'applications/maniphest/storage/subscriber');
phutil_require_module('phabricator', 'applications/maniphest/storage/taskproject');
phutil_require_module('phabricator', 'applications/phid/constants');
phutil_require_module('phabricator', 'applications/phid/storage/phid');