1 | <?php namespace EmailLog\Core\DB; |
||
13 | class TableManager { |
||
14 | |||
15 | /* Database table name */ |
||
16 | const LOG_TABLE_NAME = 'email_log'; |
||
17 | |||
18 | /* Database option name */ |
||
19 | const DB_OPTION_NAME = 'email-log-db'; |
||
20 | |||
21 | /* Database version */ |
||
22 | const DB_VERSION = '0.1'; |
||
23 | |||
24 | /** |
||
25 | * Setup hooks. |
||
26 | */ |
||
27 | public function load() { |
||
34 | |||
35 | /** |
||
36 | * On plugin activation, create table if needed. |
||
37 | */ |
||
38 | public function on_activate( $network_wide ) { |
||
53 | |||
54 | /** |
||
55 | * Create email log table when a new blog is created. |
||
56 | */ |
||
57 | public function on_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) { |
||
64 | |||
65 | /** |
||
66 | * Add email log table to the list of tables deleted when a blog is deleted. |
||
67 | * |
||
68 | * @param array $tables List of tables to be deleted. |
||
69 | * |
||
70 | * @return string[] $tables Modified list of tables to be deleted. |
||
71 | */ |
||
72 | 2 | public function on_delete_blog( $tables ) { |
|
77 | |||
78 | /** |
||
79 | * Get email log table name. |
||
80 | * |
||
81 | * @return string Email Log Table name. |
||
82 | */ |
||
83 | 4 | public function get_log_table_name() { |
|
88 | |||
89 | /** |
||
90 | * Insert log data into DB. |
||
91 | * |
||
92 | * @param array $data Data to be inserted. |
||
93 | */ |
||
94 | public function insert_log( $data ) { |
||
100 | |||
101 | /** |
||
102 | * Delete log entires by ids. |
||
103 | * |
||
104 | * @param string $ids Comma seperated list of log ids. |
||
105 | * |
||
106 | * @return false|int Number of log entries that got deleted. False on failure. |
||
107 | */ |
||
108 | public function delete_logs_by_id( $ids ) { |
||
119 | |||
120 | /** |
||
121 | * Delete all log entries. |
||
122 | * |
||
123 | * @return false|int Number of log entries that got deleted. False on failure. |
||
124 | */ |
||
125 | public function delete_all_logs() { |
||
132 | |||
133 | /** |
||
134 | * Get message by log id. |
||
135 | * |
||
136 | * @param int $id Id of the log whose message is needed. |
||
137 | * |
||
138 | * @return null|string Message of the log with $id. |
||
139 | */ |
||
140 | public function get_log_message( $id ) { |
||
148 | |||
149 | /** |
||
150 | * Fetch log items. |
||
151 | * |
||
152 | * @param array $request Request object. |
||
153 | * @param int $per_page Entries per page. |
||
154 | * @param int $current_page_no Current page no. |
||
155 | * |
||
156 | * @return array Log entries and total items count. |
||
157 | */ |
||
158 | public function fetch_log_items( $request, $per_page, $current_page_no ) { |
||
195 | |||
196 | /** |
||
197 | * Create email log table. |
||
198 | * |
||
199 | * @access private |
||
200 | * |
||
201 | * @global object $wpdb |
||
202 | */ |
||
203 | private function create_table() { |
||
228 | |||
229 | /** |
||
230 | * Fetch log item by ID. |
||
231 | * |
||
232 | * @param int $id ID of the log item to be retrieved. |
||
233 | * @return array Log item. |
||
234 | */ |
||
235 | public function fetch_log_item_by_id( $id ) { |
||
242 | |||
243 | /** |
||
244 | * Deletes Email Logs older than the specified interval. |
||
245 | * |
||
246 | * @param $interval_in_days |
||
247 | * @return int |
||
248 | */ |
||
249 | public function delete_logs_older_than( $interval_in_days ) { |
||
257 | } |
||
258 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.