Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move CustomVariables::getNumUsableCustomVariables logic to DI so tests do not need to access database #8806

Closed
wants to merge 4 commits into from

Conversation

diosmosis
Copy link
Member

This PR creates a new class, CustomVariablesMetadataProvider, which contains the main logic for CustomVariables::getNumUsableCustomVariables. A mock class is defined and used by AutoSuggestAPITest so API.getSegmentsMetadata can be used in the data provider instead of having to define them manually.

Additional changes in this PR:

  • Removed Piwik\Tracker\Cache::$cache. Since the Cache instance comes from DI, we don't need the static variable anymore.
  • Moved CustomVariables\Model instances to DI (one per 'scope').

Fixes #8756

@diosmosis diosmosis added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Needs Review PRs that need a code review labels Sep 17, 2015
@diosmosis diosmosis added this to the 2.15.0 milestone Sep 17, 2015
diosmosis added 2 commits September 16, 2015 17:04
…opes(). Move getNumUsableCustomVariables logic to CustomVariablesMetadataProvider (new service class in DI).
diosmosis added 2 commits September 16, 2015 17:05
…tom variable segments do not have to be added manually when getting all segments.
@diosmosis
Copy link
Member Author

Cannot merge w/o refactoring the tracker cache. Moving to 3.0.

@diosmosis diosmosis modified the milestones: 3.0.0, 2.15.0 Sep 21, 2015
'Piwik\Plugins\CustomVariables\Model.conversion' => DI\object('Piwik\Plugins\CustomVariables\Model')
->constructor(Model::SCOPE_CONVERSION),

'Piwik\Plugins\CustomVariables\Model.all' => array(
Copy link
Member

Choose a reason for hiding this comment

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

Is it really needed to have it in DI like this? I know it might be nice to inject it but looks a bit over engineered / complex to me. I don't think one would want to change any thing here, does one?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not about changing/extending the code (not always), it's about decoupling dependencies. Model is a dependency of CustomVariableMetadataProvider, so Model has to be in DI to inject it. If we don't do this everywhere there's application logic, we'll have to keep using StaticContainer in classes that aren't in DI, which will make embedding environments (important for cloud & tests) impossible to do completely.

The reason for the complexity here is due to the design of the Model class. Since it takes a scope as a constructor argument, we have to create multiple instances of it in DI. I can simplify it w/ some refactoring, just didn't want to w/ this PR. Of course, since the PR is broken, it's not as big a deal now.

@tsteur
Copy link
Member

tsteur commented Sep 21, 2015

There are some failing tests in https://travis-ci.org/piwik/piwik/jobs/80746350 . Is it related to this? Looks like it. Left a few comments but can be ignored I reckon

@diosmosis
Copy link
Member Author

There are some failing tests in https://travis-ci.org/piwik/piwik/jobs/80746350 . Is it related to this? Looks like it. Left a few comments but can be ignored I reckon

Yeah, that's why I moved it to 3.0. The tracker cache also accesses the database, so replacing this specific logic doesn't work completely.

@tsteur
Copy link
Member

tsteur commented Aug 30, 2016

I'll close this PR for now as it's not really needed right now and the PR would need to be made against 3.x-dev as a lot in Piwik 3 has changed also around custom variables etc. In master branch we only merge security fixes and critical bug fixes as it is in LTS mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants