-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjomres2jomres_changelog_item_process_review_unpublished.php
103 lines (83 loc) · 3.39 KB
/
jomres2jomres_changelog_item_process_review_unpublished.php
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
95
96
97
98
99
100
<?php
/**
* Jomres CMS Agnostic Plugin
* @author Woollyinwales IT <sales@jomres.net>
* @version Jomres 9
* @package Jomres
* @copyright 2005-2020 Vince Wooll
* Jomres (tm) PHP files are released under both MIT and GPL2 licenses. This means that you can choose the license that best suits your project.
**/
// ################################################################
defined( '_JOMRES_INITCHECK' ) or die( 'Direct Access to this file is not allowed.' );
// ################################################################
/**
*
* @package Jomres\CMF
*
* Handles webhook events on the parent server
*
*
*/
class jomres2jomres_changelog_item_process_review_unpublished
{
function __construct($componetArgs)
{
$item = unserialize(base64_decode($componetArgs->item));
if ( isset($item->data->property_uid) ) {
$item_type = "reviews";
$cross_references = channelmanagement_framework_utilities :: get_cross_references_for_property_uid ( 'jomres2jomres' , $componetArgs->property_uid , $item_type );
jr_import('channelmanagement_jomres2jomres_communication');
$remote_server_communication = new channelmanagement_jomres2jomres_communication();
$response = $remote_server_communication->communicate( "GET" , '/cmf/property/reviews/'.$item->data->property_uid , [] , true );
if (!isset($response->reviews)) { // No reviews returned
$this->success = false;
return;
}
$response = json_decode(json_encode($response->reviews), true);
jr_import('jomres_call_api');
$jomres_call_api = new jomres_call_api('system');
if (is_array($response) ) {
foreach ($response as $reviews) {
foreach ($reviews as $review ) {
if ($review['rating_id'] == $item->data->review_uid) {
$local_id = 0;
foreach ($cross_references as $rev) {
if ($rev["remote_id"] == $item->data->review_uid) {
$local_id = $rev['local_id'];
}
}
$put_data = array(
"property_uid" => $componetArgs->property_uid,
"review_id" => $local_id
);
$send_response = $jomres_call_api->send_request(
"PUT",
"cmf/property/review/unpublish",
$put_data,
array("X-JOMRES-channel-name: " . "jomres2jomres", "X-JOMRES-proxy-id: " . channelmanagement_framework_utilities :: get_manager_id_for_property_uid ( $componetArgs->property_uid ) )
);
if (isset($send_response->data->response) && $send_response->data->response == true ) {
logging::log_message("Unpublished review ", 'JOMRES2JOMRES', 'DEBUG', '');
logging::log_message("Component args ", 'JOMRES2JOMRES', 'DEBUG', serialize($componetArgs));
logging::log_message("Response ", 'JOMRES2JOMRES', 'DEBUG', serialize($send_response));
$this->success = true;
} else {
logging::log_message("Failed to unpublish review ", 'JOMRES2JOMRES', 'ERROR', '');
logging::log_message("Component args ", 'JOMRES2JOMRES', 'ERROR', serialize($componetArgs));
logging::log_message("Response ", 'JOMRES2JOMRES', 'ERROR', serialize($send_response));
$this->success = false;
}
}
}
}
} else {
logging::log_message("Did not get a valid response from parent server", 'JOMRES2JOMRES', 'ERROR' , serialize($response) );
}
} else {
logging::log_message("Property id not set", 'JOMRES2JOMRES', 'INFO' , '' );
}
if (!isset($this->success)) {
$this->success = false;
}
}
}