50 if (!self::$instance) {
54 return self::$instance;
91 $bucketContainer->setUserId($bucket->
getUserId());
92 $bucketContainer->setState($bucket->
getState());
93 $bucketContainer->setTotalNumberoftasks(count($bucket->
getTask()->unfoldTask()));
95 $bucketContainer->setTitle($bucket->
getTitle());
102 $bucketContainer->update();
112 ->orderBy($order_by, $order_direction)
113 ->getArray(null,
'id');
128 $bucketMeta->setUserId($bucketContainer->
getUserId());
129 $bucketMeta->setState($bucketContainer->
getState());
130 $bucketMeta->setTitle($bucketContainer->
getTitle());
132 $bucketMeta->setOverallPercentage($bucketContainer->
getPercentage());
148 return $bucket_container->
getId();
164 if (isset($this->bucketHashToObserverContainerId[spl_object_hash($bucket)])) {
165 $bucketContainer =
new BucketContainer($this->bucketHashToObserverContainerId[spl_object_hash($bucket)], $this->connector);
171 $bucketContainer->setUserId($bucket->
getUserId());
172 $bucketContainer->setState($bucket->
getState());
173 $bucketContainer->setTitle($bucket->
getTitle());
175 $bucketContainer->setTotalNumberoftasks(count($bucket->
getTask()->unfoldTask()));
179 if (!$bucketContainer->getId()) {
180 $bucketContainer->create();
192 $bucketContainer->save();
193 $this->bucketHashToObserverContainerId[spl_object_hash($bucket)] = $bucketContainer->getId();
207 if (isset($this->taskHashToTaskContainerId[spl_object_hash($task)])) {
208 $taskContainer =
new TaskContainer($this->taskHashToTaskContainerId[spl_object_hash($task)], $this->connector);
214 $taskContainer->setType($task->
getType());
215 $taskContainer->setBucketId($bucketId);
216 $reflection = new \ReflectionClass(get_class($task));
217 $taskContainer->setClassName(get_class($task));
218 $taskContainer->setClassPath($reflection->getFileName());
221 foreach ($task->
getInput() as $input) {
224 $this->saveValueToTask($task, $taskContainer, $bucketId);
227 $taskContainer->save();
228 $this->taskHashToTaskContainerId[spl_object_hash($task)] = $taskContainer->getId();
240 protected function saveValueToTask(
Task $task,
TaskContainer $taskContainer, $bucketId)
243 if ($taskContainer->
getId()) {
246 foreach ($olds as
$old) {
251 $taskContainer->
save();
255 foreach ($task->
getInput() as $inputValue) {
257 $v->setTaskId($taskContainer->
getId());
258 $v->setBucketId($bucketId);
275 if (isset($this->valueHashToValueContainerId[spl_object_hash($value)])) {
276 $valueContainer =
new ValueContainer($this->valueHashToValueContainerId[spl_object_hash($value)], $this->connector);
282 $reflection = new \ReflectionClass(get_class($value));
283 $valueContainer->setClassName(get_class($value));
284 $valueContainer->setClassPath($reflection->getFileName());
285 $valueContainer->setType($value->
getType());
287 $valueContainer->setBucketId($bucketId);
288 $valueContainer->setHash($value->
getHash());
289 $valueContainer->setSerialized($value->serialize());
298 $valueContainer->save();
299 $this->valueHashToValueContainerId[spl_object_hash($value)] = $valueContainer->getId();
311 if (!isset($this->bucketHashToObserverContainerId[spl_object_hash($bucket)])) {
313 . print_r($bucket,
true));
316 return $this->bucketHashToObserverContainerId[spl_object_hash($bucket)];
328 if (!isset($this->taskHashToTaskContainerId[spl_object_hash($task)])) {
330 . print_r($task,
true));
333 return $this->taskHashToTaskContainerId[spl_object_hash($task)];
345 if (!isset($this->valueHashToValueContainerId[spl_object_hash($value)])) {
347 . print_r($value,
true));
350 return $this->valueHashToValueContainerId[spl_object_hash($value)];
362 if (isset(self::$buckets[$bucket_id])) {
363 return self::$buckets[$bucket_id];
366 $bucketContainer = BucketContainer::find($bucket_id);
367 if (!$bucketContainer) {
368 throw new BucketNotFoundException(
"The requested bucket with container id $bucket_id could not be found in the database.");
372 $bucket->setUserId($bucketContainer->getUserId());
373 $bucket->setState($bucketContainer->getState());
374 $bucket->setTitle($bucketContainer->getTitle());
375 $bucket->setDescription($bucketContainer->getDescription());
376 $bucket->setOverallPercentage($bucketContainer->getPercentage());
377 $bucket->setLastHeartbeat($bucketContainer->getLastHeartbeat());
378 $bucket->setTask($this->loadTask($bucketContainer->getRootTaskid(), $bucket, $bucketContainer));
380 $this->bucketHashToObserverContainerId[spl_object_hash($bucket)] = $bucket_id;
400 $factory = $DIC->backgroundTasks()->taskFactory();
402 $taskContainer = TaskContainer::find($taskContainerId);
413 foreach ($valueToTasks as $valueToTask) {
414 $inputs[] = $this->loadValue($valueToTask->getValueId(), $bucket, $bucketContainer);
416 $task->setInput($inputs);
422 $this->taskHashToTaskContainerId[spl_object_hash($task)] = $taskContainerId;
431 $factory = $DIC->backgroundTasks()->injector();
434 $valueContainer = ValueContainer::find($valueContainerId);
436 require_once($valueContainer->getClassPath());
438 $value =
$factory->createInstance($valueContainer->getClassName());
440 $value->unserialize($valueContainer->getSerialized());
441 if ($valueContainer->getHasParenttask()) {
442 $value->setParentTask($this->loadTask($valueContainer->getParentTaskid(), $bucket, $bucketContainer));
445 $this->valueHashToValueContainerId[spl_object_hash($value)] = $valueContainerId;
486 unset($this->bucketHashToObserverContainerId[spl_object_hash($bucket)]);
498 foreach ($bucket_container_id as $bucket_id) {
setConnector(\arConnector $connector)
Currently for testing only.
saveObserver(Bucket $bucket)
getValueContainerId($value)
deleteBucket($bucket)
Delete the bucket and all its stuff.Bucketvoid
if(!array_key_exists('StateId', $_REQUEST)) $id
static where($where, $operator=null)
getBucketContainerId(Bucket $bucket)
$bucketHashToObserverContainerId
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
$valueHashToValueContainerId
getBucketMetaOfUser($user_id)
updateBucket(Bucket $bucket)
Updates only the bucket! Use this if e.g.
getLastHeartbeat()
When was the last time that something happened on this bucket?
saveBucketAndItsTasks(Bucket $bucket)
Fully updates or creates an Observer and all its tasks into the database.
$taskHashToTaskContainerId
getBucketIdsByState($state)
intint[] Returns a list of bucket ids for the given Observer State
saveTask(Task $task, $bucketId)
saveValue(Value $value, $bucketId)
getTaskContainerId(Task $task)
deleteBucketById($bucket_id)
Deletes the Observer AND all its tasks and values.
getBucketIdsOfUser($user_id, $order_by="id", $order_direction="ASC")
[] Returns an array of bucket ids for the given user Id.
loadBucket($bucket_container_id)
loadBuckets($bucket_container_id)