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

Changes to support custom periods #11837

Merged
merged 4 commits into from Sep 11, 2017
Merged

Changes to support custom periods #11837

merged 4 commits into from Sep 11, 2017

Conversation

diosmosis
Copy link
Member

This PR contains the following changes which allow defining & handling custom period types.

Changes

  • Add the ArchiveQueryFactory class & ArchiveQuery interface so plugins can intercept Archive instance creation.
  • Add the CustomPeriodFactory interface to handle creating new period instances.
  • Make period responsible for determining start/end time of periods so aggregation is not limited to days w/o times.
  • Allow specifying a custom archive writer in PluginsArchiver.

Notes

  • This PR should be reviewed for any potential BC breaks. Don't think there are any, but I may have missed something.
  • This PR can be reviewed commit by commit.

core/Date.php Outdated
*/
public function getDateStartUTC()
public function startOfDay()
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 prefix with get?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, keeps it consistent

@@ -55,6 +56,17 @@ public static function build($period, $date, $timezone = 'UTC')
return new Year($date);
break;
}

$customPeriodFactories = StaticContainer::get('period.custom.factories');
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could name it like just periods or so and then move all hard coded ones out of here into the config?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about that, but I think would be broken if a plugin accidentally removed the ability to create one of those periods, so I thought it would be better to hard code those, to make sure they are always available. (For example would it make sense to ever remove the day period?) What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it would make sense to ever remove a day period. Would move it to eg CoreHome plugin so it cannot be disabled. The advantage is that we would notice if something breaks in the code for "custom periods" as the "core" is using it itself and be good to have them as examples in a plugin.

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 could still be removed if a plugin sets it to an empty array or uses DI\decorate to remove it. That said it would be hard for a plugin developer to not notice if they removed it, so perhaps it's not really an issue. I'll put them in CoreHome, seems like the better path.

@tsteur
Copy link
Member

tsteur commented Jul 4, 2017

Left 2 comments, otherwise looks good 👍

@diosmosis
Copy link
Member Author

@tsteur made some changes including using Plugin\Manager::findComponents instead of DI for the period factory. I think it deserves another review.

@diosmosis
Copy link
Member Author

Looking at the unit test failures, I'm not sure if it's a good idea to make Period\Factory::build dependent on plugins for every period type. For example, the AddSegmentByLabelInUTC filter uses it, and will thus become dependent on plugins being loaded to work (which breaks unit tests that use it).

I think ideally, the build function shouldn't be called as much as it is. Since it only creates a period instance from query parameters, I think it should ideally only be called at the beginning of a request. This would be a very large change to make, though.

I see three options to solve this (please suggest others if I'm missing something):

  1. Keep the periods in CoreHome & change the unit tests to use the loaded plugins (via the deprecated UnitTestCase or making them integration tests).
  2. Go back to creating core periods in Period\Factory::build w/ a test to ensure core knows if the custom period factory code breaks. This way plugins are only required to be loaded if a custom period is requested.
  3. Modify Piwik so only the code that executes controller/API methods needs to call it (everything else uses a period).

@tsteur
Copy link
Member

tsteur commented Jul 9, 2017

Good points. I'd probably go back to 2) like you had it before (core periods in core and not in plugin).

Didn't think of tests. If we decided to keep it in CoreHome, would need to make them integration tests.

@diosmosis
Copy link
Member Author

@tsteur ready for another review.

@mattab mattab added this to the 3.1.0 milestone Aug 3, 2017
@tsteur
Copy link
Member

tsteur commented Aug 13, 2017

Sorry for late review @diosmosis
looks all good to me

@diosmosis
Copy link
Member Author

No worries @tsteur, will probably be a bit before it gets merged anyway :)

@mattab mattab merged commit f0ddb70 into matomo-org:3.x-dev Sep 11, 2017
@diosmosis diosmosis deleted the archive-query-factory branch September 11, 2017 17:42
@mattab mattab modified the milestones: 3.2.0, 3.1.1 Sep 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants