Passed
Push — master ( aa437c...805644 )
by Chris
08:50
created

MonsterInsights_Install::init()   F

Complexity

Conditions 14
Paths 388

Size

Total Lines 91
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 14
eloc 42
c 1
b 0
f 0
nc 388
nop 0
dl 0
loc 91
rs 3.0833

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * MonsterInsights Installation and Automatic Upgrades.
4
 *
5
 * This file handles setting up new
6
 * MonsterInsights installs as well as performing
7
 * behind the scene upgrades between
8
 * MonsterInsights versions.
9
 *
10
 * @package MonsterInsights
11
 * @subpackage Install/Upgrade
12
 * @since 6.0.0
13
 */
14
15
// Exit if accessed directly
16
if ( ! defined( 'ABSPATH' ) ) {
17
	exit;
18
}
19
20
/**
21
 * MonsterInsights Install.
22
 *
23
 * This class handles a new MI install
24
 * as well as automatic (non-user initiated)
25
 * upgrade routines.
26
 *
27
 * @since 6.0.0
28
 * @access public
29
 */
30
class MonsterInsights_Install {
31
32
	/**
33
	 * MI Settings.
34
	 *
35
	 * @since 6.0.0
36
	 * @access public
37
	 * @var array $new_settings When the init() function starts, initially
38
	 *      					contains the original settings. At the end
39
	 *      				 	of init() contains the settings to save.
40
	 */
41
	public $new_settings = array();
42
43
	/**
44
	 * Install/Upgrade routine.
45
	 *
46
	 * This function is what is called to actually install MI data on new installs and to do
47
	 * behind the scenes upgrades on MI upgrades. If this function contains a bug, the results
48
	 * can be catastrophic. This function gets the highest priority in all of MI for unit tests.
49
	 *
50
	 * @since 6.0.0
51
	 * @access public
52
	 *
53
	 * @return void
54
	 */
55
	public function init() {
56
57
		// Get a copy of the current MI settings.
58
		$this->new_settings = get_option( monsterinsights_get_option_name() );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_option(monsterinsights_get_option_name()) can also be of type false. However, the property $new_settings is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
59
60
		$version = get_option( 'monsterinsights_current_version', false );
61
		$cachec  = false; // have we forced an object cache to be cleared already (so we don't clear it unnecessarily)
62
63
		// if new install or Yoast Era instal
64
		if ( ! $version ) {
65
			// See if from Yoast
66
			$yoast   = get_option( 'yst_ga', false );
67
68
			// In case from Yoast, start from scratch
69
			delete_option( 'yoast-ga-access_token' );
70
			delete_option( 'yoast-ga-refresh_token' );
71
			delete_option( 'yst_ga' );
72
			delete_option( 'yst_ga_api' );
73
74
			$this->new_install();
75
76
			// set db version (Do not increment! See below large comment)
77
			update_option( 'monsterinsights_db_version', '7.4.0' );
78
79
			// Remove Yoast hook if present
80
			if ( wp_next_scheduled( 'yst_ga_aggregate_data' ) ) {
81
				wp_clear_scheduled_hook( 'yst_ga_aggregate_data' );
82
			}
83
84
			// Clear cache since coming from Yoast
85
			if ( ! $cachec && ! empty( $yoast ) ) {
0 ignored issues
show
introduced by
The condition $cachec is always false.
Loading history...
86
				wp_cache_flush();
87
				$cachec = true;
0 ignored issues
show
Unused Code introduced by
The assignment to $cachec is dead and can be removed.
Loading history...
88
			}
89
		} else { // if existing install
90
			if ( version_compare( $version, '6.0.11', '<' ) ) {
91
				if ( ! $cachec ) {
0 ignored issues
show
introduced by
The condition $cachec is always false.
Loading history...
92
					wp_cache_flush();
93
					$cachec = true;
94
				}
95
			}
96
97
			if ( version_compare( $version, '7.0.0', '<' ) ) {
98
				$this->v700_upgrades();
99
			}
100
101
			if ( version_compare( $version, '7.4.0', '<' ) ) {
102
				$this->v740_upgrades();
103
				// Do not increment! See below large comment
104
				update_option( 'monsterinsights_db_version', '7.4.0' );
105
			}
106
107
			if ( version_compare( $version, '7.5.0', '<' ) ) {
108
				$this->v750_upgrades();
109
			}
110
111
			if ( version_compare( $version, '7.6.0', '<' ) ) {
112
				$this->v760_upgrades();
113
			}
114
115
			if ( version_compare( $version, '7.7.1', '<' ) ) {
116
				$this->v771_upgrades();
117
			}
118
119
			if ( version_compare( $version, '7.8.0', '<' ) ) {
120
				$this->v780_upgrades();
121
			}
122
123
			if ( version_compare( $version, '7.9.0', '<' ) ) {
124
				$this->v790_upgrades();
125
			}
126
127
			// Do not use. See monsterinsights_after_install_routine comment below.
128
			do_action( 'monsterinsights_after_existing_upgrade_routine', $version );
129
			$version = get_option( 'monsterinsights_current_version', $version );
130
			update_option( 'monsterinsights_version_upgraded_from', $version );
131
		}
132
133
		// This hook is used primarily by the Pro version to run some Pro
134
		// specific install stuff. Please do not use this hook. It is not
135
		// considered a public hook by MI's dev team and can/will be removed,
136
		// relocated, and/or altered without warning at any time. You've been warned.
137
		// As this hook is not for public use, we've intentionally not docbloc'd this
138
		// hook to avoid developers seeing it future public dev docs.
139
		do_action( 'monsterinsights_after_install_routine', $version );
140
141
		// This is the version of MI installed
142
		update_option( 'monsterinsights_current_version', MONSTERINSIGHTS_VERSION );
143
144
		// This is where we save MI settings
145
		update_option( monsterinsights_get_option_name(), $this->new_settings );
146
147
		// There's no code for this function below this. Just an explanation
148
		// of the MI core options.
149
150
		/**
151
		 * Explanation of MonsterInsights core options
152
		 *
153
		 * By now your head is probably spinning trying to figure
154
		 * out what all of these version options are for. Note, I've abbreviated
155
		 * "monsterinsights" to "mi" in the options names to make this table easier
156
		 * to read.
157
		 *
158
		 * Here's a basic rundown:
159
		 *
160
		 * mi_current_version:  This starts with the actual version MI was
161
		 * 						installed on. We use this version to
162
		 * 						determine whether or not a site needs
163
		 * 						to run one of the behind the scenes
164
		 * 						MI upgrade routines. This version is updated
165
		 * 						every time a minor or major background upgrade
166
		 * 						routine is run. Generally lags behind the
167
		 * 						MONSTERINSIGHTS_VERSION constant by at most a couple minor
168
		 * 						versions. Never lags behind by 1 major version
169
		 * 						or more generally.
170
		 *
171
		 * mi_db_version: 		This is different from mi_current_version.
172
		 * 						Unlike the former, this is used to determine
173
		 * 						if a site needs to run a *user* initiated
174
		 * 						upgrade routine (incremented in MI_Upgrade class). This
175
		 * 						value is only update when a user initiated
176
		 * 						upgrade routine is done. Because we do very
177
		 * 						few user initiated upgrades compared to
178
		 * 						automatic ones, this version can lag behind by
179
		 * 						2 or even 3 major versions. Generally contains
180
		 * 						the current major version.
181
		 *
182
		 * mi_settings:		    Returned by monsterinsights_get_option_name(), this
183
		 * 						is actually "monsterinsights_settings" for both pro
184
		 * 						and lite version. However we use a helper function to
185
		 * 						retrieve the option name in case we ever decide down the
186
		 * 						road to maintain seperate options for the Lite and Pro versions.
187
		 * 					 	If you need to access MI's settings directly, (as opposed to our
188
		 * 					 	monsterinsights_get_option helper which uses the option name helper
189
		 * 					 	automatically), you should use this function to get the
190
		 * 					 	name of the option to retrieve.
191
		 *
192
		 * Therefore you should never increment mi_db_version in this file and always increment mi_current_version.
193
		 */
194
	}
195
196
197
	/**
198
	 * New MonsterInsights Install routine.
199
	 *
200
	 * This function installs all of the default
201
	 * things on new MI installs. Flight 5476 with
202
	 * non-stop service to a whole world of
203
	 * possibilities is now boarding.
204
	 *
205
	 * @since 6.0.0
206
	 * @access public
207
	 *
208
	 * @return void
209
	 */
210
	public function new_install() {
211
212
		// Add default settings values
213
		$this->new_settings = $this->get_monsterinsights_default_values();
214
215
		$this->maybe_import_thirstyaffiliates_options();
216
217
		$data = array(
218
			'installed_version' => MONSTERINSIGHTS_VERSION,
219
			'installed_date'    => time(),
220
			'installed_pro'     => monsterinsights_is_pro_version(),
221
		);
222
223
		update_option( 'monsterinsights_over_time', $data );
224
225
		// Let addons + MI Pro/Lite hook in here. @todo: doc as nonpublic
226
		do_action( 'monsterinsights_after_new_install_routine', MONSTERINSIGHTS_VERSION );
227
	}
228
229
	public function get_monsterinsights_default_values() {
230
		return array(
231
			'enable_affiliate_links'    => true,
232
			'affiliate_links'           => array(
233
				array(
234
					'path'  => '/go/',
235
					'label' => 'affiliate',
236
				),
237
				array(
238
					'path'  => '/recommend/',
239
					'label' => 'affiliate',
240
				)
241
			),
242
			'demographics'              => 1,
243
			'ignore_users'              => array( 'administrator' ),
244
			'dashboards_disabled'       => 0,
245
			'anonymize_ips'             => 0,
246
			'extensions_of_files'       => 'doc,exe,js,pdf,ppt,tgz,zip,xls',
247
			'subdomain_tracking'        => '',
248
			'link_attribution'          => true,
249
			'tag_links_in_rss'          => true,
250
			'allow_anchor'              => 0,
251
			'add_allow_linker'          => 0,
252
			'custom_code'               => '',
253
			'save_settings'             => array( 'administrator' ),
254
			'view_reports'              => array( 'administrator', 'editor' ),
255
			'events_mode'               => 'js',
256
			'tracking_mode'             => 'analytics',
257
		);
258
	}
259
260
	/**
261
	 * Check if ThirstyAffiliates plugin is installed and use the link prefix value in the affiliate settings.
262
	 *
263
	 * @return void
264
	 */
265
	public function maybe_import_thirstyaffiliates_options() {
266
267
		// Check if ThirstyAffiliates is installed.
268
		if ( ! function_exists( 'ThirstyAffiliates' ) ) {
269
			return;
270
		}
271
272
		$link_prefix = get_option( 'ta_link_prefix', 'recommends' );
273
274
		if ( $link_prefix === 'custom' ) {
275
			$link_prefix = get_option( 'ta_link_prefix_custom', 'recommends' );
276
		}
277
278
		if ( ! empty( $link_prefix ) ) {
279
280
			// Check if prefix exists.
281
			$prefix_set = false;
282
			foreach ( $this->new_settings['affiliate_links'] as $affiliate_link ) {
283
				if ( $link_prefix === trim( $affiliate_link['path'], '/' ) ) {
284
					$prefix_set = true;
285
					break;
286
				}
287
			}
288
289
			if ( ! $prefix_set ) {
290
				$this->new_settings['affiliate_links'][] = array(
291
					'path'  => '/' . $link_prefix . '/',
292
					'label' => 'affiliate',
293
				);
294
			}
295
		}
296
	}
297
298
	/**
299
	 * MonsterInsights Version 7.0 upgrades.
300
	 *
301
	 * This function does the
302
	 * upgrade routine from MonsterInsights 6.2->7.0.
303
	 *
304
	 * @since 7.0.0
305
	 * @access public
306
	 *
307
	 * @return void
308
	 */
309
	public function v700_upgrades() {
310
		// 1. Default all event tracking and tracking to GA + JS respectively
311
			// 3a Set tracking_mode to use analytics.js
312
			$this->new_settings['tracking_mode' ] = 'analytics';
313
314
315
			// 3b Set events mode to use JS if the events mode is not set explicitly to none
316
			if ( empty( $this->new_settings['events_mode' ] ) || $this->new_settings['events_mode' ] !== 'none' ) {
317
				$this->new_settings['events_mode' ] = 'js';
318
			}
319
320
		// 2. Migrate manual UA codes
321
			// 2a Manual UA has the lowest priority
322
			if ( ! empty( $this->new_settings['manual_ua_code' ] ) ) {
323
				// Set as manual UA code
324
				is_network_admin() ? update_site_option( 'monsterinsights_network_profile', array( 'manual' => $this->new_settings['manual_ua_code' ] ) ) : update_option( 'monsterinsights_site_profile', array( 'manual' => $this->new_settings['manual_ua_code' ] ) );
325
			}
326
327
			// 2b Then try the oAuth UA code
328
			if ( ! empty( $this->new_settings['analytics_profile_code' ] ) ) {
329
				// Set as manual UA code
330
				is_network_admin() ? update_site_option( 'monsterinsights_network_profile', array( 'manual' => $this->new_settings['analytics_profile_code' ] ) ) : update_option( 'monsterinsights_site_profile', array( 'manual' => $this->new_settings['analytics_profile_code' ] ) );
331
			}
332
333
		// 3. Migrate License keys
334
		if ( is_multisite() ) {
335
			$ms_license = get_site_option( 'monsterinsights_license', '' );
336
			if ( $ms_license ) {
337
				update_site_option( 'monsterinsights_network_license_updates', get_site_option( 'monsterinsights_license_updates', '' ) );
338
				update_site_option( 'monsterinsights_network_license', $ms_license );
339
			}
340
		}
341
	}
342
343
	/**
344
	 * Upgrade routine for the new settings panel, onboarding wizard, and the internal-as-outbound v2 settings system.
345
	 */
346
	public function v740_upgrades() {
347
348
		// 1. Settings Conversions:
349
			// Convert affiliate field to repeater format
350
			if ( ! empty( $this->new_settings['track_internal_as_outbound'] ) ) {
351
				$affiliate_old_paths = $this->new_settings['track_internal_as_outbound'];
352
				$affiliate_old_label = isset( $this->new_settings['track_internal_as_label'] ) ? $this->new_settings['track_internal_as_label'] : '';
353
354
				$new_paths = explode( ',', $affiliate_old_paths );
355
356
				$this->new_settings['affiliate_links'] = array();
357
				if ( ! empty( $new_paths ) ) {
358
					$this->new_settings['enable_affiliate_links'] = true;
359
					foreach ( $new_paths as $new_path ) {
360
						$this->new_settings['affiliate_links'][] = array(
361
							'path'  => $new_path,
362
							'label' => $affiliate_old_label,
363
						);
364
					}
365
				}
366
367
				$settings = array(
368
					'track_internal_as_outbound',
369
					'track_internal_as_label',
370
				);
371
				foreach ( $settings as $setting ) {
372
					if ( ! empty( $this->new_settings[ $setting ] ) ) {
373
						unset( $this->new_settings[ $setting ] );
374
					}
375
				}
376
			}
377
378
			// Update option to disable just reports or also the dashboard widget.
379
			if ( isset( $this->new_settings['dashboards_disabled'] ) && $this->new_settings['dashboards_disabled'] ) {
380
				$this->new_settings['dashboards_disabled'] = 'disabled';
381
			}
382
383
			$this->new_settings['tracking_mode'] = 'analytics';
384
			$this->new_settings['events_mode']   = 'js';
385
386
			// If opted in during allow_tracking era, move that over
387
			if ( ! empty( $this->new_settings['allow_tracking'] ) ) {
388
				$this->new_settings['anonymous_data'] = 1;
389
			}
390
391
		// 2. Remove Yoast stuff
392
			delete_option( 'yoast-ga-access_token' );
393
			delete_option( 'yoast-ga-refresh_token' );
394
			delete_option( 'yst_ga' );
395
			delete_option( 'yst_ga_api' );
396
397
398
		// 3. Remove fake settings from other plugins using our key for some reason and old settings of ours
399
			$settings = array(
400
				'debug_mode',
401
				'track_download_as',
402
				'analytics_profile',
403
				'analytics_profile_code',
404
				'analytics_profile_name',
405
				'manual_ua_code',
406
				'track_outbound',
407
				'track_download_as',
408
				'enhanced_link_attribution',
409
				'oauth_version',
410
				'monsterinsights_oauth_status',
411
				'firebug_lite',
412
				'google_auth_code',
413
				'allow_tracking',
414
			);
415
416
			foreach ( $settings as $setting ) {
417
				if ( ! empty( $this->new_settings[ $setting ] ) ) {
418
					unset( $this->new_settings[ $setting ] );
419
				}
420
			}
421
422
			$settings = array(
423
				'_repeated',
424
				'ajax',
425
				'asmselect0',
426
				'bawac_force_nonce',
427
				'icl_post_language',
428
				'saved_values',
429
				'mlcf_email',
430
				'mlcf_name',
431
				'cron_failed',
432
				'undefined',
433
				'cf_email',
434
				'cf_message',
435
				'cf_name',
436
				'cf_number',
437
				'cf_phone',
438
				'cf_subject',
439
				'content',
440
				'credentials',
441
				'cron_failed',
442
				'cron_last_run',
443
				'global-css',
444
				'grids',
445
				'page',
446
				'punch-fonts',
447
				'return_tab',
448
				'skins',
449
				'navigation-skins',
450
				'title',
451
				'type',
452
				'wpcf_email',
453
				'wpcf_your_name',
454
			);
455
456
			foreach ( $settings as $setting ) {
457
				if ( ! empty( $this->new_settings[ $setting ] ) ) {
458
					unset( $this->new_settings[ $setting ] );
459
				}
460
			}
461
462
		// 4. Remove old crons
463
			if ( wp_next_scheduled( 'monsterinsights_daily_cron' ) ) {
464
				wp_clear_scheduled_hook( 'monsterinsights_daily_cron' );
465
			}
466
			if ( wp_next_scheduled( 'monsterinsights_send_tracking_data' ) ) {
467
				wp_clear_scheduled_hook( 'monsterinsights_send_tracking_data' );
468
			}
469
470
			if ( wp_next_scheduled( 'monsterinsights_send_tracking_checkin' ) ) {
471
				wp_clear_scheduled_hook( 'monsterinsights_send_tracking_checkin' );
472
			}
473
474
			if ( wp_next_scheduled( 'monsterinsights_weekly_cron' ) ) {
475
				wp_clear_scheduled_hook( 'monsterinsights_weekly_cron' );
476
			}
477
478
			if ( wp_next_scheduled( 'yst_ga_aggregate_data' ) ) {
479
				wp_clear_scheduled_hook( 'yst_ga_aggregate_data' );
480
			}
481
482
			delete_option( 'monsterinsights_tracking_last_send' );
483
			delete_option( 'mi_tracking_last_send' );
484
485
		// 5. Remove old option
486
			delete_option( 'monsterinsights_settings_version' );
487
	}
488
489
490
	/**
491
	 * Upgrade routine
492
	 */
493
	public function v750_upgrades() {
494
		// 1. One time re-prompt for anonymous data (due to migration bug now fixed)
495
		// if ( ! monsterinsights_is_pro_version() ) {
496
		// 	if ( empty( $this->new_settings[ 'anonymous_data' ] ) ) {
497
		// 		update_option( 'monsterinsights_tracking_notice', 0 );
498
		// 	}
499
		// }
500
		//
501
		// 2. Clear old settings ( 	'tracking_mode','events_mode',)
502
503
504
		// 3. Attempt to extract the cross-domain settings from the Custom Code area and use in the new option.
505
		$custom_code = isset( $this->new_settings['custom_code'] ) ? $this->new_settings['custom_code'] : '';
506
		if ( ! empty( $custom_code ) ) {
507
			$pattern = '/(?:\'linker:autoLink\', )(?:\[)(.*)(?:\])/m';
508
			preg_match_all( $pattern, $custom_code, $matches, PREG_SET_ORDER, 0 );
509
			if ( ! empty( $matches ) && isset( $matches[0] ) && isset( $matches[0][1] ) ) {
510
				$cross_domains = array();
511
				$domains       = explode( ',', $matches[0][1] );
512
				foreach ( $domains as $key => $domain ) {
513
					$domain          = trim( $domain );
514
					$cross_domains[] = array(
515
						'domain' => trim( $domain, '\'\"' ),
516
					);
517
				}
518
				$this->new_settings['add_allow_linker'] = true;
519
				$this->new_settings['cross_domains']    = $cross_domains;
520
521
				$notices = get_option( 'monsterinsights_notices' );
522
				if ( ! is_array( $notices ) ) {
523
					$notices = array();
524
				}
525
				$notices['monsterinsights_cross_domains_extracted'] = false;
526
				update_option( 'monsterinsights_notices', $notices );
527
			}
528
		}
529
	}
530
531
	/**
532
	 * Upgrade routine for version 7.6.0
533
	 */
534
	public function v760_upgrades() {
535
536
		$cross_domains = isset( $this->new_settings['cross_domains'] ) ? $this->new_settings['cross_domains'] : array();
537
538
		if ( ! empty( $cross_domains ) && is_array( $cross_domains ) ) {
539
			$current_domain = wp_parse_url( home_url() );
540
			$current_domain = isset( $current_domain['host'] ) ? $current_domain['host'] : '';
541
			if ( ! empty( $current_domain ) ) {
542
				$regex = '/^(?:' . $current_domain . '|(?:.+)\.' . $current_domain . ')$/m';
543
				foreach ( $cross_domains as $key => $cross_domain ) {
544
					if ( ! isset( $cross_domain['domain'] ) ) {
545
						continue;
546
					}
547
					preg_match( $regex, $cross_domain['domain'], $matches );
548
					if ( count( $matches ) > 0 ) {
549
						unset( $this->new_settings['cross_domains'][ $key ] );
550
					}
551
				}
552
			}
553
		}
554
555
	}
556
557
	/**
558
	 * Upgrade routine for version 7.7.1
559
	 */
560
	public function v771_upgrades() {
561
562
		if ( ! monsterinsights_is_pro_version() ) {
563
			// We only need to run this for the Pro version.
564
			return;
565
		}
566
		include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
567
568
		$plugin = 'wp-scroll-depth/wp-scroll-depth.php';
569
		// Check if wp-scroll-depth is active and deactivate to avoid conflicts with the pro scroll tracking feature.
570
		if ( is_plugin_active( $plugin ) ) {
571
			deactivate_plugins( $plugin );
572
		}
573
574
	}
575
576
	/**
577
	 * Upgrade routine for version 7.8.0
578
	 */
579
	public function v780_upgrades() {
580
581
		if ( monsterinsights_get_ua() ) {
582
			// If we have a UA, don't show the first run notice.
583
			monsterinsights_update_option( 'monsterinsights_first_run_notice', true );
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $value of monsterinsights_update_option(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

583
			monsterinsights_update_option( 'monsterinsights_first_run_notice', /** @scrutinizer ignore-type */ true );
Loading history...
584
585
			// If they are already tracking when they upgrade, mark connected time as now.
586
			$over_time = get_option( 'monsterinsights_over_time', array() );
587
			if ( empty( $over_time['connected_date'] ) ) {
588
				$over_time['connected_date'] = time();
589
				update_option( 'monsterinsights_over_time', $over_time );
590
			}
591
		}
592
593
	}
594
595
	/**
596
	 * Upgrade routine for version 7.9.0
597
	 */
598
	public function v790_upgrades() {
599
600
		// If they are already tracking, don't show the notice.
601
		if ( monsterinsights_get_ua() ) {
602
			update_option( 'monsterinsights_frontend_tracking_notice_viewed', true );
603
604
			// If they are already tracking when they upgrade & not already marked mark connected time as now.
605
			// Adding this here again as 7.8.0 upgrade didn't run for all users.
606
			$over_time = get_option( 'monsterinsights_over_time', array() );
607
			if ( empty( $over_time['connected_date'] ) ) {
608
				$over_time['connected_date'] = time();
609
				update_option( 'monsterinsights_over_time', $over_time );
610
			}
611
		}
612
613
	}
614
}
615