forked from mapasculturais/plugin-MapasNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyncEntityJobType.php
More file actions
64 lines (58 loc) · 2 KB
/
SyncEntityJobType.php
File metadata and controls
64 lines (58 loc) · 2 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
58
59
60
61
62
63
64
<?php
namespace MapasNetwork;
use MapasCulturais\App;
use MapasCulturais\Entities\Job;
class SyncEntityJobType extends \MapasCulturais\Definitions\JobType
{
/**
* MapasNetwork Plugin
* @var Plugin
*/
protected $plugin;
function __construct(string $slug, Plugin $plugin)
{
$this->plugin = $plugin;
parent::__construct($slug);
}
protected function _execute(Job $job)
{
$app = App::i();
$action = $job->syncAction;
$entity = $job->entity;
$node = $job->node;
$class_name = $entity->getClassName();
$data = $this->plugin->serializeEntity($entity);
if (in_array($action, [Plugin::ACTION_RESYNC, Plugin::ACTION_SCOPED])) {
$groups = array_keys($app->getRegisteredFileGroupsByEntity($class_name));
$data = $this->plugin->serializeAttachments($entity, "files", $groups, $data);
$groups = array_keys($app->getRegisteredMetaListGroupsByEntity($class_name));
$data = $this->plugin->serializeAttachments($entity, "metalists", $groups, $data);
}
$data = [
"nodeSlug" => $this->plugin->nodeSlug,
"className" => $class_name,
"network__id" => $entity->network__id,
"data" => $data,
];
try {
Plugin::log("SYNC: [[$action]] {$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 (string) $data['entity'] . '->' . $data['node'] . '/' . $data['syncAction'];
}
}