GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( dc0f35...efd704 )
by Christian
15s
created

inc/Migration.php (4 issues)

1
<?php
2
/**
3
 * @author    Podlove <[email protected]>
4
 * @copyright Copyright (c) 2014-2018, Podlove
5
 * @license   https://github.com/podlove/podlove-subscribe-button-wp-plugin/blob/master/LICENSE MIT
6
 * @package   Podlove\PodloveSubscribeButton
7
 */
8
9
/**
10
 * Version management for database migrations.
11
 *
12
 * Database changes require special care:
13
 * - the model has to be adjusted for users installing the plugin
14
 * - the current setup has to be migrated for current users
15
 *
16
 * These migrations are a way to handle current users. They do *not*
17
 * run on plugin activation.
18
 *
19
 * Pattern:
20
 *
21
 * - increment \PodloveSubscribeButton\DATABASE_VERSION constant by 1, e.g.
22
 * 		```php
23
 * 		define( __NAMESPACE__ . '\DATABASE_VERSION', 2 );
24
 * 		```
25
 *
26
 * - add a case in `\PodloveSubscribeButton\run_migrations_for_version`, e.g.
27
 * 		```php
28
 * 		function run_migrations_for_version( $version ) {
29
 *			global $wpdb;
30
 *			switch ( $version ) {
31
 *				case 2:
32
 *					$wbdb-> // run sql or whatever
33
 *					break;
34
 *			}
35
 *		}
36
 *		```
37
 *
38
 *		Feel free to move the migration code into a separate function if it's
39
 *		rather complex.
40
 *
41
 * - adjust the main model / setup process so new users installing the plugin
42
 *   will have these changes too
43
 *
44
 * - Test the migrations! :)
45
 */
46
47
namespace PodloveSubscribeButton;
48
use \PodloveSubscribeButton\Model;
49
50
define( __NAMESPACE__ . '\DATABASE_VERSION', 3 );
51
52
class Migration {
53
54
	public static function eval_db() {
55
		add_action( 'admin_init', array( 'PodloveSubscribeButton\Migration', 'maybe_run_database_migrations' ) );
56
		add_action( 'admin_init', array( 'PodloveSubscribeButton\Migration', 'run_database_migrations' ), 5 );
57
	}
58
59
	public static function maybe_run_database_migrations() {
60
		$database_version = get_option( 'podlove_subscribe_button_plugin_database_version' );
61
62
		if ( $database_version === false ) {
63
			// plugin has just been installed or Plugin Version < 1.3
64
			update_option( 'podlove_subscribe_button_plugin_database_version', DATABASE_VERSION );
65
		}
66
67
	}
68
69
	public static function run_database_migrations() {
70
		if ( get_option( 'podlove_subscribe_button_plugin_database_version' ) >= DATABASE_VERSION ) {
71
			return;
72
		}
73
74
		if ( is_multisite() ) {
75
			set_time_limit( 0 ); // may take a while, depending on network size
76
			Helpers::for_every_podcast_blog( function() { self::migrate_for_current_blog(); });
77
		} else {
78
			self::migrate_for_current_blog();
79
		}
80
81
		if ( isset( $_REQUEST[ '_wp_http_referer' ] ) && $_REQUEST[ '_wp_http_referer' ] ) {
82
			wp_redirect( $_REQUEST[ '_wp_http_referer' ] );
83
			exit;
84
		}
85
	}
86
87
	public static function migrate_for_current_blog() {
88
		$database_version = get_option( 'podlove_subscribe_button_plugin_database_version' );
89
90
		for ( $i = $database_version + 1; $i <= DATABASE_VERSION; $i++ ) {
91
			self::run_migrations_for_version( $i );
92
			update_option( 'podlove_subscribe_button_plugin_database_version', $i );
93
		}
94
95
	}
96
97
	/**
98
	 * Find and run migration for given version number.
99
	 *
100
	 * @todo  move migrations into separate files
101
	 *
102
	 * @param  int $version
103
	 */
104
	private static function run_migrations_for_version( $version ) {
105
		global $wpdb;
106
107
		switch ( $version ) {
108
			case 3:
109
				self::migration_case_3();
110
				break;
111
		}
112
113
	}
114
115
	private static function migration_case_3() {
116
117
		/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
118
		 * @todo
119
		 *
120
		 * network: for each blog with plugin active (or all ?)
121
		 */
122
123
		//
0 ignored issues
show
Blank comments are not allowed
Loading history...
124
		/**
125
		 * 1. multiple options -> 1 option as associative array
126
		 * - consolidate `_default_*` into `_podlove_psb_defaults[*]`
127
		 * - remove old options
128
		 */
129
		if ( ! get_option( 'podlove_subscribe_button_default_size' ) ) {
130
			$old_options = array(
131
				'podlove_subscribe_button_default_size',
132
				'podlove_subscribe_button_default_autowidth',
133
				'podlove_subscribe_button_default_color',
134
				'podlove_subscribe_button_default_style',
135
				'podlove_subscribe_button_default_format',
136
				'podlove_subscribe_button_default_language',
137
			);
138
			$options     = array();
139
140
			foreach ( $old_options as $option ) {
141
142
				$split = explode( '_', $option );
143
				$key   = end( $split );
144
				$value = get_option( $option );
145
146
				$options[ $key ] = $value;
147
			}
148
149
			// if old ones exist
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
150
			add_option( 'podlove_psb_defaults', $options );
151
152
			foreach ( $old_options as $option ) {
153
				delete_option( $option );
154
			}
155
		}
156
157
		// 2. DB !?
0 ignored issues
show
There must be no blank line following an inline comment
Loading history...
158
159
	}
160
161
}
162