forked from mapasculturais/plugin-MapasNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyncMetaListJobType.php
More file actions
57 lines (52 loc) · 1.78 KB
/
SyncMetaListJobType.php
File metadata and controls
57 lines (52 loc) · 1.78 KB
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
51
52
53
54
55
56
57
<?php
namespace MapasNetwork;
use MapasCulturais\App;
use MapasCulturais\Entities\Job;
class SyncMetaListJobType extends \MapasCulturais\Definitions\JobType
{
protected $plugin;
function __construct(string $slug, Plugin $plugin)
{
$this->plugin = $plugin;
parent::__construct($slug);
return;
}
protected function _execute(Job $job)
{
$action = $job->syncAction;
$entity = $job->entity;
$node = $job->node;
$network_id = array_search($entity->id, (array) $entity->owner->network__metalist_ids);
$data = [
"nodeSlug" => $this->plugin->nodeSlug,
"ownerClassName" => $entity->owner->className,
"ownerNetworkID" => $entity->owner->network__id,
"className" => $entity->className,
"network__id" => $network_id,
"network__metalist_revisions" => $entity->owner->network__metalist_revisions,
"data" => $this->plugin->serializeEntity($entity)
];
try {
Plugin::log("SYNC: $entity -> {$node->url}");
$node->api->apiPost("network-node/{$action}", $data, [],
[CURLOPT_TIMEOUT => 30]);
} catch (\MapasSDK\Exceptions\UnexpectedError $e) {
Plugin::log($e->getMessage());
return false;
}
return true;
}
/**
*
* @param mixed $data
* @param string $start_string
* @param string $interval_string
* @param int $iterations
* @return string
*/
protected function _generateId(array $data, string $start_string,
string $interval_string, int $iterations)
{
return "{$data["entity"]->className}:{$data["entity"]->id}->{$data["node"]}/{$data["syncAction"]}";
}
}