Skip to content

Conversation

@roccotripaldi
Copy link
Contributor

@roccotripaldi roccotripaldi commented Jun 3, 2019

The Connection_Manager is_active will replace Jetpack::is_active
I'm not yet going through the code base to remove usage, but instead throwing a deprecated notice.

is_active was dependent on Jetpack_Data::get_access_token()
I've also deprectated that method and started removing usages.
There remains some to remove, I'd ideally like to remove class.jetpack-data.php altogether.

To test:
Ensure you can still connect / disconnect a site.

@roccotripaldi roccotripaldi added Connect Flow Connection banners, buttons, ... [Focus] Jetpack DNA labels Jun 3, 2019
@roccotripaldi roccotripaldi requested review from a team June 3, 2019 20:04
@jetpackbot
Copy link
Collaborator

jetpackbot commented Jun 3, 2019

Warnings
⚠️

The PR is missing at least one [Status] label. Suggestions: [Status] In Progress, [Status] Needs Review

⚠️ "Testing instructions" are missing for this PR. Please add some
⚠️ "Proposed changelog entry" is missing for this PR. Please include any meaningful changes

This is an automated check which relies on PULL_REQUEST_TEMPLATE. We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

Generated by 🚫 dangerJS against 4d62cdb

$media_keys = array_keys( $_FILES['media'] );

$token = Jetpack_Data::get_access_token( get_current_user_id() );
$token = self::init()->connection_manager->get_access_token( get_current_user_id() );
Copy link
Contributor

@gravityrail gravityrail Jun 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels pretty noisy, both in terms of the self::init() part, and the length of the connection_manager prop, and the fact that the prop is accessed as a var rather than through a method.

What about something like:

self::connection()->get_access_token( get_current_user_id() );

and elsewhere:

static function connection() {
  // maybe memoize this?
  self::init();
  return new Connection_Manager();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then anywhere else in the code we like, we can call Jetpack::connection() to get a connection manager instance, at least as shorthand unless the alternative is necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, a static entry point for connections:

// in a package file, e.g. Automattic/Jetpack/Connection.php
namespace Automattic\Jetpack;
use \Automattic\Jetpack\Connection\Manager as Connection_Manager;

function Connection() {
  return new Connection_Manager();
}

class Connection {
// dummy class?
}
// this acts as a handy singleton in other places, and doesn't need a constructor, but 
// unfortunately can't be aliased or imported, so requires a dummy class in the same file
$token = Connection()->get_access_token( $user_id );

Copy link
Contributor

@gravityrail gravityrail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty close...

Copy link
Contributor

@gravityrail gravityrail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to switch status to approve as these cleanups can be made in another PR.

@roccotripaldi if you feel my suggestions are worth exploring, either backlog a ticket or open anothre PR after this one is merged.

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work on this one 👍

@@ -1,5 +1,7 @@
<?php //phpcs:ignore

use \Automattic\Jetpack\Connection\Manager as Connection_Manager;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the leading slash? I'd suggest removing it.

"version": "1.0.0",
"require": {},
"require": {
"automattic/jetpack-options": "^1.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dev here as well?

$possible_normal_tokens[] = $stored_blog_token;
}

$defined_tokens = \Jetpack_Constants::is_defined( 'JETPACK_BLOG_TOKEN' )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be consuming Jetpack_Constants from the constants package instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are! It's class mapped!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, yeah, you're right! Yeah, seems like we need to land #12558 to make this more obvious 😉

@@ -1,5 +1,7 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we also planning to fix the tests before landing this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!

@roccotripaldi
Copy link
Contributor Author

idk - this was a bad idea. will try an other approach

@kraftbj kraftbj deleted the add/is-active-to-connection-package branch January 4, 2021 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Connect Flow Connection banners, buttons, ... [Focus] Jetpack DNA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants