PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.4.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.4.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Models / IncomingWebhook.php
IncomingWebhook.php
113 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace SureCart\Models;
3
4 use SureCart\Models\DatabaseModel;
5 use SureCart\Support\TimeDate;
6
7 /**
8 * The integration model.
9 */
10 class IncomingWebhook extends DatabaseModel {
11 /**
12 * The integrations table name.
13 *
14 * @var string
15 */
16 protected $table_name = 'surecart_incoming_webhooks';
17
18 /**
19 * The object name
20 *
21 * @var string
22 */
23 protected $object_name = 'incoming_webhook';
24
25 /**
26 * Fillable items.
27 *
28 * @var array
29 */
30 protected $fillable = array( 'id', 'webhook_id', 'processed_at', 'data', 'source', 'created_at', 'updated_at', 'deleted_at' );
31
32 /**
33 * Force `data` to be an object.
34 *
35 * @param array|object $value The value to set.
36 *
37 * @return void
38 */
39 public function setDataAttribute( $value ) {
40 $this->attributes['data'] = json_decode( wp_json_encode( $value ) );
41 }
42
43 /**
44 * Has this been processed?
45 *
46 * @return boolean
47 */
48 protected function getProcessedAttribute() {
49 return ! empty( $this->attributes['processed_at'] );
50 }
51
52 /**
53 * Serialize the data when setting it.
54 *
55 * @param mixed $value The value to set.
56 */
57 protected function setProcessedAttribute( $value ) {
58 $this->attributes['processed_at'] = ! empty( $value ) ? current_time( 'mysql' ) : null;
59 $this->attributes['processed'] = ! empty( $value );
60 }
61
62 /**
63 * Delete expired incoming webhooks.
64 *
65 * @param integer $time_ago The number of days ago to delete.
66 *
67 * @return integer The number of rows deleted.
68 */
69 protected function deleteExpired( $time_ago = '30 days' ) {
70 global $wpdb;
71 $date = new \DateTime();
72 $table_name = $wpdb->prefix . 'surecart_incoming_webhooks';
73 $formatted_date = $date->modify( '-' . $time_ago )->format( 'Y-m-d H:i:s' );
74 return $wpdb->query( $wpdb->prepare( "DELETE FROM $table_name WHERE created_at < %s", $formatted_date ) );
75 }
76
77 /**
78 * Get the created at date.
79 *
80 * @return string
81 */
82 public function getCreatedAtDateAttribute() {
83 return TimeDate::formatDate( strtotime( $this->created_at ) );
84 }
85
86 /**
87 * Get the created at date time.
88 *
89 * @return string
90 */
91 public function getCreatedAtDateTimeAttribute() {
92 return TimeDate::formatDateAndTime( strtotime( $this->created_at ) );
93 }
94
95 /**
96 * Get the updated at date.
97 *
98 * @return string
99 */
100 public function getUpdatedAtDateAttribute() {
101 return TimeDate::formatDate( strtotime( $this->updated_at ) );
102 }
103
104 /**
105 * Get the updated at date time.
106 *
107 * @return string
108 */
109 public function getUpdatedAtDateTimeAttribute() {
110 return TimeDate::formatDateAndTime( strtotime( $this->updated_at ) );
111 }
112 }
113