Code Duplication    Length = 40-40 lines in 2 locations

class.jetpack-heartbeat.php 1 location

@@ 64-103 (lines=40) @@
61
	 * @since 2.3.3
62
	 * @global string $wp_version
63
	 */
64
	public function cron_exec() {
65
66
		$jetpack = Jetpack::init();
67
68
		/*
69
		 * This should run daily.  Figuring in for variances in
70
		 * WP_CRON, don't let it run more than every 23 hours at most.
71
		 *
72
		 * i.e. if it ran less than 23 hours ago, fail out.
73
		 */
74
		$last = (int) Jetpack_Options::get_option( 'last_heartbeat' );
75
		if ( $last && ( $last + DAY_IN_SECONDS - HOUR_IN_SECONDS > time() ) ) {
76
			return;
77
		}
78
79
		/*
80
		 * Check for an identity crisis
81
		 *
82
		 * If one exists:
83
		 * - Bump stat for ID crisis
84
		 * - Email site admin about potential ID crisis
85
		 */
86
87
		// Coming Soon!
88
89
		foreach ( self::generate_stats_array( 'v2-' ) as $key => $value ) {
90
			$jetpack->stat( $key, $value );
91
		}
92
93
		Jetpack_Options::update_option( 'last_heartbeat', time() );
94
95
		$jetpack->do_stats( 'server_side' );
96
97
		/**
98
		 * Fires when we synchronize all registered options on heartbeat.
99
		 *
100
		 * @since 3.3.0
101
		 */
102
		do_action( 'jetpack_heartbeat' );
103
	}
104
105
	/**
106
	 * Generates heartbeat stats data.

packages/heartbeat/src/class-heartbeat.php 1 location

@@ 78-117 (lines=40) @@
75
	 * @since 2.3.3
76
	 * @global string $wp_version
77
	 */
78
	public function cron_exec() {
79
80
		$a8c_mc_stats = new A8c_Mc_Stats();
81
82
		/*
83
		 * This should run daily.  Figuring in for variances in
84
		 * WP_CRON, don't let it run more than every 23 hours at most.
85
		 *
86
		 * i.e. if it ran less than 23 hours ago, fail out.
87
		 */
88
		$last = (int) \Jetpack_Options::get_option( 'last_heartbeat' );
89
		if ( $last && ( $last + DAY_IN_SECONDS - HOUR_IN_SECONDS > time() ) ) {
90
			return;
91
		}
92
93
		/*
94
		 * Check for an identity crisis
95
		 *
96
		 * If one exists:
97
		 * - Bump stat for ID crisis
98
		 * - Email site admin about potential ID crisis
99
		 */
100
101
		// Coming Soon!
102
103
		foreach ( self::generate_stats_array( 'v2-' ) as $key => $value ) {
104
			$a8c_mc_stats->add( $key, $value );
105
		}
106
107
		\Jetpack_Options::update_option( 'last_heartbeat', time() );
108
109
		$a8c_mc_stats->do_server_side_stats();
110
111
		/**
112
		 * Fires when we synchronize all registered options on heartbeat.
113
		 *
114
		 * @since 3.3.0
115
		 */
116
		do_action( 'jetpack_heartbeat' );
117
	}
118
119
	/**
120
	 * Generates heartbeat stats data.