Path: blob/master/src/applications/nuance/cursor/NuanceImportCursor.php
12256 views
<?php12abstract class NuanceImportCursor extends Phobject {34private $cursorData;5private $cursorKey;6private $source;7private $viewer;89abstract protected function shouldPullDataFromSource();10abstract protected function pullDataFromSource();1112final public function getCursorType() {13return $this->getPhobjectClassConstant('CURSORTYPE', 32);14}1516public function setCursorData(NuanceImportCursorData $cursor_data) {17$this->cursorData = $cursor_data;18return $this;19}2021public function getCursorData() {22return $this->cursorData;23}2425public function setSource($source) {26$this->source = $source;27return $this;28}2930public function getSource() {31return $this->source;32}3334public function setCursorKey($cursor_key) {35$this->cursorKey = $cursor_key;36return $this;37}3839public function getCursorKey() {40return $this->cursorKey;41}4243public function setViewer($viewer) {44$this->viewer = $viewer;45return $this;46}4748public function getViewer() {49return $this->viewer;50}5152final public function importFromSource() {53if (!$this->shouldPullDataFromSource()) {54return false;55}5657$source = $this->getSource();58$key = $this->getCursorKey();5960$parts = array(61'nsc',62$source->getID(),63PhabricatorHash::digestToLength($key, 20),64);65$lock_name = implode('.', $parts);6667$lock = PhabricatorGlobalLock::newLock($lock_name);68$lock->lock(1);6970try {71$more_data = $this->pullDataFromSource();72} catch (Exception $ex) {73$lock->unlock();74throw $ex;75}7677$lock->unlock();7879return $more_data;80}8182final public function newEmptyCursorData(NuanceSource $source) {83return id(new NuanceImportCursorData())84->setCursorKey($this->getCursorKey())85->setCursorType($this->getCursorType())86->setSourcePHID($source->getPHID());87}8889final protected function logInfo($message) {90echo tsprintf(91"<cursor:%s> %s\n",92$this->getCursorKey(),93$message);9495return $this;96}9798final protected function getCursorProperty($key, $default = null) {99return $this->getCursorData()->getCursorProperty($key, $default);100}101102final protected function setCursorProperty($key, $value) {103$this->getCursorData()->setCursorProperty($key, $value);104return $this;105}106107}108109110