PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 4.7.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v4.7.0
0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / src / MigrationAbstract.php
wp-mail-smtp / src Last commit date
Admin 6 months ago Compatibility 6 months ago Helpers 6 months ago Providers 6 months ago Queue 6 months ago Reports 6 months ago Tasks 6 months ago UsageTracking 6 months ago AbstractConnection.php 6 months ago Conflicts.php 6 months ago Connect.php 6 months ago Connection.php 6 months ago ConnectionInterface.php 6 months ago ConnectionsManager.php 6 months ago Core.php 6 months ago DBRepair.php 6 months ago Debug.php 6 months ago Geo.php 6 months ago MailCatcher.php 6 months ago MailCatcherInterface.php 6 months ago MailCatcherTrait.php 6 months ago MailCatcherV6.php 6 months ago Migration.php 6 months ago MigrationAbstract.php 6 months ago Migrations.php 6 months ago OptimizedEmailSending.php 6 months ago Options.php 6 months ago Processor.php 6 months ago SiteHealth.php 6 months ago Upgrade.php 6 months ago Uploads.php 6 months ago WP.php 6 months ago WPMailArgs.php 6 months ago WPMailInitiator.php 6 months ago
MigrationAbstract.php
162 lines
1 <?php
2
3 namespace WPMailSMTP;
4
5 /**
6 * Class MigrationAbstract helps migrate plugin options, DB tables and more.
7 *
8 * @since 3.0.0
9 */
10 abstract class MigrationAbstract {
11
12 /**
13 * Version of the latest migration.
14 *
15 * @since 3.0.0
16 */
17 const DB_VERSION = 1;
18
19 /**
20 * Option key where we save the current migration version.
21 *
22 * @since 3.0.0
23 */
24 const OPTION_NAME = 'wp_mail_smtp_migration_version';
25
26 /**
27 * Option key where we save any errors while performing migration.
28 *
29 * @since 3.0.0
30 */
31 const ERROR_OPTION_NAME = 'wp_mail_smtp_migration_error';
32
33 /**
34 * Current migration version, received from static::OPTION_NAME WP option
35 *
36 * @since 3.0.0
37 *
38 * @var int
39 */
40 protected $cur_ver;
41
42 /**
43 * Migration constructor.
44 *
45 * @since 3.0.0
46 */
47 public function __construct() {
48
49 $this->cur_ver = static::get_current_version();
50 }
51
52 /**
53 * Initialize migration.
54 *
55 * @since 3.0.0
56 */
57 public function init() {
58
59 $this->validate_db();
60 }
61
62 /**
63 * Whether migration is enabled.
64 *
65 * @since 3.0.0
66 *
67 * @return bool
68 */
69 public static function is_enabled() {
70
71 return true;
72 }
73
74 /**
75 * Static on purpose, to get current DB version without __construct() and validation.
76 *
77 * @since 3.0.0
78 *
79 * @return int
80 */
81 public static function get_current_version() {
82
83 return (int) get_option( static::OPTION_NAME, 0 );
84 }
85
86 /**
87 * Check DB version and update to the latest one.
88 *
89 * @since 3.0.0
90 */
91 protected function validate_db() {
92
93 if ( $this->cur_ver < static::DB_VERSION ) {
94 $this->run( static::DB_VERSION );
95 }
96 }
97
98 /**
99 * Update DB version in options table.
100 *
101 * @since 3.0.0
102 *
103 * @param int $version Version number.
104 */
105 protected function update_db_ver( $version = 0 ) {
106
107 $version = (int) $version;
108
109 if ( empty( $version ) ) {
110 $version = static::DB_VERSION;
111 }
112
113 // Autoload it, because this value is checked all the time
114 // and no need to request it separately from all autoloaded options.
115 update_option( static::OPTION_NAME, $version, true );
116 }
117
118 /**
119 * Prevent running the same migration twice.
120 * Run migration only when required.
121 *
122 * @since 3.0.0
123 *
124 * @param int $version The current migration version.
125 */
126 protected function maybe_required_older_migrations( $version ) {
127
128 $version = (int) $version;
129
130 if ( ( $version - $this->cur_ver ) > 1 ) {
131 $this->run( $version - 1 );
132 }
133 }
134
135 /**
136 * Actual migration launcher.
137 *
138 * @since 3.0.0
139 *
140 * @param int $version The specified migration version to run.
141 */
142 protected function run( $version ) {
143
144 $version = (int) $version;
145
146 if ( method_exists( $this, 'migrate_to_' . $version ) ) {
147 $this->{'migrate_to_' . $version}();
148 } else {
149 if ( WP::in_wp_admin() ) {
150 $message = sprintf( /* translators: %1$s - the DB option name, %2$s - WP Mail SMTP, %3$s - error message. */
151 esc_html__( 'There was an error while upgrading the %1$s database. Please contact %2$s support with this information: %3$s.', 'wp-mail-smtp' ),
152 static::OPTION_NAME,
153 '<strong>WP Mail SMTP</strong>',
154 '<code>migration from v' . static::get_current_version() . ' to v' . static::DB_VERSION . ' failed. Plugin version: v' . WPMS_PLUGIN_VER . '</code>'
155 );
156
157 WP::add_admin_notice( $message, WP::ADMIN_NOTICE_ERROR );
158 }
159 }
160 }
161 }
162