PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.10.1
GiveWP – Donation Plugin and Fundraising Platform v2.10.1
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-give-logging.php
give / includes Last commit date
admin 5 years ago api 5 years ago database 5 years ago deprecated 5 years ago donors 5 years ago emails 6 years ago forms 5 years ago frontend 6 years ago gateways 5 years ago libraries 6 years ago payments 5 years ago actions.php 5 years ago ajax-functions.php 5 years ago class-give-async-process.php 6 years ago class-give-background-updater.php 6 years ago class-give-cache-setting.php 5 years ago class-give-cache.php 6 years ago class-give-cli-commands.php 6 years ago class-give-comment.php 6 years ago class-give-cron.php 6 years ago class-give-donate-form.php 6 years ago class-give-donor.php 5 years ago class-give-email-access.php 5 years ago class-give-license-handler.php 5 years ago class-give-logging.php 5 years ago class-give-readme-parser.php 6 years ago class-give-roles.php 6 years ago class-give-scripts.php 5 years ago class-give-session.php 5 years ago class-give-stats.php 6 years ago class-give-template-loader.php 6 years ago class-give-tooltips.php 6 years ago class-give-translation.php 6 years ago class-notices.php 5 years ago country-functions.php 5 years ago currencies-list.php 6 years ago currency-functions.php 6 years ago error-tracking.php 6 years ago filters.php 5 years ago formatting.php 6 years ago install.php 5 years ago login-register.php 6 years ago misc-functions.php 5 years ago plugin-compatibility.php 6 years ago post-types.php 5 years ago price-functions.php 6 years ago process-donation.php 5 years ago setting-functions.php 6 years ago shortcodes.php 6 years ago template-functions.php 6 years ago user-functions.php 5 years ago
class-give-logging.php
317 lines
1 <?php
2
3 use Give\Log\LogFactory;
4 use Give\Log\LogRepository;
5 use Give\Log\ValueObjects\LogType;
6 use Give\Log\Helpers\LogTypeHelper;
7 /**
8 * Class for logging events and errors
9 *
10 * @package Give
11 * @subpackage Classes/Give_Logging
12 * @copyright Copyright (c) 2016, GiveWP
13 * @license https://opensource.org/licenses/gpl-license GNU Public License
14 * @since 1.0
15 */
16
17 // Exit if accessed directly.
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 /**
23 * Give_Logging Class
24 *
25 * A general use class for logging events and errors.
26 *
27 * @deprecated 2.10.0
28 * @use Log
29 * @see Log
30 *
31 * @since 1.0
32 */
33 class Give_Logging {
34 /**
35 * @var LogRepository
36 */
37 private $logRepository;
38
39 /**
40 * @var LogTypeHelper
41 */
42 private $logTypeHelper;
43
44 /**
45 * Class Constructor
46 *
47 * Set up the Give Logging Class.
48 *
49 * @since 1.0
50 * @access public
51 */
52 public function __construct() {
53 $this->logRepository = give( LogRepository::class );
54 $this->logTypeHelper = give( LogTypeHelper::class );
55 }
56
57 /**
58 * Create new log entry
59 *
60 * This is just a simple and fast way to log something. Use $this->insert_log()
61 * if you need to store custom meta data.
62 *
63 * @deprecated 2.10.0
64 * @use Log::LOG_TYPE( $message );
65 * @see Log
66 *
67 * @since 1.0
68 * @access public
69 *
70 * @param string $title Log entry title. Default is empty.
71 * @param string $message Log entry message. Default is empty.
72 * @param int $parent Log entry parent. Default is 0.
73 * @param string $type Log type. Default is empty string.
74 *
75 * @return int Log ID.
76 */
77 public function add( $title = '', $message = '', $parent = 0, $type = '' ) {
78 $log_data = [
79 'post_title' => $title,
80 'post_content' => $message,
81 'post_parent' => $parent,
82 'log_type' => $type,
83 ];
84
85 return $this->insert_log( $log_data );
86 }
87
88 /**
89 * Helper method used to map the fields from the old system to the new system
90 *
91 * @since 2.10.0
92 *
93 * @param array $logData
94 * @param array $logMeta
95 *
96 * @return array
97 */
98 private function getLogData( $logData, $logMeta ) {
99 $oldType = isset( $logData['log_type'] )
100 ? $logData['log_type']
101 : LogType::getDefault();
102
103 $data = $this->logTypeHelper->getDataFromType( $oldType );
104
105 $content = esc_html__( 'Something went wrong', 'give' );
106
107 if ( isset( $logData['log_content'] ) ) {
108 $content = $logData['log_content'];
109 } else {
110 if ( isset( $logData['post_title'] ) ) {
111 $content = $logData['post_title'];
112 }
113 }
114
115 return [
116 'type' => $data['type'],
117 'category' => $data['category'],
118 'message' => $content,
119 'context' => array_merge( $logData, $logMeta ),
120 ];
121 }
122
123 /**
124 * Get Logs
125 *
126 * Retrieves log items for a particular object ID.
127 *
128 * @deprecated 2.10.0
129 * @use LogRepository::getLogs();
130 * @see LogRepository
131 *
132 * @since 1.0
133 * @access public
134 *
135 * @param int $object_id Log object ID. Default is 0.
136 * @param string $type Log type. Default is empty string.
137 * @param int $paged Page number Default is null.
138 *
139 * @return array An array of the connected logs.
140 */
141 public function get_logs( $object_id = 0, $type = '', $paged = null ) {
142 if ( $object_id ) {
143 $log = $this->logRepository->getLog( $object_id );
144
145 return [
146 (object) [
147 'ID' => $log->getId(),
148 'log_date' => $log->getDate(),
149 'log_date_gmt' => '',
150 'log_content' => $log->getMessage(),
151 'log_title' => $log->getCategory() . ' - ' . $log->getSource(),
152 'log_type' => $log->getType(),
153 ],
154 ];
155 }
156
157 if ( ! empty( $type ) ) {
158 $data = [];
159 $logs = $this->logRepository->getLogsByType( $type );
160
161 foreach ( $logs as $log ) {
162 $data[] = (object) [
163 'ID' => $log->getId(),
164 'log_date' => $log->getDate(),
165 'log_date_gmt' => '',
166 'log_content' => $log->getMessage(),
167 'log_title' => $log->getCategory() . ' - ' . $log->getSource(),
168 'log_type' => $log->getType(),
169 ];
170 }
171
172 return $data;
173 }
174
175 return [];
176 }
177
178 /**
179 * Stores a log entry
180 *
181 * @deprecated 2.10.0
182 * @use Log::LOG_TYPE( $message );
183 * @see Log
184 *
185 * @since 1.0
186 * @access public
187 *
188 * @param array $log_data Log entry data.
189 * @param array $log_meta Log entry meta.
190 *
191 * @return int The ID of the newly created log item.
192 */
193 public function insert_log( $log_data = [], $log_meta = [] ) {
194 // Extract data from parameters
195 $data = $this->getLogData( $log_data, $log_meta );
196
197 $backtrace = debug_backtrace();
198
199 // Add more context
200 if (
201 isset( $backtrace[1] ) &&
202 ! array_diff( [ 'file', 'line', 'function', 'class' ], array_keys( $backtrace[1] ) )
203 ) {
204 $data['context']['file'] = $backtrace[1]['file'];
205 $data['context']['line'] = $backtrace[1]['line'];
206 $data['context']['function'] = $backtrace[1]['function'];
207 $data['context']['class'] = $backtrace[1]['class'];
208 }
209
210 $log = LogFactory::make(
211 $data['type'],
212 $data['message'],
213 $data['category'],
214 'n/a',
215 $data['context']
216 );
217
218 $log->save();
219
220 return $log->getId();
221 }
222
223 /**
224 * Update and existing log item
225 *
226 * @deprecated 2.10.0
227 * @use Log::LOG_TYPE( $message );
228 * @see Log
229 *
230 * @since 1.0
231 * @access public
232 *
233 * @param array $log_data Log entry data.
234 * @param array $log_meta Log entry meta.
235 *
236 * @return bool|null True if successful, false otherwise.
237 */
238 public function update_log( $log_data = [], $log_meta = [] ) {
239 return $this->insert_log( $log_data, $log_meta );
240 }
241
242 /**
243 * Retrieve all connected logs
244 *
245 * Used for retrieving logs related to particular items, such as a specific donation.
246 * For new table params check: Give_DB_Logs::get_column_defaults and Give_DB_Logs::get_sql#L262
247 *
248 * @deprecated 2.10.0
249 *
250 * @since 1.0
251 * @since 2.0 Added new table logic.
252 * @access public
253 *
254 * @param array $args Query arguments.
255 *
256 * @return array|false Array if logs were found, false otherwise.
257 */
258 public function get_connected_logs( $args = [] ) {
259 return false;
260 }
261
262 /**
263 * Retrieve Log Count
264 *
265 * Retrieves number of log entries connected to particular object ID.
266 *
267 * @deprecated 2.10.0
268 * @use LogRepository::getTotalCount()
269 * @see LogRepository
270 *
271 * @since 1.0
272 * @access public
273 *
274 * @param int $object_id Log object ID. Default is 0.
275 * @param string $type Log type. Default is empty string.
276 * @param array $meta_query Log meta query. Default is null.
277 * @param array $date_query Log data query. Default is null.
278 *
279 * @return int Log count.
280 */
281 public function get_log_count( $object_id = 0, $type = '', $meta_query = null, $date_query = null ) {
282 if ( $object_id ) {
283 return 0;
284 }
285
286 if ( ! empty( $type ) ) {
287 $logs = $this->logRepository->getLogsByType( $type );
288 return count( $logs );
289 }
290
291 return $this->logRepository->getTotalCount();
292 }
293
294 /**
295 * Delete Logs
296 *
297 * Remove log entries connected to particular object ID.
298 *
299 * @deprecated 2.10.0
300 * @use LogRepository::deleteLogs()
301 * @see LogRepository
302 *
303 * @since 1.0
304 * @access public
305 *
306 * @param int $object_id Log object ID. Default is 0.
307 * @param string $type Log type. Default is empty string.
308 * @param array $meta_query Log meta query. Default is null.
309 *
310 * @return void
311 */
312 public function delete_logs( $object_id = 0, $type = '', $meta_query = null ) {
313 $this->logRepository->deleteLogs();
314 }
315
316 }
317