<?php
namespace WPMailSMTP;
/**
* Class MigrationAbstract helps migrate plugin options, DB tables and more.
*
* @since 3.0.0
*/
abstract class MigrationAbstract {
/**
* Version of the latest migration.
*
* @since 3.0.0
*/
const DB_VERSION = 1;
/**
* Option key where we save the current migration version.
*
* @since 3.0.0
*/
const OPTION_NAME = 'wp_mail_smtp_migration_version';
/**
* Option key where we save any errors while performing migration.
*
* @since 3.0.0
*/
const ERROR_OPTION_NAME = 'wp_mail_smtp_migration_error';
/**
* Current migration version, received from static::OPTION_NAME WP option
*
* @since 3.0.0
*
* @var int
*/
protected $cur_ver;
/**
* Migration constructor.
*
* @since 3.0.0
*/
public function __construct() {
$this->cur_ver = static::get_current_version();
}
/**
* Initialize migration.
*
* @since 3.0.0
*/
public function init() {
$this->validate_db();
}
/**
* Whether migration is enabled.
*
* @since 3.0.0
*
* @return bool
*/
public static function is_enabled() {
return true;
}
/**
* Static on purpose, to get current DB version without __construct() and validation.
*
* @since 3.0.0
*
* @return int
*/
public static function get_current_version() {
return (int) get_option( static::OPTION_NAME, 0 );
}
/**
* Check DB version and update to the latest one.
*
* @since 3.0.0
*/
protected function validate_db() {
if ( $this->cur_ver < static::DB_VERSION ) {
$this->run( static::DB_VERSION );
}
}
/**
* Update DB version in options table.
*
* @since 3.0.0
*
* @param int $version Version number.
*/
protected function update_db_ver( $version = 0 ) {
$version = (int) $version;
if ( empty( $version ) ) {
$version = static::DB_VERSION;
}
// Autoload it, because this value is checked all the time
// and no need to request it separately from all autoloaded options.
update_option( static::OPTION_NAME, $version, true );
}
/**
* Prevent running the same migration twice.
* Run migration only when required.
*
* @since 3.0.0
*
* @param int $version The current migration version.
*/
protected function maybe_required_older_migrations( $version ) {
$version = (int) $version;
if ( ( $version - $this->cur_ver ) > 1 ) {
$this->run( $version - 1 );
}
}
/**
* Actual migration launcher.
*
* @since 3.0.0
*
* @param int $version The specified migration version to run.
*/
protected function run( $version ) {
$version = (int) $version;
if ( method_exists( $this, 'migrate_to_' . $version ) ) {
$this->{'migrate_to_' . $version}();
} else {
if ( WP::in_wp_admin() ) {
$message = sprintf( /* translators: %1$s - the DB option name, %2$s - WP Mail SMTP, %3$s - error message. */
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' ),
static::OPTION_NAME,
'<strong>WP Mail SMTP</strong>',
'<code>migration from v' . static::get_current_version() . ' to v' . static::DB_VERSION . ' failed. Plugin version: v' . WPMS_PLUGIN_VER . '</code>'
);
WP::add_admin_notice( $message, WP::ADMIN_NOTICE_ERROR );
}
}
}
}
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| Abilities/ | 2026-07-21 14:14 | 14.29 KB | 76129f60960:kunden | dxwrx-r--r | |
| Admin/ | 2026-07-21 14:14 | 651.31 KB | 76129f60960:kunden | dxwrx-r--r | |
| Compatibility/ | 2026-07-21 14:14 | 9.47 KB | 76129f60960:kunden | dxwrx-r--r | |
| Helpers/ | 2026-07-21 14:14 | 29.47 KB | 76129f60960:kunden | dxwrx-r--r | |
| Integrations/ | 2026-07-21 14:14 | 7.61 KB | 76129f60960:kunden | dxwrx-r--r | |
| Providers/ | 2026-07-21 14:14 | 380.79 KB | 76129f60960:kunden | dxwrx-r--r | |
| Queue/ | 2026-07-21 14:14 | 36.42 KB | 76129f60960:kunden | dxwrx-r--r | |
| Reports/ | 2026-07-21 14:14 | 28.76 KB | 76129f60960:kunden | dxwrx-r--r | |
| Tasks/ | 2026-07-21 14:14 | 40.6 KB | 76129f60960:kunden | dxwrx-r--r | |
| TestEmail/ | 2026-07-21 14:14 | 22.48 KB | 76129f60960:kunden | dxwrx-r--r | |
| UsageTracking/ | 2026-07-21 14:14 | 22.97 KB | 76129f60960:kunden | dxwrx-r--r | |
| WPCLI/ | 2026-07-21 14:14 | 52.21 KB | 76129f60960:kunden | dxwrx-r--r | |
| AbstractConnection.php | 2026-07-21 14:14 | 1.09 KB | 76129f60960:kunden | -xw-x----- | |
| Conflicts.php | 2026-07-21 14:14 | 16.65 KB | 76129f60960:kunden | -xw-x----- | |
| Connect.php | 2026-07-21 14:14 | 9.18 KB | 76129f60960:kunden | -xw-x----- | |
| Connection.php | 2026-07-21 14:14 | 964 B | 76129f60960:kunden | -xw-x----- | |
| ConnectionInterface.php | 2026-07-21 14:14 | 1.01 KB | 76129f60960:kunden | -xw-x----- | |
| ConnectionsManager.php | 2026-07-21 14:14 | 765 B | 76129f60960:kunden | -xw-x----- | |
| Core.php | 2026-07-21 14:14 | 33.84 KB | 76129f60960:kunden | -xw-x----- | |
| DBRepair.php | 2026-07-21 14:14 | 6.36 KB | 76129f60960:kunden | -xw-x----- | |
| Debug.php | 2026-07-21 14:14 | 4.24 KB | 76129f60960:kunden | -xw-x----- | |
| EmailSendingDebug.php | 2026-07-21 14:14 | 4.82 KB | 76129f60960:kunden | -xw-x----- | |
| Geo.php | 2026-07-21 14:14 | 6.76 KB | 76129f60960:kunden | -xw-x----- | |
| MailCatcher.php | 2026-07-21 14:14 | 1.36 KB | 76129f60960:kunden | -xw-x----- | |
| MailCatcherInterface.php | 2026-07-21 14:14 | 1.16 KB | 76129f60960:kunden | -xw-x----- | |
| MailCatcherTrait.php | 2026-07-21 14:14 | 27.44 KB | 76129f60960:kunden | -xw-x----- | |
| MailCatcherV6.php | 2026-07-21 14:14 | 1.2 KB | 76129f60960:kunden | -xw-x----- | |
| Migration.php | 2026-07-21 14:14 | 12.11 KB | 76129f60960:kunden | -xw-x----- | |
| MigrationAbstract.php | 2026-07-21 14:14 | 3.21 KB | 76129f60960:kunden | -xw-x----- | |
| Migrations.php | 2026-07-21 14:14 | 4.12 KB | 76129f60960:kunden | -xw-x----- | |
| OptimizedEmailSending.php | 2026-07-21 14:14 | 1.17 KB | 76129f60960:kunden | -xw-x----- | |
| Options.php | 2026-07-21 14:14 | 48.36 KB | 76129f60960:kunden | -xw-x----- | |
| Processor.php | 2026-07-21 14:14 | 14.11 KB | 76129f60960:kunden | -xw-x----- | |
| SiteHealth.php | 2026-07-21 14:14 | 12.66 KB | 76129f60960:kunden | -xw-x----- | |
| Upgrade.php | 2026-07-21 14:14 | 1.55 KB | 76129f60960:kunden | -xw-x----- | |
| Uploads.php | 2026-07-21 14:14 | 5.44 KB | 76129f60960:kunden | -xw-x----- | |
| WP.php | 2026-07-21 14:14 | 24.5 KB | 76129f60960:kunden | -xw-x----- | |
| WPMailArgs.php | 2026-07-21 14:14 | 4.44 KB | 76129f60960:kunden | -xw-x----- | |
| WPMailInitiator.php | 2026-07-21 14:14 | 4.38 KB | 76129f60960:kunden | -xw-x----- | |