Changeset View
Changeset View
Standalone View
Standalone View
src/applications/nuance/cursor/NuanceImportCursor.php
<?php | <?php | ||||
abstract class NuanceImportCursor extends Phobject { | abstract class NuanceImportCursor extends Phobject { | ||||
private $cursorData; | |||||
private $cursorKey; | |||||
private $source; | |||||
abstract protected function shouldPullDataFromSource(); | |||||
abstract protected function pullDataFromSource(); | |||||
final public function getCursorType() { | |||||
return $this->getPhobjectClassConstant('CURSORTYPE', 32); | |||||
} | |||||
public function setCursorData(NuanceImportCursorData $cursor_data) { | |||||
$this->cursorData = $cursor_data; | |||||
return $this; | |||||
} | |||||
public function getCursorData() { | |||||
return $this->cursorData; | |||||
} | |||||
public function setSource($source) { | |||||
$this->source = $source; | |||||
return $this; | |||||
} | |||||
public function getSource() { | |||||
return $this->source; | |||||
} | |||||
public function setCursorKey($cursor_key) { | |||||
$this->cursorKey = $cursor_key; | |||||
return $this; | |||||
} | |||||
public function getCursorKey() { | |||||
return $this->cursorKey; | |||||
} | |||||
final public function importFromSource() { | final public function importFromSource() { | ||||
// TODO: Perhaps, do something. | if (!$this->shouldPullDataFromSource()) { | ||||
return false; | return false; | ||||
} | } | ||||
$source = $this->getSource(); | |||||
$key = $this->getCursorKey(); | |||||
$parts = array( | |||||
'nsc', | |||||
$source->getID(), | |||||
PhabricatorHash::digestToLength($key, 20), | |||||
); | |||||
$lock_name = implode('.', $parts); | |||||
$lock = PhabricatorGlobalLock::newLock($lock_name); | |||||
$lock->lock(1); | |||||
try { | |||||
$more_data = $this->pullDataFromSource(); | |||||
} catch (Exception $ex) { | |||||
$lock->unlock(); | |||||
throw $ex; | |||||
} | |||||
$lock->unlock(); | |||||
return $more_data; | |||||
} | |||||
final public function newEmptyCursorData(NuanceSource $source) { | |||||
return id(new NuanceImportCursorData()) | |||||
->setCursorKey($this->getCursorKey()) | |||||
->setCursorType($this->getCursorType()) | |||||
->setSourcePHID($source->getPHID()); | |||||
} | |||||
final protected function logInfo($message) { | |||||
echo tsprintf( | |||||
"<cursor:%s> %s\n", | |||||
$this->getCursorKey(), | |||||
$message); | |||||
return $this; | |||||
} | |||||
final protected function getCursorProperty($key, $default = null) { | |||||
return $this->getCursorData()->getCursorProperty($key, $default); | |||||
} | |||||
final protected function setCursorProperty($key, $value) { | |||||
$this->getCursorData()->setCursorProperty($key, $value); | |||||
return $this; | |||||
} | |||||
} | } |