PluginProbe
YayMail – WooCommerce Email Customizer / trunk
YayMail – WooCommerce Email Customizer vtrunk
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / TemplateLibrary / LibraryTemplateSchema.php

LibraryTemplateSchema.php in YayMail – WooCommerce Email Customizer trunk, at src/TemplateLibrary/LibraryTemplateSchema.php

64 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\TemplateLibrary;
4
5 use YayMail\Models\LibraryTemplateModel;
6
7 /**
8 * Ensures the library templates custom table exists (e.g. before migration runs in dev).
9 */
10 class LibraryTemplateSchema {
11
12 /**
13 * Create table via dbDelta if missing.
14 *
15 * @return void
16 */
17 public static function maybe_create_table() {
18 global $wpdb;
19
20 $table_name = LibraryTemplateModel::get_table_name();
21
22 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
23 if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) === $table_name ) {
24 return;
25 }
26
27 self::create_table();
28 }
29
30 /**
31 * Run dbDelta for yaymail_library_templates.
32 *
33 * @return void
34 */
35 public static function create_table() {
36 global $wpdb;
37
38 $table_name = LibraryTemplateModel::get_table_name();
39 $charset_collate = $wpdb->get_charset_collate();
40
41 $sql = "CREATE TABLE {$table_name} (
42 id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
43 public_id char(36) NOT NULL,
44 email_type varchar(64) NOT NULL,
45 name varchar(255) NOT NULL,
46 description text NULL,
47 elements longtext NOT NULL,
48 email_settings text NOT NULL,
49 global_header_settings text NULL,
50 global_footer_settings text NULL,
51 position smallint(5) unsigned NOT NULL DEFAULT 100,
52 created_by bigint(20) unsigned NOT NULL DEFAULT 0,
53 created_at datetime NOT NULL,
54 updated_at datetime NOT NULL,
55 PRIMARY KEY (id),
56 UNIQUE KEY public_id (public_id),
57 KEY idx_email_type (email_type)
58 ) {$charset_collate};";
59
60 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
61 dbDelta( $sql );
62 }
63 }
64