PluginProbe
HTML Forms – Simple WordPress Forms Plugin / 1.3.27
HTML Forms – Simple WordPress Forms Plugin v1.3.27
trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 All 66 releases
html-forms / src / admin / class-migrations.php

class-migrations.php in HTML Forms – Simple WordPress Forms Plugin 1.3.27, at src/admin/class-migrations.php

87 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace HTML_Forms\Admin;
4
5 /**
6 * Class Migrations
7 *
8 * This class takes care of loading migration files from the specified migrations directory.
9 * Migration files should only use default WP functions and NOT use code which might not be there in the future.
10 *
11 * @ignore
12 */
13 class Migrations {
14
15 /**
16 * @var float
17 */
18 protected $version_from = 0;
19
20 /**
21 * @var float
22 */
23 protected $version_to = 0;
24
25 /**
26 * @var string
27 */
28 protected $migrations_dir = '';
29
30 /**
31 * @param string $from
32 * @param string $to
33 * @param string $migrations_dir
34 */
35 public function __construct( $from, $to, $migrations_dir ) {
36 $this->version_from = $from;
37 $this->version_to = $to;
38 $this->migrations_dir = $migrations_dir;
39 }
40
41 /**
42 * Run the various upgrade routines, all the way up to the latest version
43 */
44 public function run() {
45 $migrations = $this->find_migrations();
46
47 // run in function for scope
48 array_map( array( $this, 'run_migration' ), $migrations );
49 }
50
51 /**
52 * @return array
53 */
54 public function find_migrations() {
55
56 $files = glob( rtrim( $this->migrations_dir, '/' ) . '/*.php' );
57 $migrations = array();
58
59 // return empty array when glob returns non-array value.
60 if ( ! is_array( $files ) ) {
61 return $migrations;
62 }
63
64 foreach ( $files as $file ) {
65 $migration = basename( $file );
66 $parts = explode( '-', $migration );
67 $version = $parts[0];
68
69 if ( version_compare( $this->version_from, $version, '<' ) ) {
70 $migrations[] = $file;
71 }
72 }
73
74 return $migrations;
75 }
76
77 /**
78 * Include a migration file and runs it.
79 *
80 * @param string $file
81 */
82 protected function run_migration( $file ) {
83 include $file;
84 }
85
86 }
87