52 $this->valueHashToValueContainerId = new \SplObjectStorage();
53 $this->bucketHashToObserverContainerId = new \SplObjectStorage();
54 $this->taskHashToTaskContainerId = new \SplObjectStorage();
59 if (!self::$instance) {
63 return self::$instance;
103 $bucketContainer->setUserId($bucket->
getUserId());
104 $bucketContainer->setState($bucket->
getState());
105 $bucketContainer->setTotalNumberoftasks(count($bucket->
getTask()->unfoldTask()));
107 $bucketContainer->setTitle($bucket->
getTitle());
114 $bucketContainer->update();
124 ->orderBy($order_by, $order_direction)
125 ->getArray(null,
'id');
140 $bucketMeta->setUserId($bucketContainer->
getUserId());
141 $bucketMeta->setState($bucketContainer->
getState());
142 $bucketMeta->setTitle($bucketContainer->
getTitle());
144 $bucketMeta->setOverallPercentage($bucketContainer->
getPercentage());
160 return $bucket_container->
getId();
176 if ($this->bucketHashToObserverContainerId->contains($bucket)) {
177 $bucketContainer =
new BucketContainer($this->bucketHashToObserverContainerId[$bucket], $this->connector);
183 $bucketContainer->setUserId($bucket->
getUserId());
184 $bucketContainer->setState($bucket->
getState());
185 $bucketContainer->setTitle($bucket->
getTitle());
187 $bucketContainer->setTotalNumberoftasks(count($bucket->
getTask()->unfoldTask()));
191 if (!$bucketContainer->getId()) {
192 $bucketContainer->create();
204 $bucketContainer->save();
205 $this->bucketHashToObserverContainerId[$bucket] = $bucketContainer->getId();
219 if ($this->taskHashToTaskContainerId->contains($task)) {
220 $taskContainer =
new TaskContainer($this->taskHashToTaskContainerId[$task], $this->connector);
226 $taskContainer->setType($task->
getType());
227 $taskContainer->setBucketId($bucketId);
228 $reflection = new \ReflectionClass(get_class($task));
229 $taskContainer->setClassName(get_class($task));
231 $absolute_class_path = $reflection->getFileName();
233 $taskContainer->setClassPath($reflection->getFileName());
239 $this->saveValueToTask($task, $taskContainer, $bucketId);
242 $taskContainer->save();
243 $this->taskHashToTaskContainerId[$task] = $taskContainer->getId();
255 protected function saveValueToTask(
Task $task,
TaskContainer $taskContainer, $bucketId)
258 if ($taskContainer->
getId()) {
261 foreach ($olds as $old) {
266 $taskContainer->
save();
270 foreach ($task->
getInput() as $k => $inputValue) {
272 $v->setTaskId($taskContainer->
getId());
274 $v->setBucketId($bucketId);
291 if ($this->valueHashToValueContainerId->contains($value)) {
292 $valueContainer =
new ValueContainer($this->valueHashToValueContainerId[$value], $this->connector);
298 $reflection = new \ReflectionClass(get_class($value));
299 $valueContainer->setClassName(get_class($value));
304 $valueContainer->setType($value->
getType());
306 $valueContainer->setBucketId($bucketId);
307 $valueContainer->setPosition($position);
308 $valueContainer->setHash($value->
getHash());
309 $valueContainer->setSerialized($value->serialize());
318 $valueContainer->save();
319 $this->valueHashToValueContainerId->attach($value, $valueContainer->getId());
331 if (!$this->bucketHashToObserverContainerId->contains(($bucket))) {
333 . print_r($bucket,
true));
336 return $this->bucketHashToObserverContainerId[$bucket];
348 if (!$this->taskHashToTaskContainerId->contains($task)) {
350 . print_r($task,
true));
353 return $this->taskHashToTaskContainerId[$task];
365 if (!$this->valueHashToValueContainerId->contains($value)) {
367 . print_r($value,
true));
370 return (
int) $this->valueHashToValueContainerId[$value];
382 if (isset(self::$buckets[$bucket_id])) {
383 return self::$buckets[$bucket_id];
386 $bucketContainer = BucketContainer::find($bucket_id);
387 if (!$bucketContainer) {
388 throw new BucketNotFoundException(
"The requested bucket with container id $bucket_id could not be found in the database.");
392 $bucket->setUserId($bucketContainer->getUserId());
393 $bucket->setState($bucketContainer->getState());
394 $bucket->setTitle($bucketContainer->getTitle());
395 $bucket->setDescription($bucketContainer->getDescription());
396 $bucket->setOverallPercentage($bucketContainer->getPercentage());
397 $bucket->setLastHeartbeat($bucketContainer->getLastHeartbeat());
398 $bucket->setTask($this->loadTask($bucketContainer->getRootTaskid(), $bucket, $bucketContainer));
400 $this->bucketHashToObserverContainerId[$bucket] = $bucket_id;
420 $factory = $DIC->backgroundTasks()->taskFactory();
422 $taskContainer = TaskContainer::find($taskContainerId);
433 ->orderBy(
'position')
437 foreach ($valueToTasks as $valueToTask) {
438 $inputs[] = $this->loadValue($valueToTask->getValueId(), $bucket, $bucketContainer);
446 $this->taskHashToTaskContainerId[$task] = $taskContainerId;
455 $factory = $DIC->backgroundTasks()->injector();
458 $valueContainer = ValueContainer::find($valueContainerId);
462 $value =
$factory->createInstance($valueContainer->getClassName());
464 $value->unserialize($valueContainer->getSerialized());
465 if ($valueContainer->getHasParenttask()) {
466 $value->setParentTask($this->loadTask($valueContainer->getParentTaskid(), $bucket, $bucketContainer));
469 $this->valueHashToValueContainerId[$value] = $valueContainerId;
511 $this->bucketHashToObserverContainerId->detach($bucket);
523 foreach ($bucket_container_id as $bucket_id) {
setConnector(\arConnector $connector)
Currently for testing only.
saveObserver(Bucket $bucket)
saveValue(Value $value, $bucketId, $position)
getValueContainerId($value)
deleteBucket($bucket)
Delete the bucket and all its stuff.Bucketvoid
if(!array_key_exists('StateId', $_REQUEST)) $id
__construct()
BasicPersistence constructor.
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)
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)