forked from mapasculturais/plugin-MapasNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyncDeletionJobType.php
More file actions
65 lines (60 loc) · 2.17 KB
/
SyncDeletionJobType.php
File metadata and controls
65 lines (60 loc) · 2.17 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
<?php
namespace MapasNetwork;
use MapasCulturais\App;
use MapasCulturais\Entities\Job;
class SyncDeletionJobType extends \MapasCulturais\Definitions\JobType
{
protected $plugin;
function __construct(string $slug, Plugin $plugin)
{
$this->plugin = $plugin;
parent::__construct($slug);
return;
}
protected function _execute(Job $job)
{
$app = App::i();
$node = $job->node;
$data = [
"nodeSlug" => $this->plugin->nodeSlug,
"className" => $job->className,
"network__id" => $job->networkID,
"ownerClassName" => $job->ownerClassName,
"ownerNetworkID" => $job->ownerNetworkID,
"group" => $job->group,
$job->revisions_key => $job->revisions,
];
try {
Plugin::log("SYNC: {$job->className}:{$job->entity["id"]} " .
"-> {$node->url}");
$node->api->apiPost("network-node/{$job->syncAction}", $data, [],
[CURLOPT_TIMEOUT => 30]);
$target_network_id = in_array($job->className, ["Agent", "Space"]) ? $job->networkID : $job->ownerNetworkID;
$entity = $this->plugin->getEntityByNetworkId($target_network_id);
if (($entity != null) && ($target_network_id == $job->networkID)) {
$meta_key = $node->entityMetadataKey;
$entity->$meta_key = 0;
$this->plugin->skip($entity, [Plugin::SKIP_BEFORE, Plugin::SKIP_AFTER]);
$entity->save(true);
}
} 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["className"]}:{$data["entity"]["id"]}->" .
"{$data["node"]}/{$data["syncAction"]}");
}
}