Changeset View
Changeset View
Standalone View
Standalone View
src/applications/nuance/source/NuanceSourceDefinition.php
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | abstract class NuanceSourceDefinition extends Phobject { | ||||
} | } | ||||
final public function getImportCursors() { | final public function getImportCursors() { | ||||
if (!$this->hasImportCursors()) { | if (!$this->hasImportCursors()) { | ||||
throw new Exception( | throw new Exception( | ||||
pht('This source has no input cursors.')); | pht('This source has no input cursors.')); | ||||
} | } | ||||
return $this->newImportCursors(); | $source = $this->getSource(); | ||||
$cursors = $this->newImportCursors(); | |||||
$data = id(new NuanceImportCursorDataQuery()) | |||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
->withSourcePHIDs(array($source->getPHID())) | |||||
->execute(); | |||||
$data = mpull($data, 'getCursorKey'); | |||||
$map = array(); | |||||
foreach ($cursors as $cursor) { | |||||
if (!($cursor instanceof NuanceImportCursor)) { | |||||
throw new Exception( | |||||
pht( | |||||
'Source "%s" (of class "%s") returned an invalid value from '. | |||||
'method "%s": all values must be objects of class "%s".', | |||||
$this->getName(), | |||||
get_class($this), | |||||
'newImportCursors()', | |||||
'NuanceImportCursor')); | |||||
} | |||||
$key = $cursor->getCursorKey(); | |||||
if (!strlen($key)) { | |||||
throw new Exception( | |||||
pht( | |||||
'Source "%s" (of class "%s") returned an import cursor with '. | |||||
'a missing key from "%s". Each cursor must have a unique, '. | |||||
'nonempty key.', | |||||
$this->getName(), | |||||
get_class($this), | |||||
'newImportCursors()')); | |||||
} | |||||
$other = idx($map, $key); | |||||
if ($other) { | |||||
throw new Exception( | |||||
pht( | |||||
'Source "%s" (of class "%s") returned two cursors from method '. | |||||
'"%s" with the same key ("%s"). Each cursor must have a unique '. | |||||
'key.', | |||||
$this->getName(), | |||||
get_class($this), | |||||
'newImportCursors()', | |||||
$key)); | |||||
} | |||||
$map[$key] = $cursor; | |||||
$cursor->setSource($source); | |||||
$cursor_data = idx($data, $key); | |||||
if (!$cursor_data) { | |||||
$cursor_data = $cursor->newEmptyCursorData($source); | |||||
} | |||||
$cursor->setCursorData($cursor_data); | |||||
} | |||||
return $cursors; | |||||
} | } | ||||
protected function newImportCursors() { | protected function newImportCursors() { | ||||
throw new PhutilMethodNotImplementedException(); | throw new PhutilMethodNotImplementedException(); | ||||
} | } | ||||
/** | /** | ||||
* A human readable string like "Twitter" or "Phabricator Form". | * A human readable string like "Twitter" or "Phabricator Form". | ||||
Show All 9 Lines | abstract class NuanceSourceDefinition extends Phobject { | ||||
/** | /** | ||||
* This should be a any VARCHAR(32). | * This should be a any VARCHAR(32). | ||||
* | * | ||||
* @{method:getAllDefinitions} will throw if you choose a string that | * @{method:getAllDefinitions} will throw if you choose a string that | ||||
* collides with another @{class:NuanceSourceDefinition} class. | * collides with another @{class:NuanceSourceDefinition} class. | ||||
*/ | */ | ||||
abstract public function getSourceTypeConstant(); | abstract public function getSourceTypeConstant(); | ||||
/** | public function renderView() { | ||||
* Code to create and update @{class:NuanceItem}s and | return null; | ||||
* @{class:NuanceRequestor}s via daemons goes here. | } | ||||
* | |||||
* If that does not make sense for the @{class:NuanceSource} you are | |||||
* defining, simply return null. For example, | |||||
* @{class:NuancePhabricatorFormSourceDefinition} since these are one-way | |||||
* contact forms. | |||||
*/ | |||||
abstract public function updateItems(); | |||||
abstract public function renderView(); | |||||
abstract public function renderListView(); | |||||
public function renderListView() { | |||||
return null; | |||||
} | |||||
protected function newItemFromProperties( | protected function newItemFromProperties( | ||||
NuanceRequestor $requestor, | NuanceRequestor $requestor, | ||||
array $properties, | array $properties, | ||||
PhabricatorContentSource $content_source) { | PhabricatorContentSource $content_source) { | ||||
// TODO: Should we have a tighter actor/viewer model? Requestors will | // TODO: Should we have a tighter actor/viewer model? Requestors will | ||||
// often have no real user associated with them... | // often have no real user associated with them... | ||||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |