PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / trunk
GiveWP – Donation Plugin and Fundraising Platform vtrunk
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 21 hours ago api 3 years ago database 5 months ago deprecated 1 month ago donors 5 months ago emails 9 months ago forms 21 hours ago frontend 6 years ago gateways 9 months ago libraries 9 months ago payments 2 months ago actions.php 9 months ago ajax-functions.php 2 days ago class-give-async-process.php 1 year ago class-give-background-updater.php 9 months ago class-give-cache-setting.php 1 year ago class-give-cache.php 9 months ago class-give-cli-commands.php 1 year ago class-give-comment.php 9 months ago class-give-cron.php 9 months ago class-give-donate-form.php 1 year ago class-give-donor.php 2 years ago class-give-email-access.php 5 years ago class-give-license-handler.php 1 month ago class-give-logging.php 9 months ago class-give-readme-parser.php 4 years ago class-give-roles.php 5 months ago class-give-scripts.php 2 weeks ago class-give-session.php 9 months 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 4 years ago class-notices.php 9 months ago country-functions.php 7 months ago currencies-list.php 7 months ago currency-functions.php 3 years ago error-tracking.php 6 years ago filters.php 9 months ago formatting.php 9 months ago install.php 9 months ago login-register.php 2 years ago misc-functions.php 1 month ago plugin-compatibility.php 6 years ago post-types.php 1 year ago price-functions.php 6 years ago process-donation.php 1 year ago setting-functions.php 6 years ago shortcodes.php 1 year ago template-functions.php 1 year ago user-functions.php 3 years ago
class-give-logging.php
316 lines
1 <?php
2
3 use Give\Log\Log;
4 use Give\Log\LogFactory;
5 use Give\Log\LogRepository;
6 use Give\Log\ValueObjects\LogType;
7 use Give\Log\Helpers\LogTypeHelper;
8 /**
9 * Class for logging events and errors
10 *
11 * @package Give
12 * @subpackage Classes/Give_Logging
13 * @copyright Copyright (c) 2016, GiveWP
14 * @license https://opensource.org/licenses/gpl-license GNU Public License
15 * @since 1.0
16 */
17
18 // Exit if accessed directly.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Give_Logging Class
25 *
26 * A general use class for logging events and errors.
27 *
28 * @deprecated 2.10.0
29 * @use Log
30 * @see Log
31 *
32 * @since 1.0
33 */
34 class Give_Logging {
35 /**
36 * @var LogRepository
37 */
38 private $logRepository;
39
40 /**
41 * @var LogTypeHelper
42 */
43 private $logTypeHelper;
44
45 /**
46 * Class Constructor
47 *
48 * Set up the Give Logging Class.
49 *
50 * @since 1.0
51 * @access public
52 */
53 public function __construct() {
54 $this->logRepository = give( LogRepository::class );
55 $this->logTypeHelper = give( LogTypeHelper::class );
56 }
57
58 /**
59 * Create new log entry
60 *
61 * This is just a simple and fast way to log something. Use $this->insert_log()
62 * if you need to store custom meta data.
63 *
64 * @deprecated 2.10.0
65 * @use Log::LOG_TYPE( $message );
66 * @see Log
67 *
68 * @since 1.0
69 * @access public
70 *
71 * @param string $title Log entry title. Default is empty.
72 * @param string $message Log entry message. Default is empty.
73 * @param int $parent Log entry parent. Default is 0.
74 * @param string $type Log type. Default is empty string.
75 *
76 * @return int Log ID.
77 */
78 public function add( $title = '', $message = '', $parent = 0, $type = '' ) {
79 $log_data = [
80 'post_title' => $title,
81 'post_content' => $message,
82 'post_parent' => $parent,
83 'log_type' => $type,
84 ];
85
86 return $this->insert_log( $log_data );
87 }
88
89 /**
90 * Helper method used to map the fields from the old system to the new system
91 *
92 * @since 2.10.0
93 *
94 * @param array $logData
95 * @param array $logMeta
96 *
97 * @return array
98 */
99 private function getLogData( $logData, $logMeta ) {
100 $oldType = isset( $logData['log_type'] )
101 ? $logData['log_type']
102 : LogType::getDefault();
103
104 $data = $this->logTypeHelper->getDataFromType( $oldType );
105
106 $content = esc_html__( 'Something went wrong', 'give' );
107
108 if ( isset( $logData['log_content'] ) ) {
109 $content = $logData['log_content'];
110 } else {
111 if ( isset( $logData['post_title'] ) ) {
112 $content = $logData['post_title'];
113 }
114 }
115
116 return [
117 'type' => $data['type'],
118 'category' => $data['category'],
119 'message' => $content,
120 'context' => array_merge( $logData, $logMeta ),
121 ];
122 }
123
124 /**
125 * Get Logs
126 *
127 * Retrieves log items for a particular object ID.
128 *
129 * @deprecated 2.10.0
130 * @use LogRepository::getLogs();
131 * @see LogRepository
132 *
133 * @since 1.0
134 * @access public
135 *
136 * @param int $object_id Log object ID. Default is 0.
137 * @param string $type Log type. Default is empty string.
138 * @param int $paged Page number Default is null.
139 *
140 * @return array An array of the connected logs.
141 */
142 public function get_logs( $object_id = 0, $type = '', $paged = null ) {
143 if ( $object_id ) {
144 $log = $this->logRepository->getLog( $object_id );
145
146 return [
147 (object) [
148 'ID' => $log->getId(),
149 'log_date' => $log->getDate(),
150 'log_date_gmt' => '',
151 'log_content' => $log->getMessage(),
152 'log_title' => $log->getCategory() . ' - ' . $log->getSource(),
153 'log_type' => $log->getType(),
154 ],
155 ];
156 }
157
158 if ( ! empty( $type ) ) {
159 $data = [];
160 $logs = $this->logRepository->getLogsByType( $type );
161
162 foreach ( $logs as $log ) {
163 $data[] = (object) [
164 'ID' => $log->getId(),
165 'log_date' => $log->getDate(),
166 'log_date_gmt' => '',
167 'log_content' => $log->getMessage(),
168 'log_title' => $log->getCategory() . ' - ' . $log->getSource(),
169 'log_type' => $log->getType(),
170 ];
171 }
172
173 return $data;
174 }
175
176 return [];
177 }
178
179 /**
180 * Stores a log entry
181 *
182 * @deprecated 2.10.0
183 * @use Log::LOG_TYPE( $message );
184 * @see Log
185 *
186 * @since 1.0
187 * @access public
188 *
189 * @param array $log_data Log entry data.
190 * @param array $log_meta Log entry meta.
191 *
192 * @return int The ID of the newly created log item.
193 */
194 //phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
195 public function insert_log( $log_data = [], $log_meta = [] ) {
196 // Extract data from parameters
197 $data = $this->getLogData( $log_data, $log_meta );
198
199 $backtrace = debug_backtrace();
200
201 // Add more context
202 if (
203 isset( $backtrace[1] ) &&
204 ! array_diff( [ 'file', 'line', 'function', 'class' ], array_keys( $backtrace[1] ) )
205 ) {
206 $data['context']['file'] = $backtrace[1]['file'];
207 $data['context']['line'] = $backtrace[1]['line'];
208 $data['context']['function'] = $backtrace[1]['function'];
209 $data['context']['class'] = $backtrace[1]['class'];
210 }
211
212 try {
213 $log = LogFactory::makeFromArray( $data );
214 $log->save();
215
216 return $log->getId();
217 } catch ( Exception $exception ) {
218 error_log( $exception->getMessage() );
219 }
220 }
221
222 /**
223 * Update and existing log item
224 *
225 * @deprecated 2.10.0
226 * @use Log::LOG_TYPE( $message );
227 * @see Log
228 *
229 * @since 1.0
230 * @access public
231 *
232 * @param array $log_data Log entry data.
233 * @param array $log_meta Log entry meta.
234 *
235 * @return bool|null True if successful, false otherwise.
236 */
237 public function update_log( $log_data = [], $log_meta = [] ) {
238 return $this->insert_log( $log_data, $log_meta );
239 }
240
241 /**
242 * Retrieve all connected logs
243 *
244 * Used for retrieving logs related to particular items, such as a specific donation.
245 * For new table params check: Give_DB_Logs::get_column_defaults and Give_DB_Logs::get_sql#L262
246 *
247 * @deprecated 2.10.0
248 *
249 * @since 1.0
250 * @since 2.0 Added new table logic.
251 * @access public
252 *
253 * @param array $args Query arguments.
254 *
255 * @return array|false Array if logs were found, false otherwise.
256 */
257 public function get_connected_logs( $args = [] ) {
258 return false;
259 }
260
261 /**
262 * Retrieve Log Count
263 *
264 * Retrieves number of log entries connected to particular object ID.
265 *
266 * @deprecated 2.10.0
267 * @use LogRepository::getTotalCount()
268 * @see LogRepository
269 *
270 * @since 1.0
271 * @access public
272 *
273 * @param int $object_id Log object ID. Default is 0.
274 * @param string $type Log type. Default is empty string.
275 * @param array $meta_query Log meta query. Default is null.
276 * @param array $date_query Log data query. Default is null.
277 *
278 * @return int Log count.
279 */
280 public function get_log_count( $object_id = 0, $type = '', $meta_query = null, $date_query = null ) {
281 if ( $object_id ) {
282 return 0;
283 }
284
285 if ( ! empty( $type ) ) {
286 $logs = $this->logRepository->getLogsByType( $type );
287 return count( $logs );
288 }
289
290 return $this->logRepository->getTotalCount();
291 }
292
293 /**
294 * Delete Logs
295 *
296 * Remove log entries connected to particular object ID.
297 *
298 * @deprecated 2.10.0
299 * @use LogRepository::deleteLogs()
300 * @see LogRepository
301 *
302 * @since 1.0
303 * @access public
304 *
305 * @param int $object_id Log object ID. Default is 0.
306 * @param string $type Log type. Default is empty string.
307 * @param array $meta_query Log meta query. Default is null.
308 *
309 * @return void
310 */
311 public function delete_logs( $object_id = 0, $type = '', $meta_query = null ) {
312 $this->logRepository->deleteLogs();
313 }
314
315 }
316