$stored ) && ( $ver > $stored ) && ( $ver <= $target ); }, ARRAY_FILTER_USE_BOTH ); if ( ! empty( $migrate_methods ) ) { \ksort( $migrate_methods ); foreach ( $migrate_methods as $method ) { static::{$method}(); } } self::store_updated_version(); } /** * Downgrading the plugin? Set the version number. * Leave the rest as is. * * @return void * * @since 1.1.0 */ if ( version_compare( static::get_stored_version(), \ADVAN_VERSION, '>' ) ) { self::store_updated_version(); } } /** * Extracts currently stored version from the DB * * @return string * * @since 1.1.0 */ private static function get_stored_version() { if ( '' === trim( (string) static::$stored_version ) ) { static::$stored_version = (string) Settings::get_version(); } return static::$stored_version; } /** * Stores the version to which we migrated * * @return void * * @since 1.1.0 */ private static function store_updated_version() { Settings::store_version(); } /** * 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 string * * @since 1.1.0 */ public static function normalize_version( string $version ) { $version_as_number = (int) filter_var( $version, FILTER_SANITIZE_NUMBER_INT ); if ( self::$pad_length > strlen( (string) $version_as_number ) ) { $version_as_number = str_pad( (string) $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 1.1.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; } } }