Updater::migrate_zoom_account( TribeEventsVirtualMeetingsZoomApi $api, string $refresh_token )

Migrate the Zoom Account.


Parameters

$api

(TribeEventsVirtualMeetingsZoomApi) (Required) An instance of the API class.

$refresh_token

(string) (Required) The refresh token from the connection before multiple accounts.


Top ↑

Return

(boolean) whether the migration to multiple accounts is complete.


Top ↑

Source

File: src/Tribe/Updater.php

	public function migrate_zoom_account( $api, $refresh_token ) {
		$refreshed = false;
		$api->post(
			OAuth::$token_request_url,
			[
				'body'    => [
					'grant_type'    => 'refresh_token',
					'refresh_token' => $refresh_token,
				],
			],
			200
		)->then(
			function ( array $response ) use ( &$api, &$refreshed ) {

				if (
					! (
						isset( $response['body'] )
						&& false !== ( $body = json_decode( $response['body'], true ) )
						&& isset( $body['access_token'], $body['refresh_token'], $body['expires_in'] )
					)
				) {
					do_action( 'tribe_log', 'error', __CLASS__, [
						'action'   => __METHOD__,
						'message'  => 'Zoom account migration could not be completed, please manually add your account on the Settings/API section.',
						'response' => $body,
					] );

					return false;
				}

				$refreshed = $api->save_account( $response );

				// Clear existing account settings.
				tribe_update_option( Settings::$option_prefix . 'refresh_token', '' );
				delete_transient( Settings::$option_prefix . 'access_token' );

				// Save the original account id to use to update existing events as they are viewed in the admin.
				$user = $api->fetch_user( 'me', false, $refreshed );
				if ( empty( $user['id'] ) ) {
					return $refreshed;
				}
				tribe_update_option( Settings::$option_prefix . 'original_account', esc_attr( $user['id'] ) );

				return $refreshed;
			}
		);

		return $refreshed;
	}

Top ↑

Changelog

Changelog
Version Description
1.5.0 Introduced.