PluginProbe
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager / 0.0.3
Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager v0.0.3
0.0.11 0.0.10 0.0.9 0.0.8 0.0.7 0.0.6 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5
cookiez / modules / cookie / database / cookie-table.php

cookie-table.php in Cookie Consent – GDPR & CCPA Cookie Banner & Consent Manager 0.0.3, at modules/cookie/database/cookie-table.php

129 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Cookiez\Modules\Cookie\Database;
4
5 use Cookiez\Classes\Database\{
6 Database_Constants,
7 Table
8 };
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Class Cookie_Table
16 * Stores cookies from both scans and manual entries
17 */
18 class Cookie_Table extends Table {
19 const DB_VERSION = '1';
20 const DB_VERSION_FLAG_NAME = 'cookiez_cookie_db_version';
21
22 const ID = 'id';
23 const SCAN_ID = 'scan_id';
24 const NAME = 'name';
25 const DOMAIN = 'domain';
26 const DURATION = 'duration';
27 const CATEGORY = 'category';
28 const DESCRIPTION = 'description';
29 const TYPE = 'type';
30 const CREATED_AT = 'created_at';
31 const UPDATED_AT = 'updated_at';
32
33 public static $table_name = 'cookiez_cookies';
34
35 /**
36 * Get table columns definition
37 * @return array
38 */
39 public static function get_columns(): array {
40 return [
41 self::ID => [
42 'type' => Database_Constants::get_col_type( Database_Constants::BIGINT ) . ' UNSIGNED',
43 'flags' => Database_Constants::build_flags_string( [
44 Database_Constants::NOT_NULL,
45 Database_Constants::AUTO_INCREMENT,
46 ] ),
47 'key' => Database_Constants::get_primary_key_string( self::ID ),
48 ],
49 self::SCAN_ID => [
50 'type' => Database_Constants::get_col_type( Database_Constants::BIGINT ) . ' UNSIGNED',
51 'flags' => Database_Constants::build_flags_string( [
52 Database_Constants::NULL,
53 Database_Constants::DEFAULT,
54 'NULL',
55 ] ),
56 ],
57 self::NAME => [
58 'type' => Database_Constants::get_col_type( Database_Constants::VARCHAR, 255 ),
59 'flags' => Database_Constants::build_flags_string( [
60 Database_Constants::NOT_NULL,
61 ] ),
62 ],
63 self::DOMAIN => [
64 'type' => Database_Constants::get_col_type( Database_Constants::VARCHAR, 255 ),
65 'flags' => Database_Constants::build_flags_string( [
66 Database_Constants::NOT_NULL,
67 ] ),
68 ],
69 self::DURATION => [
70 'type' => Database_Constants::get_col_type( Database_Constants::BIGINT ),
71 'flags' => Database_Constants::build_flags_string( [
72 Database_Constants::NULL,
73 Database_Constants::DEFAULT,
74 'NULL', // null === session cookie
75 ] ),
76 ],
77 self::CATEGORY => [
78 'type' => Database_Constants::get_col_type( Database_Constants::VARCHAR, 20 ),
79 'flags' => Database_Constants::build_flags_string( [
80 Database_Constants::NOT_NULL,
81 ] ),
82 ],
83 self::DESCRIPTION => [
84 'type' => Database_Constants::get_col_type( Database_Constants::TEXT ),
85 'flags' => Database_Constants::build_flags_string( [
86 Database_Constants::NULL,
87 ] ),
88 ],
89 self::TYPE => [
90 'type' => Database_Constants::get_col_type( Database_Constants::VARCHAR, 20 ),
91 'flags' => Database_Constants::build_flags_string( [
92 Database_Constants::NOT_NULL,
93 ] ),
94 ],
95 self::CREATED_AT => [
96 'type' => Database_Constants::get_col_type( Database_Constants::DATETIME ),
97 'flags' => Database_Constants::build_flags_string( [
98 Database_Constants::NOT_NULL,
99 Database_Constants::DEFAULT,
100 Database_Constants::CURRENT_TIMESTAMP,
101 ] ),
102 ],
103 self::UPDATED_AT => [
104 'type' => Database_Constants::get_col_type( Database_Constants::DATETIME ),
105 'flags' => Database_Constants::build_flags_string( [
106 Database_Constants::NOT_NULL,
107 Database_Constants::DEFAULT,
108 Database_Constants::CURRENT_TIMESTAMP,
109 Database_Constants::ON_UPDATE,
110 Database_Constants::CURRENT_TIMESTAMP,
111 ] ),
112 ],
113 ];
114 }
115
116 /**
117 * Get additional keys for the table
118 * @return array
119 */
120 protected static function get_extra_keys(): array {
121 return [
122 Database_Constants::UNIQUE . ' ' . Database_Constants::KEY . ' name_domain (' . self::NAME . ', ' . self::DOMAIN . ')',
123 Database_Constants::build_key_string( Database_Constants::KEY, self::SCAN_ID ),
124 Database_Constants::build_key_string( Database_Constants::KEY, self::CATEGORY ),
125 Database_Constants::build_key_string( Database_Constants::KEY, self::TYPE ),
126 ];
127 }
128 }
129