forked from mapasculturais/plugin-MapasNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateNetworkIdJobType.php
More file actions
57 lines (52 loc) · 1.68 KB
/
UpdateNetworkIdJobType.php
File metadata and controls
57 lines (52 loc) · 1.68 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\Entities\Job;
/**
* @package MapasNetwork
*/
class UpdateNetworkIdJobType extends \MapasCulturais\Definitions\JobType
{
protected $plugin;
function __construct(string $slug, Plugin $plugin)
{
$this->plugin = $plugin;
parent::__construct($slug);
return;
}
protected function _execute(Job $job)
{
$skip_node = $job->node;
$entity = $job->entity;
// ugly but we need these registrations and they can't be moved to Plugin::register
$this->plugin->registerEntityMetadataKeyForNodes(Plugin::getEntityNodes($entity->owner));
if ($job->current_network__id == $job->new_network__id) {
return true;
}
$this->plugin->foreachEntityNodeDo($entity, function ($node, $entity) use ($job, $skip_node) {
if ($node->equals($skip_node)) {
return;
}
$data = [
"className" => $entity->className,
"current_network__id" => $job->current_network__id,
"nodeSlug" => $this->plugin->nodeSlug,
"new_network__id" => $job->new_network__id
];
$node->api->apiPost("network-node/updateEntityNetworkId", $data);
return;
});
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["node"]}/{$data["entity"]}/updateEntityNetworkId");
}
}