Commit f00b43d4 authored by epriestley's avatar epriestley
Browse files

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
parent 3aa5fcfc
......@@ -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',
......
......@@ -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();
......
......@@ -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();
......
......@@ -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);
......
......@@ -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();
......
<?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;
}
}
......@@ -3,7 +3,7 @@
/**
* @group countdown
*/
final class CountdownQuery
final class PhabricatorCountdownQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
......
......@@ -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();
......
......@@ -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 )------------------------- */
......
......@@ -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';
......
......@@ -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();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment