1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Conpherence - implement PhabricatorDestructibleInterface so threads can be deleted

Summary: Fixes T7694. I had to complicate the `ConpherenceThreadQuery` code slightly so that if we specify id(s) or phid(s) then we don't bother with all that join stuff we need to make sure we have a reasonable query in production.

Test Plan: `bin/remove destroy ZXX` worked! tried to visit `ZXX` and got a nice 404. Clicked around and couldn't find anything broken because of the deletion

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7756, T7694

Differential Revision: https://secure.phabricator.com/D12304
This commit is contained in:
Bob Trahan 2015-04-08 12:19:40 -07:00
parent 8fc45e1774
commit d24b3dcb7d
4 changed files with 64 additions and 4 deletions

View file

@ -3446,6 +3446,7 @@ phutil_register_library_map(array(
'ConpherenceDAO', 'ConpherenceDAO',
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
'PhabricatorApplicationTransactionInterface', 'PhabricatorApplicationTransactionInterface',
'PhabricatorDestructibleInterface',
), ),
'ConpherenceThreadIndexer' => 'PhabricatorSearchDocumentIndexer', 'ConpherenceThreadIndexer' => 'PhabricatorSearchDocumentIndexer',
'ConpherenceThreadListView' => 'AphrontView', 'ConpherenceThreadListView' => 'AphrontView',

View file

@ -35,4 +35,34 @@ final class PhabricatorConpherenceThreadPHIDType extends PhabricatorPHIDType {
} }
} }
public function canLoadNamedObject($name) {
return preg_match('/^Z\d*[1-9]\d*$/i', $name);
}
public function loadNamedObjects(
PhabricatorObjectQuery $query,
array $names) {
$id_map = array();
foreach ($names as $name) {
$id = (int)substr($name, 1);
$id_map[$id][] = $name;
}
$objects = id(new ConpherenceThreadQuery())
->setViewer($query->getViewer())
->withIDs(array_keys($id_map))
->execute();
$objects = mpull($objects, null, 'getID');
$results = array();
foreach ($objects as $id => $object) {
foreach (idx($id_map, $id, array()) as $name) {
$results[$name] = $object;
}
}
return $results;
}
} }

View file

@ -133,7 +133,7 @@ final class ConpherenceThreadQuery
} }
$viewer = $this->getViewer(); $viewer = $this->getViewer();
if ($viewer->isLoggedIn()) { if ($this->shouldJoinForViewer($viewer)) {
$joins[] = qsprintf( $joins[] = qsprintf(
$conn_r, $conn_r,
'LEFT JOIN %T v ON v.conpherencePHID = conpherence_thread.phid '. 'LEFT JOIN %T v ON v.conpherencePHID = conpherence_thread.phid '.
@ -147,6 +147,15 @@ final class ConpherenceThreadQuery
return implode(' ', $joins); return implode(' ', $joins);
} }
private function shouldJoinForViewer(PhabricatorUser $viewer) {
if ($viewer->isLoggedIn() &&
$this->ids === null &&
$this->phids === null) {
return true;
}
return false;
}
protected function buildWhereClause($conn_r) { protected function buildWhereClause($conn_r) {
$where = array(); $where = array();
@ -181,11 +190,11 @@ final class ConpherenceThreadQuery
} }
$viewer = $this->getViewer(); $viewer = $this->getViewer();
if ($viewer->isLoggedIn()) { if ($this->shouldJoinForViewer($viewer)) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'conpherence_thread.isRoom = 1 OR v.participantPHID IS NOT NULL'); 'conpherence_thread.isRoom = 1 OR v.participantPHID IS NOT NULL');
} else { } else if ($this->phids === null && $this->ids === null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'conpherence_thread.isRoom = 1'); 'conpherence_thread.isRoom = 1');

View file

@ -3,7 +3,8 @@
final class ConpherenceThread extends ConpherenceDAO final class ConpherenceThread extends ConpherenceDAO
implements implements
PhabricatorPolicyInterface, PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface { PhabricatorApplicationTransactionInterface,
PhabricatorDestructibleInterface {
protected $title; protected $title;
protected $isRoom = 0; protected $isRoom = 0;
@ -339,4 +340,23 @@ final class ConpherenceThread extends ConpherenceDAO
return $timeline; return $timeline;
} }
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->openTransaction();
$this->delete();
$participants = id(new ConpherenceParticipant())
->loadAllWhere('conpherencePHID = %s', $this->getPHID());
foreach ($participants as $participant) {
$participant->delete();
}
$this->saveTransaction();
}
} }