-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjomres2jomres_changelog_item_process_room_deleted.php
74 lines (61 loc) · 2.9 KB
/
jomres2jomres_changelog_item_process_room_deleted.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
<?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_room_deleted
{
function __construct($componetArgs)
{
$item = unserialize(base64_decode($componetArgs->item));
if ( isset($item->data->property_uid) ) {
$item_type = "rooms";
$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/rooms/'.$item->data->property_uid , [] , true );
jr_import('jomres_call_api');
$jomres_call_api = new jomres_call_api('system');
if ( isset($cross_references[$item->data->room_uid])) {
$send_response = $jomres_call_api->send_request(
"DELETE",
"cmf/property/room/".$componetArgs->property_uid.'/'.$cross_references[$item->data->room_uid]['local_id'],
[],
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 ) {
channelmanagement_framework_utilities::set_cross_references_for_property_uid('jomres2jomres', $componetArgs->property_uid, $item_type, $item->data->room_uid, 0 ); // Although the api endpoint should create a link we still need this cross referencing for room images
logging::log_message("Added room ", '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 add room ", '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("Property id not set", 'JOMRES2JOMRES', 'INFO' , '' );
}
if (!isset($this->success)) {
$this->success = false;
}
}
}