Closed (fixed)
Project:
Commerce License
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
14 Jul 2017 at 12:51 UTC
Updated:
17 Aug 2017 at 16:55 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
Kazanir commentedStart of a patch for this.
Comment #3
joachim commentedThese two should match. I would go with license_default, as Commerce uses 'order_default'.
I think it would be a good idea to add comments to describe some of these.
Eg, what's the difference between suspended and revoked? And what does pending signify?
Comment #4
bojanz commentedLet's use "new" instead of "created", it's what Commerce went with.
@joachim
Pending is for remote licenses that are awaiting activation (provisioning call in progress).
Comment #5
chrisrockwell commentedDoes this mean the
statusfield on the license entity goes away, becomes a 0|1, or should be varchar to mirror what state machine would hold?Comment #6
joachim commented> Does this mean the status field on the license entity goes away, becomes a 0|1, or should be varchar to mirror what state machine would hold?
Good point. I think that for now it should go away. Orders don't have a boolean status field, only their workflow state.
If we find that queries to get active licenses are slow, we can add it back in, but for now let's keep things simple :)
Off the top of my head, I think most queries to fetch licenses don't need to be particularly performant, as licenses get loaded in queue jobs when they need to activate or expire.
Comment #7
joachim commentedHere's a patch with the various changes from above, and also some docs for the pending state.
This just adds the workflow and the field -- making it do something I think is for over at #2879263: License creation/destruction logic in sync with cart/order lifecycle.
As it's had a few reviews already, I think this is RTBC, and tweaks can come in follow-ups.
Comment #8
joachim commentedWhoaaaa just spotted a few things to fix in this.
Comment #9
joachim commentedFurther changes:
- remove param from License::getWorkflowID()
- add getWorkflowID() to license interface
- remove unrelated addition of getType() to interface: filed #2898618: rename getType() and add it to LicenseInterface for this
- doc tweaks
Comment #10
joachim commentedGot a review from bojanz on IRC, made further fixes and tweaks:
- Fixed name of workflow
- remove transitions from pending to suspended and expire
- Added cancel state and transition for pending to go to
- rearranged transition code order in the yml file
- fixed license name in getWorkflowId
And I'm removing this, and filing a new feature request #2898654: add ability to license type plugin instances to specify a license workflow for it:
I figure we'll leave the getWorkflowId on the license type plugin base, as the code is there already.
Comment #11
joachim commentedGoing to commit this so I can keep going with other issues today...
Comment #13
jurgenhaasJust came across this while working on #2879276: Licensable order item types & fields and think that getWorkflowId can't be static while it has to access an instance of License when using $this. I've looked for other instances doing similar things and found this in the Order entity:
This is working without $this because the order is being passed along as a parameter. I don't know how this is achieved but something similar should be used here as well.
Comment #14
joachim commentedYou're quite right, getWorkflowId() is used as a callback on the field definition, given as a static callable.
I don't have the code in front of me right now, so not sure how we fix.
Is there a way we can specify this has to pass in the entity? Or maybe state_machine module passes it anyway?
Comment #15
jurgenhaasSomething similar to this is used by the entity types Order and also Payment. Both are taking an entity as their only parameter so I guess we can assume that it is passed along. Yes, looking into StateItem::loadWorkflow(), that is passing the entity forward.
So, we now need to determine how to find out the correct workflow ID. Is this the workflow ID from the order item type?
Comment #16
joachim commentedNo, it's the workflow that our license entity wants to use.
Where we had:
we just need to change $this to the given $license parameter.
Comment #17
jurgenhaasThere is more to it. Chaning it to
$license->getType()will then bring us into that getType() function which is also still unclear to me and according to #2898613: license type plugin instances are created with a license name passed in for $config, but nothing uses it we can remove that getType() function and handle everything inside of getWorkflowId().That leaves the question how to get the license type. As far as I understand it, the license type is a plugin from \Drupal\commerce_license\Plugin\Commerce\LicenseType, so it can either be role or file at this point. So when a license gets created, one of those types/plugins must be associated with the license. Is that the bundle()? If so, the attached patch should solve this issue.
Comment #18
jurgenhaasRe-rolled patch with dorgflow
Comment #19
joachim commentedThanks for the reroll! Patch format looks good now.
Just a few points:
We shouldn't be removing this here.
If getType() was something the previous patch on this issue had added, which we now felt wasn't needed, then fine.
But it was there before that patch, so removing it is out of this issue's scope.
I'm going to say that for now, we should assume it's needed for things we don't know about yet, so getWorkflowId() should call it. We can think about removing it later on, probably when we're at beta and the code is reasonably complete, and we can then see whether anything else does call it.
Let's change this to:
'Callback for the license state field's workflow_callback setting.'
The docs I wrote here are based on my incorrect understanding.
Comment #20
jurgenhaasRegarding 1: the getType function was introduced specifically for this, see #2898613: license type plugin instances are created with a license name passed in for $config, but nothing uses it which we closed in favour of this issue here as we realized that the two things relate to each other. I also cross checked and getType isn't used anywhere else and it hasn't been declared in the interface either such that nobody should even know about it. Of course, the git log shows that it really was only introduced a couple of days ago in this current context.
Regarding 2: will update, let's clarify your comment above first and then I re-roll the patch to address both topics.
Comment #21
joachim commented> the getType function was introduced specifically for this
gets me:
and:
gets me:
We introduced a call to getType(), but it was already there.
Comment #22
jurgenhaasAgreed, I brought it back and also renamed it and put it into the interface as suggested in #2898618: rename getType() and add it to LicenseInterface
Comment #23
joachim commentedI'm committing this patch which has the following:
- fix License::getWorkflowId to not access $this in static
- added $license param to LicenseInterface::getWorkflowId()
- added $license param to License::getWorkflowId()
- fixed docblock for LicenseInterface::getWorkflowId()
- added @see to docblock for LicenseInterface::getWorkflowId()
> Agreed, I brought it back and also renamed it and put it into the interface as suggested in #2898618: rename getType() and add it to LicenseInterface
The change to add it to the interface should be done as part of that other issue, not here. It's important to keep patches focussed on just the issue they are trying to fix, and not add in fixes that are unrelated. It helps a great deal when in the future we do the sort of git archaeology I did in comment #21.
Comment #25
jurgenhaasOK, that makes sense. I've submitted a patch separately in the other issue.
However, this introduced some small syntax issues in the interface and I've fixed them in the hopefully last patch:
This uses itself which isn't a great idea and phpcs complaints about it. At the same time I've also removed those that are no longer used:
Then, the following line has a missing leading backslash which phpcs doesn't like either:
That's corrected too.
Comment #26
joachim commentedAh whoops!
Could you file a new issue for that please, as part of that is general cleanup?
Comment #27
jurgenhaasOK, moved to #2899717: Code cleanup