1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-20 13:52:40 +01:00

Use application PHIDs in countdown

Summary: Ref T2715. Swap countdown to application PHIDs.

Test Plan: Used `phid.lookup`; `phid.query`.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2715

Differential Revision: https://secure.phabricator.com/D6532
This commit is contained in:
epriestley 2013-07-22 14:42:25 -07:00
parent 3aa5fcfcc7
commit f00b43d448
11 changed files with 90 additions and 30 deletions

View file

@ -283,7 +283,6 @@ phutil_register_library_map(array(
'ConpherenceViewController' => 'applications/conpherence/controller/ConpherenceViewController.php',
'ConpherenceWidgetController' => 'applications/conpherence/controller/ConpherenceWidgetController.php',
'ConpherenceWidgetView' => 'applications/conpherence/view/ConpherenceWidgetView.php',
'CountdownQuery' => 'applications/countdown/query/CountdownQuery.php',
'DarkConsoleController' => 'aphront/console/DarkConsoleController.php',
'DarkConsoleCore' => 'aphront/console/DarkConsoleCore.php',
'DarkConsoleDataController' => 'aphront/console/DarkConsoleDataController.php',
@ -998,6 +997,8 @@ phutil_register_library_map(array(
'PhabricatorCountdownDeleteController' => 'applications/countdown/controller/PhabricatorCountdownDeleteController.php',
'PhabricatorCountdownEditController' => 'applications/countdown/controller/PhabricatorCountdownEditController.php',
'PhabricatorCountdownListController' => 'applications/countdown/controller/PhabricatorCountdownListController.php',
'PhabricatorCountdownPHIDTypeCountdown' => 'applications/countdown/phid/PhabricatorCountdownPHIDTypeCountdown.php',
'PhabricatorCountdownQuery' => 'applications/countdown/query/PhabricatorCountdownQuery.php',
'PhabricatorCountdownRemarkupRule' => 'applications/countdown/remarkup/PhabricatorCountdownRemarkupRule.php',
'PhabricatorCountdownViewController' => 'applications/countdown/controller/PhabricatorCountdownViewController.php',
'PhabricatorCountedToggleButtonsExample' => 'applications/uiexample/examples/PhabricatorCountedToggleButtonsExample.php',
@ -2257,7 +2258,6 @@ phutil_register_library_map(array(
'ConpherenceViewController' => 'ConpherenceController',
'ConpherenceWidgetController' => 'ConpherenceController',
'ConpherenceWidgetView' => 'AphrontView',
'CountdownQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'DarkConsoleController' => 'PhabricatorController',
'DarkConsoleDataController' => 'PhabricatorController',
'DarkConsoleErrorLogPlugin' => 'DarkConsolePlugin',
@ -2996,6 +2996,8 @@ phutil_register_library_map(array(
'PhabricatorCountdownDeleteController' => 'PhabricatorCountdownController',
'PhabricatorCountdownEditController' => 'PhabricatorCountdownController',
'PhabricatorCountdownListController' => 'PhabricatorCountdownController',
'PhabricatorCountdownPHIDTypeCountdown' => 'PhabricatorPHIDType',
'PhabricatorCountdownQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorCountdownRemarkupRule' => 'PhabricatorRemarkupRuleObject',
'PhabricatorCountdownViewController' => 'PhabricatorCountdownController',
'PhabricatorCountedToggleButtonsExample' => 'PhabricatorUIExample',

View file

@ -17,7 +17,7 @@ final class PhabricatorCountdownDeleteController
$request = $this->getRequest();
$user = $request->getUser();
$countdown = id(new CountdownQuery())
$countdown = id(new PhabricatorCountdownQuery())
->setViewer($user)
->withIDs(array($this->id))
->executeOne();

View file

@ -18,7 +18,7 @@ final class PhabricatorCountdownEditController
$action_label = pht('Create Countdown');
if ($this->id) {
$countdown = id(new CountdownQuery())
$countdown = id(new PhabricatorCountdownQuery())
->setViewer($user)
->withIDs(array($this->id))
->executeOne();

View file

@ -14,7 +14,7 @@ final class PhabricatorCountdownListController
$pager = new AphrontCursorPagerView();
$pager->readFromRequest($request);
$query = id(new CountdownQuery())
$query = id(new PhabricatorCountdownQuery())
->setViewer($user);
$countdowns = $query->executeWithCursorPager($pager);

View file

@ -18,7 +18,7 @@ final class PhabricatorCountdownViewController
$request = $this->getRequest();
$user = $request->getUser();
$countdown = id(new CountdownQuery())
$countdown = id(new PhabricatorCountdownQuery())
->setViewer($user)
->withIDs(array($this->id))
->executeOne();

View file

@ -0,0 +1,75 @@
<?php
final class PhabricatorCountdownPHIDTypeCountdown extends PhabricatorPHIDType {
const TYPECONST = 'CDWN';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Countdown');
}
public function newObject() {
return new PhabricatorCountdown();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorCountdownQuery())
->setViewer($query->getViewer())
->withPHIDs($phids)
->execute();
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$countdown = $objects[$phid];
$name = $countdown->getTitle();
$id = $countdown->getID();
$handle->setName("C{$id}");
$handle->setFullName("C{$id}: {$name}");
$handle->setURI("/countdown/{$id}/");
}
}
public function canLoadNamedObject($name) {
return preg_match('/^C\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 PhabricatorCountdownQuery())
->setViewer($query->getViewer())
->withIDs(array_keys($id_map))
->execute();
$results = array();
foreach ($objects as $id => $object) {
foreach (idx($id_map, $id, array()) as $name) {
$results[$name] = $object;
}
}
return $results;
}
}

View file

@ -3,7 +3,7 @@
/**
* @group countdown
*/
final class CountdownQuery
final class PhabricatorCountdownQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;

View file

@ -12,7 +12,7 @@ final class PhabricatorCountdownRemarkupRule
protected function loadObjects(array $ids) {
$viewer = $this->getEngine()->getConfig('viewer');
return id(new CountdownQuery())
return id(new PhabricatorCountdownQuery())
->setViewer($viewer)
->withIDs($ids)
->execute();

View file

@ -3,7 +3,8 @@
/**
* @group countdown
*/
final class PhabricatorCountdown extends PhabricatorCountdownDAO
final class PhabricatorCountdown
extends PhabricatorCountdownDAO
implements PhabricatorPolicyInterface {
protected $id;
@ -20,11 +21,12 @@ final class PhabricatorCountdown extends PhabricatorCountdownDAO
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID('CDWN');
return PhabricatorPHID::generateNewPHID(
PhabricatorCountdownPHIDTypeCountdown::TYPECONST);
}
public function getViewPolicy() {
return "users";
return PhabricatorPolicies::POLICY_USER;
}
/* -( PhabricatorPolicyInterface Implementation )------------------------- */

View file

@ -30,7 +30,6 @@ final class PhabricatorPHIDConstants {
const PHID_TYPE_PAYM = 'PAYM';
const PHID_TYPE_CHRG = 'CHRG';
const PHID_TYPE_CART = 'CART';
const PHID_TYPE_CDWN = 'CDWN';
const PHID_TYPE_LEGD = 'LEGD';
const PHID_TYPE_LEGB = 'LEGB';

View file

@ -492,24 +492,6 @@ final class PhabricatorObjectHandleData {
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_CDWN:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Countdown');
} else {
$countdown = $objects[$phid];
$handle->setName($countdown->getTitle());
$handle->setFullName($countdown->getTitle());
$handle->setURI('/countdown/'.$countdown->getID().'/');
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_LEGD:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();