PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.0-dev2
Elementor Website Builder – more than just a page builder v4.1.0-dev2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / database / base-database-updater.php

base-database-updater.php in Elementor Website Builder – more than just a page builder 4.1.0-dev2, at core/database/base-database-updater.php

55 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Database;
3
4 use Elementor\Core\Utils\Collection;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 abstract class Base_Database_Updater {
11 public function up( $force = false ) {
12 $installed_version = $this->get_installed_version();
13
14 if ( ! $force && $this->get_db_version() <= $installed_version ) {
15 return;
16 }
17
18 $migrations = new Collection( $this->get_migrations() );
19
20 if ( ! $force ) {
21 $migrations = $migrations->filter( function ( $_, $version ) use ( $installed_version ) {
22 return $version > $installed_version;
23 } );
24 }
25
26 $migrations->map( function ( Base_Migration $migration, $version ) {
27 $migration->up();
28
29 $this->update_db_version_option( $version );
30 } );
31
32 $this->update_db_version_option( $this->get_db_version() );
33 }
34
35 public function register() {
36 add_action( 'admin_init', function () {
37 $this->up();
38 } );
39 }
40
41 protected function update_db_version_option( $version ) {
42 update_option( $this->get_db_version_option_name(), $version );
43 }
44
45 protected function get_installed_version() {
46 return intval( get_option( $this->get_db_version_option_name() ) );
47 }
48
49 abstract protected function get_db_version();
50
51 abstract protected function get_db_version_option_name(): string;
52
53 abstract protected function get_migrations(): array;
54 }
55