| @@ -185,8 +185,52 @@ | ||
| 185 | 185 | 'plugin' => 'double-opt-in', |
| 186 | 186 | ] ); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | + if ( version_compare( $currentVersion, '5.6.0' ) < 0 ) { | |
| 190 | + $logger->info( 'Updating to version 5.6.0 (adds follow-up status table)', [ | |
| 191 | + 'plugin' => 'double-opt-in', | |
| 192 | + 'current' => $currentVersion, | |
| 193 | + 'target' => '5.6.0', | |
| 194 | + ] ); | |
| 195 | + | |
| 196 | + // New table only. Opt-ins confirmed before this version get no | |
| 197 | + // rows and are shown as "no status recorded" — deliberately not | |
| 198 | + // replayed, which would re-send historic mails. | |
| 199 | + \Forge12\DoubleOptIn\Repository\FollowUpSchema::install(); | |
| 200 | + | |
| 201 | + update_option( FORGE12_OPTIN_SLUG . '_version', '5.6.0' ); | |
| 202 | + } | |
| 203 | + | |
| 204 | + if ( version_compare( $currentVersion, '5.8.0' ) < 0 ) { | |
| 205 | + $logger->info( 'Updating to version 5.8.0 (adds confirmation mail status columns)', [ | |
| 206 | + 'plugin' => 'double-opt-in', | |
| 207 | + 'current' => $currentVersion, | |
| 208 | + 'target' => '5.8.0', | |
| 209 | + ] ); | |
| 210 | + | |
| 211 | + // mail_status / mail_error / mail_status_at. Existing rows keep an | |
| 212 | + // empty status ("recorded before 5.8"), nothing is back-filled. | |
| 213 | + createTableOptin(); | |
| 214 | + | |
| 215 | + update_option( FORGE12_OPTIN_SLUG . '_version', '5.8.0' ); | |
| 216 | + } | |
| 217 | + | |
| 218 | + if ( version_compare( $currentVersion, '5.12.0' ) < 0 ) { | |
| 219 | + $logger->info( 'Updating to version 5.12.0 (adds form_ref column)', [ | |
| 220 | + 'plugin' => 'double-opt-in', | |
| 221 | + 'current' => $currentVersion, | |
| 222 | + 'target' => '5.12.0', | |
| 223 | + ] ); | |
| 224 | + | |
| 225 | + // form_ref tells two forms on the same page apart. Existing rows | |
| 226 | + // keep an empty value and stay tied to the whole form; nothing is | |
| 227 | + // guessed or back-filled. | |
| 228 | + createTableOptin(); | |
| 229 | + | |
| 230 | + update_option( FORGE12_OPTIN_SLUG . '_version', '5.12.0' ); | |
| 231 | + } | |
| 232 | + | |
| 189 | 233 | // Safety net: Ensure both tables always exist regardless of stored version. |
| 190 | 234 | // Handles edge cases such as database migrations, manual file uploads, or |
| 191 | 235 | // restored backups that are missing the custom tables. |
| 192 | 236 | global $wpdb; |
| @@ -206,8 +250,13 @@ | ||
| 206 | 250 | $auditTable = $wpdb->prefix . 'f12_cf7_doubleoptin_audit_log'; |
| 207 | 251 | if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $auditTable ) ) !== $auditTable ) { |
| 208 | 252 | $logger->warning( 'Audit log table missing – recreating.', [ 'plugin' => 'double-opt-in', 'table' => $auditTable ] ); |
| 209 | 253 | createTableAuditLog(); |
| 254 | + } | |
| 255 | + | |
| 256 | + if ( ! \Forge12\DoubleOptIn\Repository\FollowUpSchema::isCurrent() ) { | |
| 257 | + $logger->warning( 'Follow-up table missing or outdated – running dbDelta.', [ 'plugin' => 'double-opt-in' ] ); | |
| 258 | + \Forge12\DoubleOptIn\Repository\FollowUpSchema::install(); | |
| 210 | 259 | } |
| 211 | 260 | |
| 212 | 261 | // Always pin the stored version to the live plugin version. The |
| 213 | 262 | // version_compare ladder above only writes the target of the last |