PluginProbe
Stream – Activity Log & Audit Trail / 3.4.2
Stream – Activity Log & Audit Trail v3.4.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-record.php +7 -165 4.3.03.4.2 View file →
@@ -1,120 +1,23 @@
1 1 <?php
2 -/**
3 - * Manages the state of a single record
4 - *
5 - * @package WP_Stream
6 - */
7 -
8 2 namespace WP_Stream;
9 3
10 -/**
11 - * Class - Record
12 - */
13 4 class Record {
14 - /**
15 - * Record ID
16 - *
17 - * @var int
18 - */
19 5 public $ID;
20 -
21 - /**
22 - * Date record created
23 - *
24 - * @var string
25 - */
26 6 public $created;
27 -
28 - /**
29 - * Site ID of the site where the record was created
30 - *
31 - * @var int
32 - */
33 7 public $site_id;
34 -
35 - /**
36 - * Blog ID of the site where the record was created
37 - *
38 - * @var int
39 - */
40 8 public $blog_id;
41 -
42 - /**
43 - * Record Object ID
44 - *
45 - * @var int
46 - */
47 9 public $object_id;
48 -
49 - /**
50 - * User ID of the record creator
51 - *
52 - * @var int
53 - */
54 10 public $user_id;
55 -
56 - /**
57 - * User role of the record creator
58 - *
59 - * @var string
60 - */
61 11 public $user_role;
62 -
63 - /**
64 - * Record user meta data.
65 - *
66 - * @var string
67 - */
68 12 public $user_meta;
69 -
70 - /**
71 - * Record summary
72 - *
73 - * @var string
74 - */
75 13 public $summary;
76 -
77 - /**
78 - * Record connector
79 - *
80 - * @var string
81 - */
82 14 public $connector;
83 -
84 - /**
85 - * Context record was made in.
86 - *
87 - * @var string
88 - */
89 15 public $context;
90 -
91 - /**
92 - * Record action
93 - *
94 - * @var string
95 - */
96 16 public $action;
97 -
98 - /**
99 - * IP of event requestee
100 - *
101 - * @var string
102 - */
103 17 public $ip;
104 -
105 - /**
106 - * Record meta data
107 - *
108 - * @var array
109 - */
110 18 public $meta;
111 19
112 - /**
113 - * Class constructor
114 - *
115 - * @param object $item Record data object.
116 - */
117 20 public function __construct( $item ) {
118 21 $this->ID = isset( $item->ID ) ? $item->ID : null;
119 22 $this->created = isset( $item->created ) ? $item->created : null;
120 23 $this->site_id = isset( $item->site_id ) ? $item->site_id : null;
@@ -134,58 +37,8 @@
134 37 unset( $this->meta['user_meta'] );
135 38 }
136 39 }
137 40
138 - /**
139 - * Fetch a single record row by ID, including its metadata.
140 - *
141 - * Stream's Query class doesn't expose a single-ID filter (record__in is
142 - * broken for one-element arrays due to array_shift() in Query::query()),
143 - * so query the table directly. Pass $blog_id to scope the lookup to a
144 - * specific blog on multisite — callers running in REST/non-network-admin
145 - * contexts should pass get_current_blog_id() to prevent cross-site reads.
146 - *
147 - * @param int $id Record ID.
148 - * @param int|null $blog_id Optional blog ID to constrain the lookup to.
149 - *
150 - * @return array|null Associative row with merged 'meta' key, or null when
151 - * no matching record exists.
152 - */
153 - public static function get_by_id( $id, $blog_id = null ) {
154 - global $wpdb;
155 -
156 - $id = (int) $id;
157 - if ( $id <= 0 ) {
158 - return null;
159 - }
160 -
161 - $where = '';
162 - $prepared = array( $id );
163 - if ( null !== $blog_id ) {
164 - $where = ' AND blog_id = %d';
165 - $prepared[] = (int) $blog_id;
166 - }
167 -
168 - // $wpdb->stream and {$where} are constructed from string literals (no
169 - // user input), and $prepared holds only integer IDs.
170 - $sql = "SELECT * FROM {$wpdb->stream} WHERE ID = %d{$where}";
171 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared
172 - $row = $wpdb->get_row( $wpdb->prepare( $sql, $prepared ), ARRAY_A );
173 -
174 - if ( empty( $row ) ) {
175 - return null;
176 - }
177 -
178 - $row['meta'] = (array) get_metadata( 'record', $row['ID'] );
179 -
180 - return $row;
181 - }
182 -
183 - /**
184 - * Save record.
185 - *
186 - * @return int|WP_Error
187 - */
188 41 public function save() {
189 42 if ( ! $this->validate() ) {
190 43 return new \WP_Error( 'validation-error', esc_html__( 'Could not validate record data.', 'stream' ) );
191 44 }
@@ -192,13 +45,8 @@
192 45
193 46 return wp_stream_get_instance()->db->insert( (array) $this );
194 47 }
195 48
196 - /**
197 - * Populate "$this" object with provided data.
198 - *
199 - * @param array $raw Data to be used to populate $this object.
200 - */
201 49 public function populate( array $raw ) {
202 50 $keys = get_class_vars( $this );
203 51 $data = array_intersect_key( $raw, $keys );
204 52 foreach ( $data as $key => $val ) {
@@ -205,15 +53,8 @@
205 53 $this->{$key} = $val;
206 54 }
207 55 }
208 56
209 - /**
210 - * Validates this record
211 - *
212 - * @todo Add actual validation measures.
213 - *
214 - * @return bool
215 - */
216 57 public function validate() {
217 58 return true;
218 59 }
219 60
@@ -219,10 +60,10 @@
219 60
220 61 /**
221 62 * Query record meta
222 63 *
223 - * @param string $meta_key Meta key (optional).
224 - * @param bool $single Return only first found (optional).
64 + * @param string $meta_key (optional)
65 + * @param bool $single (optional)
225 66 *
226 67 * @return array
227 68 */
228 69 public function get_meta( $meta_key = '', $single = false ) {
@@ -231,11 +72,11 @@
231 72
232 73 /**
233 74 * Update record meta
234 75 *
235 - * @param string $meta_key Meta key.
236 - * @param mixed $meta_value New meta value.
237 - * @param mixed $prev_value Old meta value (optional).
76 + * @param string $meta_key
77 + * @param mixed $meta_value
78 + * @param mixed $prev_value (optional)
238 79 *
239 80 * @return bool
240 81 */
241 82 public function update_meta( $meta_key, $meta_value, $prev_value = '' ) {
@@ -244,9 +85,10 @@
244 85
245 86 /**
246 87 * Determine the title of an object that a record is for.
247 88 *
248 - * @return mixed The title of the object as a string, otherwise false
89 + * @param object Record object
90 + * @return mixed The title of the object as a string, otherwise false
249 91 */
250 92 public function get_object_title() {
251 93 if ( ! isset( $this->object_id ) || empty( $this->object_id ) ) {
252 94 return false;