PluginProbe
Boxzilla – WordPress Popup Builder / 3.0
Boxzilla – WordPress Popup Builder v3.0
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
boxzilla / src / admin / class-migrations.php

class-migrations.php in Boxzilla – WordPress Popup Builder 3.0, at src/admin/class-migrations.php

82 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Boxzilla\Admin;
4
5 use Exception;
6
7 /**
8 *
9 */
10 class Migrations {
11
12 /**
13 * @var float
14 */
15 protected $version_from = 0;
16
17 /**
18 * @var float
19 */
20 protected $version_to = 0;
21
22 /**
23 * @var string
24 */
25 protected $migrations_dir = '';
26
27 /**
28 * @param float $from
29 * @param float $to
30 * @param string $migrations_dir
31 */
32 public function __construct( $from, $to, $migrations_dir ) {
33 $this->version_from = $from;
34 $this->version_to = $to;
35 $this->migrations_dir = $migrations_dir;
36 }
37
38 /**
39 * Run the various upgrade routines, all the way up to the latest version
40 */
41 public function run() {
42 $migrations = $this->find_migrations();
43 // run in sub-function for scope
44 array_map( array( $this, 'run_migration' ), $migrations );
45 }
46
47 /**
48 * @return array
49 */
50 public function find_migrations() {
51 $files = glob( rtrim( $this->migrations_dir, '/' ) . '/*.php' );
52 $migrations = array();
53
54 foreach( $files as $file ) {
55 $migration = basename( $file );
56 $parts = explode( '-', $migration );
57 $version = $parts[0];
58
59 if( version_compare( $this->version_from, $version, '<' ) ) {
60 $migrations[] = $file;
61 }
62 }
63
64 return $migrations;
65 }
66
67 /**
68 * Include a migration file and runs it.
69 *
70 * @param string $file
71 *
72 * @throws Exception
73 */
74 protected function run_migration( $file ) {
75
76 if( ! file_exists( $file ) ) {
77 throw new Exception( "Migration file $file does not exist.");
78 }
79
80 include $file;
81 }
82 }