| @@ -150,10 +150,26 @@ | ||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | public static function seedDefaultTaxClass() |
| 153 | 153 | { |
| 154 | - TaxClass::query()->firstOrCreate( | |
| 155 | - ['slug' => 'standard'], | |
| 156 | - ['title' => 'Standard'] | |
| 157 | - ); | |
| 154 | + global $wpdb; | |
| 155 | + | |
| 156 | + if (TaxClass::query()->where('slug', 'standard')->exists()) { | |
| 157 | + return; | |
| 158 | + } | |
| 159 | + | |
| 160 | + $table = static::getTableName(); | |
| 161 | + | |
| 162 | + // INSERT IGNORE so a concurrent migration run that inserted the row | |
| 163 | + // between our exists() check and this insert can't raise a | |
| 164 | + // duplicate-entry error on the unique slug index. | |
| 165 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 166 | + $wpdb->query($wpdb->prepare( | |
| 167 | + "INSERT IGNORE INTO %i (`slug`, `title`, `created_at`, `updated_at`) VALUES (%s, %s, %s, %s)", | |
| 168 | + $table, | |
| 169 | + 'standard', | |
| 170 | + 'Standard', | |
| 171 | + current_time('mysql', true), | |
| 172 | + current_time('mysql', true) | |
| 173 | + )); | |
| 158 | 174 | } |
| 159 | 175 | } |