( ( (int) $stored_version_as_number ) / 1000 ) ) { return ( in_array( $key, range( $stored_version_as_number + 1, $target_version_as_number ), true ) ); } return false; }, ARRAY_FILTER_USE_BOTH ); if ( ! empty( $migrate_methods ) ) { \ksort( $migrate_methods ); foreach ( $migrate_methods as $method ) { static::{$method}(); } } self::store_updated_version(); } finally { \WSAL\Helpers\WP_Helper::delete_global_option( self::STARTED_MIGRATION_PROCESS ); } } } /** * Downgrading the plugin? Set the version number. * Leave the rest as is. * * @return void * * @since 4.4.2.1 */ if ( false === $migration_started && version_compare( static::get_stored_version(), \constant( static::$const_name_of_plugin_version ), '>' ) ) { self::store_updated_version(); } } /** * Removes redundant notices * * @param string $notice - Notice to be removed. * * @return void * * @since 4.4.2.1 */ public static function remove_notice( string $notice ) { global $wpdb; $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '%s';", // phpcs:ignore $notice ) ); } /** * Extracts currently stored version from the DB * * @return string * * @since 4.4.0 */ private static function get_stored_version() { if ( '' === trim( static::$stored_version ) ) { static::$stored_version = WP_Helper::get_global_option( static::$version_option_name, '0.0.0' ); } return static::$stored_version; } /** * Stores the version to which we migrated * * @return void * * @since 4.4.0 */ private static function store_updated_version() { if ( version_compare( static::get_stored_version(), \constant( static::$const_name_of_plugin_version ), '<' ) ) { WP_Helper::update_global_option( static::$version_option_name, \constant( static::$const_name_of_plugin_version ) ); if ( '0.0.0' !== (string) static::$stored_version ) { WP_Helper::set_global_option( self::UPGRADE_NOTICE, true ); } } } /** * Normalized the version numbers to numbers * * Version format is expected to be as follows: * X.X.X * * All non numeric values will be removed from the version string * * Note: version is expected in version format - 1.0.0; 1; 1.0; 1.0.0.0 * Note: only numbers will be processed * * @param string $version - The version string we have to use. * * @return int * * @since 4.4.0 */ private static function normalize_version( string $version ): string { $version_as_number = (string) filter_var( $version, FILTER_SANITIZE_NUMBER_INT ); if ( self::$pad_length > strlen( $version_as_number ) ) { $version_as_number = str_pad( $version_as_number, static::$pad_length, '0', STR_PAD_RIGHT ); } return $version_as_number; } /** * Collects all the migration methods from the class and stores them in the array * Array is in following format: * key - number of the version * value - name of the method * * @return array * * @since 4.4.0 */ private static function get_all_migration_methods_as_numbers() { $class_methods = \get_class_methods( get_called_class() ); $method_as_version_numbers = array(); foreach ( $class_methods as $method ) { if ( false !== \strpos( $method, 'migrate_up_to_' ) ) { $ver = \substr( $method, \strrpos( $method, '_' ) + 1, \strlen( $method ) ); $method_as_version_numbers[ $ver ] = $method; } } return $method_as_version_numbers; } } }