1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

Straighten out some reviewer-realtd horribleness.

This commit is contained in:
epriestley 2011-02-02 17:38:03 -08:00
parent ba26f67687
commit 223ac18287
6 changed files with 48 additions and 88 deletions

View file

@ -53,8 +53,10 @@ class DifferentialRevisionEditController extends DifferentialController {
$e_title = true; $e_title = true;
$e_testplan = true; $e_testplan = true;
$errors = array(); $errors = array();
$revision->loadRelationships();
if ($request->isFormPost() && !$request->getStr('viaDiffView')) { if ($request->isFormPost() && !$request->getStr('viaDiffView')) {
$revision->setTitle($request->getStr('title')); $revision->setTitle($request->getStr('title'));
$revision->setSummary($request->getStr('summary')); $revision->setSummary($request->getStr('summary'));
$revision->setTestPlan($request->getStr('testplan')); $revision->setTestPlan($request->getStr('testplan'));
@ -93,11 +95,19 @@ class DifferentialRevisionEditController extends DifferentialController {
$reviewer_phids = $request->getArr('reviewers'); $reviewer_phids = $request->getArr('reviewers');
$cc_phids = $request->getArr('cc'); $cc_phids = $request->getArr('cc');
} else { } else {
// $reviewer_phids = $revision->getReviewers(); $reviewer_phids = $revision->getReviewers();
// $cc_phids = $revision->getCCPHIDs(); $cc_phids = $revision->getCCPHIDs();
$reviewer_phids = array();
$cc_phids = array();
} }
$phids = array_merge($reviewer_phids, $cc_phids);
$phids = array_unique($phids);
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
$handles = mpull($handles, 'getFullName', 'getPHID');
$reviewer_map = array_select_keys($handles, $reviewer_phids);
$cc_map = array_select_keys($handles, $cc_phids);
$form = new AphrontFormView(); $form = new AphrontFormView();
$form->setUser($request->getUser()); $form->setUser($request->getUser());
@ -148,7 +158,7 @@ class DifferentialRevisionEditController extends DifferentialController {
->setLabel('CC') ->setLabel('CC')
->setName('cc') ->setName('cc')
->setDatasource('/typeahead/common/mailable/') ->setDatasource('/typeahead/common/mailable/')
->setValue($reviewer_map)) ->setValue($cc_map))
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setLabel('Blame Revision') ->setLabel('Blame Revision')

View file

@ -497,7 +497,7 @@ class DifferentialRevisionEditor {
array $rem_phids, array $rem_phids,
array $add_phids, array $add_phids,
$reason_phid) { $reason_phid) {
$rem_map = array_fill_keys($rem_phids, true); $rem_map = array_fill_keys($rem_phids, true);
$add_map = array_fill_keys($add_phids, true); $add_map = array_fill_keys($add_phids, true);
@ -515,8 +515,8 @@ class DifferentialRevisionEditor {
} }
$raw = $revision->getRawRelations(DifferentialRevision::RELATION_REVIEWER); $raw = $revision->getRawRelations(DifferentialRevision::RELATION_REVIEWER);
$raw = ipull($raw, 'objectPHID'); $raw = ipull($raw, null, 'objectPHID');
$sequence = count($seq_map); $sequence = count($seq_map);
foreach ($raw as $phid => $relation) { foreach ($raw as $phid => $relation) {
if (isset($seq_map[$phid])) { if (isset($seq_map[$phid])) {
@ -529,34 +529,28 @@ class DifferentialRevisionEditor {
foreach ($raw as $phid => $relation) { foreach ($raw as $phid => $relation) {
if (isset($rem_map[$phid])) { if (isset($rem_map[$phid])) {
$relation['forbidden'] = true; unset($raw[$phid]);
$relation['reasonPHID'] = $reason_phid;
} else if (isset($add_map[$phid])) {
$relation['forbidden'] = false;
$relation['reasonPHID'] = $reason_phid;
} }
} }
foreach ($add_phids as $add) { foreach ($add_phids as $add) {
$raw[] = array( $raw[$add] = array(
'objectPHID' => $add, 'objectPHID' => $add,
'forbidden' => false,
'sequence' => idx($seq_map, $add, $sequence++), 'sequence' => idx($seq_map, $add, $sequence++),
'reasonPHID' => $reason_phid, 'reasonPHID' => $reason_phid,
); );
} }
$conn_w = $revision->establishConnection('w'); $conn_w = $revision->establishConnection('w');
$sql = array(); $sql = array();
foreach ($raw as $relation) { foreach ($raw as $relation) {
$sql[] = qsprintf( $sql[] = qsprintf(
$conn_w, $conn_w,
'(%d, %s, %s, %d, %d, %s)', '(%d, %s, %s, %d, %s)',
$revision->getID(), $revision->getID(),
DifferentialRevision::RELATION_REVIEWER, DifferentialRevision::RELATION_REVIEWER,
$relation['objectPHID'], $relation['objectPHID'],
$relation['forbidden'],
$relation['sequence'], $relation['sequence'],
$relation['reasonPHID']); $relation['reasonPHID']);
} }
@ -572,7 +566,7 @@ class DifferentialRevisionEditor {
queryfx( queryfx(
$conn_w, $conn_w,
'INSERT INTO %T 'INSERT INTO %T
(revisionID, relation, objectPHID, forbidden, sequence, reasonPHID) (revisionID, relation, objectPHID, sequence, reasonPHID)
VALUES %Q', VALUES %Q',
DifferentialRevision::RELATIONSHIP_TABLE, DifferentialRevision::RELATIONSHIP_TABLE,
implode(', ', $sql)); implode(', ', $sql));

View file

@ -33,13 +33,13 @@ class DifferentialRevision extends DifferentialDAO {
protected $lineCount; protected $lineCount;
private $related; private $relationships;
private $forbidden;
const RELATIONSHIP_TABLE = 'differential_relationship'; const RELATIONSHIP_TABLE = 'differential_relationship';
const RELATION_REVIEWER = 'revw'; const RELATION_REVIEWER = 'revw';
const RELATION_SUBSCRIBED = 'subd'; const RELATION_SUBSCRIBED = 'subd';
const RELATION_UNSUBSCRIBED = 'usub';
public function getConfiguration() { public function getConfiguration() {
return array( return array(
@ -78,8 +78,6 @@ class DifferentialRevision extends DifferentialDAO {
public function loadRelationships() { public function loadRelationships() {
if (!$this->getID()) { if (!$this->getID()) {
$this->relationships = array(); $this->relationships = array();
$this->related = array();
$this->forbidden = array();
return; return;
} }
@ -89,19 +87,6 @@ class DifferentialRevision extends DifferentialDAO {
self::RELATIONSHIP_TABLE, self::RELATIONSHIP_TABLE,
$this->getID()); $this->getID());
$related = array();
$forbidden = array();
foreach ($data as $row) {
if ($row['forbidden']) {
$forbidden[] = $row;
} else {
$related[] = $row;
}
}
$this->related = igroup($related, 'relation');
$this->forbidden = igroup($related, 'relation');
$this->relationships = igroup($data, 'relation'); $this->relationships = igroup($data, 'relation');
return $this; return $this;
@ -116,60 +101,14 @@ class DifferentialRevision extends DifferentialDAO {
} }
private function getRelatedPHIDs($relation) { private function getRelatedPHIDs($relation) {
if ($this->related === null) { if ($this->relationships === null) {
throw new Exception("Must load relationships!"); throw new Exception("Must load relationships!");
} }
$related = idx($this->related, $relation, array()); return ipull($this->getRawRelations($relation), 'objectPHID');
return ipull($related, 'objectPHID');
} }
public function getRawRelations($relation) { public function getRawRelations($relation) {
return idx($this->relationships, $relation, array()); return idx($this->relationships, $relation, array());
} }
public function writeRelatedPHIDs(
$relation,
$phids,
$reason_phid,
$forbidden) {
$conn_w = $this->establishConnection('w');
$sql = array();
$phids = array_values($phids);
foreach ($phids as $key => $phid) {
$sql[] = qsprintf(
$conn_w,
'(%d, %s, %d, %s, %d)',
$this->getRevisionID(),
$phid,
$key,
$reason_phid,
$forbidden);
}
$conn_w->openTransaction();
queryfx(
$conn_w,
'DELETE FROM %T WHERE revisionID = %d AND relation = %s
AND forbidden = %d
AND relatedPHID NOT IN (%Ls)',
self::RELATIONSHIP_TABLE,
$this->getID(),
$relation,
$forbidden,
$phids);
queryfx(
$conn_w,
'INSERT INTO %T
(revisionID, relatedPHID, sequence, reason_phid, forbidden)
VALUES %Q
ON DUPLICATE KEY UPDATE sequence = VALUES(sequence)',
self::RELATIONSHIP_TABLE,
implode(', ', $sql));
$conn_w->saveTransaction();
}
} }

View file

@ -23,6 +23,7 @@ class PhabricatorObjectHandle {
private $type; private $type;
private $name; private $name;
private $email; private $email;
private $fullName;
private $imageURI; private $imageURI;
public function setURI($uri) { public function setURI($uri) {
@ -52,6 +53,15 @@ class PhabricatorObjectHandle {
return $this->name; return $this->name;
} }
public function setFullName($full_name) {
$this->fullName = $full_name;
return $this;
}
public function getFullName() {
return $this->fullName;
}
public function setType($type) { public function setType($type) {
$this->type = $type; $this->type = $type;
return $this; return $this;

View file

@ -58,6 +58,8 @@ class PhabricatorObjectHandleData {
$handle->setName($user->getUsername()); $handle->setName($user->getUsername());
$handle->setURI('/p/'.$user->getUsername().'/'); $handle->setURI('/p/'.$user->getUsername().'/');
$handle->setEmail($user->getEmail()); $handle->setEmail($user->getEmail());
$handle->setFullName(
$user->getUsername().' ('.$user->getRealName().')');
$img_phid = $user->getProfileImagePHID(); $img_phid = $user->getProfileImagePHID();
if ($img_phid) { if ($img_phid) {
@ -89,6 +91,7 @@ class PhabricatorObjectHandleData {
$handle->setEmail($list->getEmail()); $handle->setEmail($list->getEmail());
$handle->setName($list->getName()); $handle->setName($list->getName());
$handle->setURI($list->getURI()); $handle->setURI($list->getURI());
$handle->setFullName($list->getName());
} }
$handles[$phid] = $handle; $handles[$phid] = $handle;
} }

View file

@ -2693,8 +2693,12 @@ JX.install('DOM', {
listen : function(node, type, path, callback) { listen : function(node, type, path, callback) {
var id = ['id:' + JX.DOM.uniqID(node)]; var id = ['id:' + JX.DOM.uniqID(node)];
path = JX.$AX(path || []); path = JX.$AX(path || []);
for (var ii = 0; ii < path.length; ii++) { if (!path.length) {
path[ii] = id.concat(JX.$AX(path[ii])); path = id;
} else {
for (var ii = 0; ii < path.length; ii++) {
path[ii] = id.concat(JX.$AX(path[ii]));
}
} }
return JX.Stratcom.listen(type, path, callback); return JX.Stratcom.listen(type, path, callback);
}, },