-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-migrations.php
99 lines (78 loc) · 2.76 KB
/
wp-migrations.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/*
Plugin Name: WP Migrations
Description: Enable hardcoded migrations for every WordPress plugin option
Author: Pionect
Version: 0.0.1
Author URI: http://www.pionect.nl
Text Domain: wp_migrations
*/
/**
* TODO
* - fix fatal error, when mu-plugin & WPI cli call is made
* - migrations creator - pick two versions and create a migration
* - add tabs to the value modal [raw, maybe_unserialized, diff]
* - show real plugin names instead of folder names
* - change repositories to singletons
* - add page with a list of all the migrations ran
* - add a notice if the supplied migrations folder isn't correct
* - add a setting to enable/disable optionVersions
**/
namespace WP_Migrations;
use Composer\Semver\Comparator;
use WP_Migrations\OptionVersions\Repositories\OptionScriptRepository;
use WP_Migrations\OptionVersions\Repositories\OptionVersionRepository;
include('vendor/autoload.php');
class Plugin
{
const VERSION = '0.0.1';
static function init()
{
if(!class_exists('\WP_Migrations\OptionVersions\Tracking\OptionScriptProvider')){
return;
}
if(!get_option('siteurl')){
return;
}
static::plugin_upgrade();
add_action('admin_init', array(static::class, 'run_migrations'), 100);
$optionScriptTrackingProvider = new OptionVersions\Tracking\OptionScriptProvider(
new OptionScriptRepository()
);
$optionScriptTrackingProvider->init();
$optionVersionTrackingProvider = new OptionVersions\Tracking\OptionVersionProvider(
new OptionVersionRepository()
);
$optionVersionTrackingProvider->init();
$optionVersionsUIProvider = new OptionVersions\UserInterface\Provider(
new OptionVersionRepository()
);
$optionVersionsUIProvider->init();
}
static function plugin_upgrade()
{
$currentVersion = get_option('wp-migrations-version') ?: '0.0.0';
if(Comparator::lessThan($currentVersion,'0.0.1')) {
// initial installation
Migrations\Repository::createRepository();
OptionVersionRepository::createRepository();
OptionScriptRepository::createRepository();
}
add_option('wp-migrations-version', self::VERSION);
}
static function run_migrations()
{
$directory = apply_filters('wpmigrations_directory', null);
$namespace = apply_filters('wpmigrations_namespace', 'Migrations');
if (is_null($directory)) {
return;
}
$migrationHandler = new Migrations\Migrator(
new Migrations\Repository(),
new Migrations\Validator(),
$namespace
);
$migrationHandler->run($directory);
}
}
Plugin::init();