aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Job/ProcessIncomingPush.php
blob: 2d27f80b660334b924ae286eb43ab1b302172466 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Digitigrade\Job;

use Digitigrade\Job;
use Digitigrade\Logger;
use Digitigrade\Model\Actor;
use Digitigrade\Model\Interaction;
use Digitigrade\Model\Note;

class ProcessIncomingPush extends Job {
    public \stdClass $object;

    public function __construct(\stdClass $object) {
        $this->object = $object;
        $this->remainingTries = 3;
    }

    public function run() {
        assert(isset($this->object->type));
        $log = Logger::getInstance();
        $type = $this->object->type;
        if ($type == 'tombstone') {
            if (!isset($this->object->previousType)) {
                throw new \RuntimeException('tombstone object does not have a previousType');
            }
            $log->info('the following object import is actually a tombstone ...');
            $type = $this->object->previousType;
        }
        switch ($type) {
            case 'actor':
                $log->info('importing actor with uri ' . $this->object->self);
                Actor::importFromReceivedObject($this->object);
                break;
            case 'note':
                $log->info('importing note with uri ' . $this->object->self);
                $note = Note::importFromReceivedObject($this->object);
                $note->processTimelineAdditions();
                break;
            case 'interaction':
                $log->info('importing interaction with uri ' . $this->object->self);
                $interaction = Interaction::importFromReceivedObject($this->object);
                $interaction->processTimelineAdditions();
                break;
            case 'extension':
                throw new \RuntimeException('object type ' . $this->object->type . ' not yet implemented :(');
            default:
                throw new \RuntimeException('invalid object type: ' . $this->object->type);
        }
    }
}