Uh oh!
There was an error while loading. Please reload this page.
forked from mapasculturais/plugin-MapasNetwork
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeBootstrapJobType.php
More file actions
Latest commit
94 lines (87 loc) · 3.57 KB
/
Copy pathNodeBootstrapJobType.php
File metadata and controls
94 lines (87 loc) · 3.57 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespaceMapasNetwork;
useMapasCulturais\ApiQuery;
useMapasCulturais\App;
useMapasCulturais\Entities\Agent;
useMapasCulturais\Entities\Job;
useMapasCulturais\Entities\Space;
class NodeBootstrapJobType extends \MapasCulturais\Definitions\JobType
{
protected$plugin;
function__construct(string$slug, Plugin$plugin)
{
$this->plugin = $plugin;
parent::__construct($slug);
return;
}
protectedfunction_execute(Job$job)
{
$app = App::i();
$node = $job->node;
$user = $node->user;
$file_groups = [
"agent" => array_keys($app->getRegisteredFileGroupsByEntity(Agent::class)),
"space" => array_keys($app->getRegisteredFileGroupsByEntity(Space::class)),
];
$metalist_groups = [
"agent" => array_keys($app->getRegisteredMetaListGroupsByEntity(Agent::class)),
"space" => array_keys($app->getRegisteredMetaListGroupsByEntity(Space::class)),
];
$map_ids = function ($entity) { return$entity->id; };
$map_serialize = function ($entity) use ($file_groups, $metalist_groups) {
if (Plugin::ensureNetworkID($entity)) {
$this->plugin->skip($entity, [Plugin::SKIP_BEFORE, Plugin::SKIP_AFTER]);
Plugin::saveMetadata($entity, ["network__id"]);
}
$serialised = $this->plugin->serializeEntity($entity);
$serialised = $this->plugin->serializeAttachments($entity, "files", $file_groups[$entity->controllerId], $serialised);
$serialised = $this->plugin->serializeAttachments($entity, "metalists", $metalist_groups[$entity->controllerId], $serialised);
return$serialised;
};
// agents
$agents_args = Plugin::parseFilters($node->getFilters('agent'));
$agent_ids = array_map($map_ids, $user->getEnabledAgents());
if ($agent_ids) { // it HAS been the case that this was reached with only a draft agent, thus the need to check
$agents_args["id"] = "IN(" . implode(",", $agent_ids) . ")";
$agents_query = newApiQuery(Agent::class, $agents_args);
$agent_ids = $agents_query->findIds();
if(!in_array($user->profile->id, $agent_ids)) {
$agent_ids[] = $user->profile->id;
}
$agents = $app->repo("Agent")->findBy(["id" => $agent_ids]);
} else {
$agents = [];
}
// spaces
$spaces_args = Plugin::parseFilters($node->getFilters('space'));
$space_ids = array_map($map_ids, $user->getEnabledSpaces());
if ($space_ids) {
$spaces_args["id"] = "IN(" . implode(",", $space_ids) . ")";
$spaces_query = newApiQuery(Space::class, $spaces_args);
$space_ids = $spaces_query->findIds();
$spaces = $app->repo("Space")->findBy(["id" => $space_ids]);
} else {
$spaces = [];
}
// POST data
$data = [
"nodeSlug" => $this->plugin->nodeSlug,
"agents" => array_map($map_serialize, $agents),
"spaces" => array_map($map_serialize, $spaces),
];
$node->api->apiPost("network-node/bootstrapSync", $data);
returntrue;
}
/**
*
* @param mixed $data
* @param string $start_string
* @param string $interval_string
* @param int $iterations
* @return string
*/
protectedfunction_generateId(array$data, string$start_string, string$interval_string, int$iterations)
{
return ("{$data["node"]}/bootstrapSync");
}
}