-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclass-network-post-updated.php
81 lines (71 loc) · 1.79 KB
/
class-network-post-updated.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
<?php
/**
* Newspack Network Content Distribution Post Update.
*
* @package Newspack
*/
namespace Newspack_Network\Incoming_Events;
use Newspack_Network\Debugger;
use Newspack_Network\Content_Distribution\Incoming_Post;
/**
* Class to handle the network post update.
*/
class Network_Post_Updated extends Abstract_Incoming_Event {
/**
* Processes the event
*
* @return void
*/
public function post_process_in_hub() {
$this->process_post_updated();
}
/**
* Process event in Node
*
* @return void
*/
public function process_in_node() {
$this->process_post_updated();
}
/**
* Process post updated
*/
protected function process_post_updated() {
$payload = (array) $this->get_data();
Debugger::log( 'Processing network_post_updated ' . wp_json_encode( $payload['sites'] ) );
$error = Incoming_Post::get_payload_error( $payload );
if ( is_wp_error( $error ) ) {
Debugger::log( 'Error processing network_post_updated: ' . $error->get_error_message() );
return;
}
try {
$incoming_post = new Incoming_Post( $payload );
} catch ( \Exception $e ) {
Debugger::log( 'Error processing network_post_updated: ' . $e->getMessage() );
return;
}
$post_id = $incoming_post->insert();
if ( ! is_wp_error( $post_id ) ) {
$elapsed_time = time() - $this->get_timestamp();
$message = sprintf(
'Post %d updated %d seconds after distribution',
$post_id,
$elapsed_time
);
Debugger::log( $message );
if ( method_exists( 'Newspack\Logger', 'newspack_log' ) ) {
$payload_info = $payload;
unset( $payload_info['post_data'] );
\Newspack\Logger::newspack_log(
'newspack_network_post_updated',
$message,
[
'payload_info' => $payload_info,
'elapsed_time' => $elapsed_time,
],
'debug'
);
}
}
}
}