Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/nuance/cursor/NuanceImportCursor.php
12256 views
1
<?php
2
3
abstract class NuanceImportCursor extends Phobject {
4
5
private $cursorData;
6
private $cursorKey;
7
private $source;
8
private $viewer;
9
10
abstract protected function shouldPullDataFromSource();
11
abstract protected function pullDataFromSource();
12
13
final public function getCursorType() {
14
return $this->getPhobjectClassConstant('CURSORTYPE', 32);
15
}
16
17
public function setCursorData(NuanceImportCursorData $cursor_data) {
18
$this->cursorData = $cursor_data;
19
return $this;
20
}
21
22
public function getCursorData() {
23
return $this->cursorData;
24
}
25
26
public function setSource($source) {
27
$this->source = $source;
28
return $this;
29
}
30
31
public function getSource() {
32
return $this->source;
33
}
34
35
public function setCursorKey($cursor_key) {
36
$this->cursorKey = $cursor_key;
37
return $this;
38
}
39
40
public function getCursorKey() {
41
return $this->cursorKey;
42
}
43
44
public function setViewer($viewer) {
45
$this->viewer = $viewer;
46
return $this;
47
}
48
49
public function getViewer() {
50
return $this->viewer;
51
}
52
53
final public function importFromSource() {
54
if (!$this->shouldPullDataFromSource()) {
55
return false;
56
}
57
58
$source = $this->getSource();
59
$key = $this->getCursorKey();
60
61
$parts = array(
62
'nsc',
63
$source->getID(),
64
PhabricatorHash::digestToLength($key, 20),
65
);
66
$lock_name = implode('.', $parts);
67
68
$lock = PhabricatorGlobalLock::newLock($lock_name);
69
$lock->lock(1);
70
71
try {
72
$more_data = $this->pullDataFromSource();
73
} catch (Exception $ex) {
74
$lock->unlock();
75
throw $ex;
76
}
77
78
$lock->unlock();
79
80
return $more_data;
81
}
82
83
final public function newEmptyCursorData(NuanceSource $source) {
84
return id(new NuanceImportCursorData())
85
->setCursorKey($this->getCursorKey())
86
->setCursorType($this->getCursorType())
87
->setSourcePHID($source->getPHID());
88
}
89
90
final protected function logInfo($message) {
91
echo tsprintf(
92
"<cursor:%s> %s\n",
93
$this->getCursorKey(),
94
$message);
95
96
return $this;
97
}
98
99
final protected function getCursorProperty($key, $default = null) {
100
return $this->getCursorData()->getCursorProperty($key, $default);
101
}
102
103
final protected function setCursorProperty($key, $value) {
104
$this->getCursorData()->setCursorProperty($key, $value);
105
return $this;
106
}
107
108
}
109
110