← All changes
|
vendor/woocommerce/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php
+21
-11
1.3.0
→
trunk
View file →
| @@ -12,19 +12,25 @@ | ||
| 12 | 12 | */ |
| 13 | 13 | abstract class ActionScheduler_Abstract_Schema { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * @var int Increment this value in derived class to trigger a schema update. | |
| 16 | + * Increment this value in derived class to trigger a schema update. | |
| 17 | + * | |
| 18 | + * @var int | |
| 17 | 19 | */ |
| 18 | 20 | protected $schema_version = 1; |
| 19 | 21 | |
| 20 | 22 | /** |
| 21 | - * @var string Schema version stored in database. | |
| 23 | + * Schema version stored in database. | |
| 24 | + * | |
| 25 | + * @var string | |
| 22 | 26 | */ |
| 23 | 27 | protected $db_version; |
| 24 | 28 | |
| 25 | 29 | /** |
| 26 | - * @var array Names of tables that will be registered by this class. | |
| 30 | + * Names of tables that will be registered by this class. | |
| 31 | + * | |
| 32 | + * @var array | |
| 27 | 33 | */ |
| 28 | 34 | protected $tables = array(); |
| 29 | 35 | |
| 30 | 36 | /** |
| @@ -42,9 +48,9 @@ | ||
| 42 | 48 | */ |
| 43 | 49 | public function register_tables( $force_update = false ) { |
| 44 | 50 | global $wpdb; |
| 45 | 51 | |
| 46 | - // make WP aware of our tables | |
| 52 | + // make WP aware of our tables. | |
| 47 | 53 | foreach ( $this->tables as $table ) { |
| 48 | 54 | $wpdb->tables[] = $table; |
| 49 | 55 | $name = $this->get_full_table_name( $table ); |
| 50 | 56 | $wpdb->$table = $name; |
| @@ -49,9 +55,9 @@ | ||
| 49 | 55 | $name = $this->get_full_table_name( $table ); |
| 50 | 56 | $wpdb->$table = $name; |
| 51 | 57 | } |
| 52 | 58 | |
| 53 | - // create the tables | |
| 59 | + // create the tables. | |
| 54 | 60 | if ( $this->schema_update_required() || $force_update ) { |
| 55 | 61 | foreach ( $this->tables as $table ) { |
| 56 | 62 | /** |
| 57 | 63 | * Allow custom processing before updating a table schema. |
| @@ -66,10 +72,12 @@ | ||
| 66 | 72 | } |
| 67 | 73 | } |
| 68 | 74 | |
| 69 | 75 | /** |
| 70 | - * @param string $table The name of the table | |
| 76 | + * Get table definition. | |
| 71 | 77 | * |
| 78 | + * @param string $table The name of the table. | |
| 79 | + * | |
| 72 | 80 | * @return string The CREATE TABLE statement, suitable for passing to dbDelta |
| 73 | 81 | */ |
| 74 | 82 | abstract protected function get_table_definition( $table ); |
| 75 | 83 | |
| @@ -83,9 +91,9 @@ | ||
| 83 | 91 | private function schema_update_required() { |
| 84 | 92 | $option_name = 'schema-' . static::class; |
| 85 | 93 | $this->db_version = get_option( $option_name, 0 ); |
| 86 | 94 | |
| 87 | - // Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema | |
| 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. | |
| 88 | 96 | if ( 0 === $this->db_version ) { |
| 89 | 97 | |
| 90 | 98 | $plugin_option_name = 'schema-'; |
| 91 | 99 | |
| @@ -114,9 +122,9 @@ | ||
| 114 | 122 | */ |
| 115 | 123 | private function mark_schema_update_complete() { |
| 116 | 124 | $option_name = 'schema-' . static::class; |
| 117 | 125 | |
| 118 | - // work around race conditions and ensure that our option updates | |
| 126 | + // work around race conditions and ensure that our option updates. | |
| 119 | 127 | $value_to_save = (string) $this->schema_version . '.0.' . time(); |
| 120 | 128 | |
| 121 | 129 | update_option( $option_name, $value_to_save ); |
| 122 | 130 | } |
| @@ -123,9 +131,9 @@ | ||
| 123 | 131 | |
| 124 | 132 | /** |
| 125 | 133 | * Update the schema for the given table |
| 126 | 134 | * |
| 127 | - * @param string $table The name of the table to update | |
| 135 | + * @param string $table The name of the table to update. | |
| 128 | 136 | * |
| 129 | 137 | * @return void |
| 130 | 138 | */ |
| 131 | 139 | private function update_table( $table ) { |
| @@ -134,9 +142,9 @@ | ||
| 134 | 142 | if ( $definition ) { |
| 135 | 143 | $updated = dbDelta( $definition ); |
| 136 | 144 | foreach ( $updated as $updated_table => $update_description ) { |
| 137 | 145 | if ( strpos( $update_description, 'Created table' ) === 0 ) { |
| 138 | - do_action( 'action_scheduler/created_table', $updated_table, $table ); | |
| 146 | + do_action( 'action_scheduler/created_table', $updated_table, $table ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores | |
| 139 | 147 | } |
| 140 | 148 | } |
| 141 | 149 | } |
| 142 | 150 | } |
| @@ -141,9 +149,11 @@ | ||
| 141 | 149 | } |
| 142 | 150 | } |
| 143 | 151 | |
| 144 | 152 | /** |
| 145 | - * @param string $table | |
| 153 | + * Get full table name. | |
| 154 | + * | |
| 155 | + * @param string $table Table name. | |
| 146 | 156 | * |
| 147 | 157 | * @return string The full name of the table, including the |
| 148 | 158 | * table prefix for the current blog |
| 149 | 159 | */ |