PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.1
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.1
3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / vendor / woocommerce / action-scheduler / classes / abstracts / ActionScheduler_Abstract_Schema.php
jetformbuilder / vendor / woocommerce / action-scheduler / classes / abstracts Last commit date
ActionScheduler.php 1 month ago ActionScheduler_Abstract_ListTable.php 1 year ago ActionScheduler_Abstract_QueueRunner.php 1 month ago ActionScheduler_Abstract_RecurringSchedule.php 1 year ago ActionScheduler_Abstract_Schedule.php 1 year ago ActionScheduler_Abstract_Schema.php 1 year ago ActionScheduler_Lock.php 1 year ago ActionScheduler_Logger.php 1 year ago ActionScheduler_Store.php 1 year ago ActionScheduler_TimezoneHelper.php 1 year ago ActionScheduler_WPCLI_Command.php 1 year ago
ActionScheduler_Abstract_Schema.php
188 lines
1 <?php
2
3
4 /**
5 * Class ActionScheduler_Abstract_Schema
6 *
7 * @package Action_Scheduler
8 *
9 * @codeCoverageIgnore
10 *
11 * Utility class for creating/updating custom tables
12 */
13 abstract class ActionScheduler_Abstract_Schema {
14
15 /**
16 * Increment this value in derived class to trigger a schema update.
17 *
18 * @var int
19 */
20 protected $schema_version = 1;
21
22 /**
23 * Schema version stored in database.
24 *
25 * @var string
26 */
27 protected $db_version;
28
29 /**
30 * Names of tables that will be registered by this class.
31 *
32 * @var array
33 */
34 protected $tables = array();
35
36 /**
37 * Can optionally be used by concrete classes to carry out additional initialization work
38 * as needed.
39 */
40 public function init() {}
41
42 /**
43 * Register tables with WordPress, and create them if needed.
44 *
45 * @param bool $force_update Optional. Default false. Use true to always run the schema update.
46 *
47 * @return void
48 */
49 public function register_tables( $force_update = false ) {
50 global $wpdb;
51
52 // make WP aware of our tables.
53 foreach ( $this->tables as $table ) {
54 $wpdb->tables[] = $table;
55 $name = $this->get_full_table_name( $table );
56 $wpdb->$table = $name;
57 }
58
59 // create the tables.
60 if ( $this->schema_update_required() || $force_update ) {
61 foreach ( $this->tables as $table ) {
62 /**
63 * Allow custom processing before updating a table schema.
64 *
65 * @param string $table Name of table being updated.
66 * @param string $db_version Existing version of the table being updated.
67 */
68 do_action( 'action_scheduler_before_schema_update', $table, $this->db_version );
69 $this->update_table( $table );
70 }
71 $this->mark_schema_update_complete();
72 }
73 }
74
75 /**
76 * Get table definition.
77 *
78 * @param string $table The name of the table.
79 *
80 * @return string The CREATE TABLE statement, suitable for passing to dbDelta
81 */
82 abstract protected function get_table_definition( $table );
83
84 /**
85 * Determine if the database schema is out of date
86 * by comparing the integer found in $this->schema_version
87 * with the option set in the WordPress options table
88 *
89 * @return bool
90 */
91 private function schema_update_required() {
92 $option_name = 'schema-' . static::class;
93 $this->db_version = get_option( $option_name, 0 );
94
95 // Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema.
96 if ( 0 === $this->db_version ) {
97
98 $plugin_option_name = 'schema-';
99
100 switch ( static::class ) {
101 case 'ActionScheduler_StoreSchema':
102 $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Store_Table_Maker';
103 break;
104 case 'ActionScheduler_LoggerSchema':
105 $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Logger_Table_Maker';
106 break;
107 }
108
109 $this->db_version = get_option( $plugin_option_name, 0 );
110
111 delete_option( $plugin_option_name );
112 }
113
114 return version_compare( $this->db_version, $this->schema_version, '<' );
115 }
116
117 /**
118 * Update the option in WordPress to indicate that
119 * our schema is now up to date
120 *
121 * @return void
122 */
123 private function mark_schema_update_complete() {
124 $option_name = 'schema-' . static::class;
125
126 // work around race conditions and ensure that our option updates.
127 $value_to_save = (string) $this->schema_version . '.0.' . time();
128
129 update_option( $option_name, $value_to_save );
130 }
131
132 /**
133 * Update the schema for the given table
134 *
135 * @param string $table The name of the table to update.
136 *
137 * @return void
138 */
139 private function update_table( $table ) {
140 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
141 $definition = $this->get_table_definition( $table );
142 if ( $definition ) {
143 $updated = dbDelta( $definition );
144 foreach ( $updated as $updated_table => $update_description ) {
145 if ( strpos( $update_description, 'Created table' ) === 0 ) {
146 do_action( 'action_scheduler/created_table', $updated_table, $table ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
147 }
148 }
149 }
150 }
151
152 /**
153 * Get full table name.
154 *
155 * @param string $table Table name.
156 *
157 * @return string The full name of the table, including the
158 * table prefix for the current blog
159 */
160 protected function get_full_table_name( $table ) {
161 return $GLOBALS['wpdb']->prefix . $table;
162 }
163
164 /**
165 * Confirms that all of the tables registered by this schema class have been created.
166 *
167 * @return bool
168 */
169 public function tables_exist() {
170 global $wpdb;
171
172 $tables_exist = true;
173
174 foreach ( $this->tables as $table_name ) {
175 $table_name = $wpdb->prefix . $table_name;
176 $pattern = str_replace( '_', '\\_', $table_name );
177 $existing_table = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $pattern ) );
178
179 if ( $existing_table !== $table_name ) {
180 $tables_exist = false;
181 break;
182 }
183 }
184
185 return $tables_exist;
186 }
187 }
188