4 * @task action Handling Action Requests
6 abstract class NuanceSourceDefinition
extends Phobject
{
11 public function setViewer(PhabricatorUser
$viewer) {
12 $this->viewer
= $viewer;
16 public function getViewer() {
18 throw new PhutilInvalidStateException('setViewer');
23 public function setSource(NuanceSource
$source) {
24 $this->source
= $source;
28 public function getSource() {
30 throw new PhutilInvalidStateException('setSource');
35 public function getSourceViewActions(AphrontRequest
$request) {
39 public static function getAllDefinitions() {
40 return id(new PhutilClassMapQuery())
41 ->setAncestorClass(__CLASS__
)
42 ->setUniqueMethod('getSourceTypeConstant')
46 public function hasImportCursors() {
50 final public function getImportCursors() {
51 if (!$this->hasImportCursors()) {
53 pht('This source has no input cursors.'));
56 $viewer = PhabricatorUser
::getOmnipotentUser();
57 $source = $this->getSource();
58 $cursors = $this->newImportCursors();
60 $data = id(new NuanceImportCursorDataQuery())
62 ->withSourcePHIDs(array($source->getPHID()))
64 $data = mpull($data, null, 'getCursorKey');
67 foreach ($cursors as $cursor) {
68 if (!($cursor instanceof NuanceImportCursor
)) {
71 'Source "%s" (of class "%s") returned an invalid value from '.
72 'method "%s": all values must be objects of class "%s".',
76 'NuanceImportCursor'));
79 $key = $cursor->getCursorKey();
83 'Source "%s" (of class "%s") returned an import cursor with '.
84 'a missing key from "%s". Each cursor must have a unique, '.
88 'newImportCursors()'));
91 $other = idx($map, $key);
95 'Source "%s" (of class "%s") returned two cursors from method '.
96 '"%s" with the same key ("%s"). Each cursor must have a unique '.
100 'newImportCursors()',
104 $map[$key] = $cursor;
106 $cursor_data = idx($data, $key);
108 $cursor_data = $cursor->newEmptyCursorData($source);
114 ->setCursorData($cursor_data);
120 protected function newImportCursors() {
121 throw new PhutilMethodNotImplementedException();
125 * A human readable string like "Twitter" or "Phabricator Form".
127 abstract public function getName();
131 * Human readable description of this source, a sentence or two long.
133 abstract public function getSourceDescription();
136 * This should be a any VARCHAR(32).
138 * @{method:getAllDefinitions} will throw if you choose a string that
139 * collides with another @{class:NuanceSourceDefinition} class.
141 abstract public function getSourceTypeConstant();
143 public function renderView() {
147 public function renderListView() {
151 protected function newItemFromProperties(
155 PhabricatorContentSource
$content_source) {
157 // TODO: Should we have a tighter actor/viewer model? Requestors will
158 // often have no real user associated with them...
159 $actor = PhabricatorUser
::getOmnipotentUser();
160 $source = $this->getSource();
162 $item = NuanceItem
::initializeNewItem($item_type);
166 $xactions[] = id(new NuanceItemTransaction())
167 ->setTransactionType(NuanceItemSourceTransaction
::TRANSACTIONTYPE
)
168 ->setNewValue($source->getPHID());
170 // TODO: Eventually, apply real routing rules. For now, just put everything
171 // in the default queue for the source.
172 $xactions[] = id(new NuanceItemTransaction())
173 ->setTransactionType(NuanceItemQueueTransaction
::TRANSACTIONTYPE
)
174 ->setNewValue($source->getDefaultQueuePHID());
176 // TODO: Maybe this should all be modular transactions now?
177 foreach ($properties as $key => $property) {
178 $xactions[] = id(new NuanceItemTransaction())
179 ->setTransactionType(NuanceItemPropertyTransaction
::TRANSACTIONTYPE
)
180 ->setMetadataValue(NuanceItemTransaction
::PROPERTY_KEY
, $key)
181 ->setNewValue($property);
184 $editor = id(new NuanceItemEditor())
186 ->setActingAsPHID($author_phid)
187 ->setContentSource($content_source);
189 $editor->applyTransactions($item, $xactions);
194 public function renderItemEditProperties(
195 PhabricatorUser
$viewer,
197 PHUIPropertyListView
$view) {
202 /* -( Handling Action Requests )------------------------------------------- */
205 public function handleActionRequest(AphrontRequest
$request) {
206 return new Aphront404Response();
209 public function getActionURI($path = null) {
210 $source_id = $this->getSource()->getID();
211 return '/action/'.$source_id.'/'.ltrim($path, '/');