-
Notifications
You must be signed in to change notification settings - Fork 29
[WIP] Support for handling defunct routes #81
[WIP] Support for handling defunct routes #81
Conversation
- How to correctly transfer the children of a PHPCR-ODM defunct auto route to the new route?
quite alot of refacvtoring. Renamed The defunct route handler stuff is now plumbed into the ServierRegistry and DI compiler pass. We need to change from URL to URI. WIP. |
The remove defunct route functionality works now. I have introduced phpspec ... |
* | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
class DelegatingDefunctRouteHandler implements DefunctRouteHandlerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the AutoRouteManager
accepts one DefunctRouteHandler
, this one will use delegate to handlers registered with the ServiceRegistry
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContext; | ||
use Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface; | ||
|
||
class UrlContextStackSpec extends ObjectBehavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First spec .. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 (although we should change all PHPunit tests to PHPspec)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok with that in theory -- but is what would be the best way to do:
public function providesFoobar()
{
return array(
array('...', '...';, '...'),
array('...', '...';, '...'),
);
}
/**
* @dataProvider provideFoobar
*/
public function foobar($a, $b, $c)
{
}
Then again, I don;t really care if we have the two at the same time. At least for the time being.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought that might be the case. That kinda sucks.
ok this is getting there. todo:
|
I have run into a wall with PHPCR-ODM. At the moment I am removing routes in the ODM listener in the post-flush event. This works, but if I want to leave a redirect route this becomes awkward, and it is the wrong way to do things - and other implementations would not do things in this order. The best way to handle all of this is during the flush -- but PHPCR-ODM does not support deleting a route and then creating a new route in its place (i.e. replacing a route).because of the sequence of operations: doctrine/phpcr-odm#396 There is also the issue with At this point I could bypass the ODM completely and create the objects with the ODM mappings directly with PHPCR - or stop doing RoutingAuto and invest the time instead into PHPCR-ODM. Hm. Seems a shame as this PR is so close to being finished. |
Yeah it is very tricky .. we tried to do a replace for the ODM and always got stuck some where and ended up saying for now it just requires a 2 step flush. |
i would really do it in two steps for now. that way we have the feature, and if its used a lot and the double flushes are really a performance issue, we can go and try to improve the odm (i guess it always goes down to the operations queue). for the referrers, i just commented on 464 - i see no way we could provide that reliably but performant. |
I could somehow support firing a "handle defunct routes" event before and after the flush, enabling different implementations (adapters) to handle things at different times. Handling it 100% in PHPCR still holds some appeal, as I think it could be done safely before the flush - the only problem would be converting the Document to a Node without duplicating too much logic from the UOW. |
i think events would be a nice thing here. i can imagine people need the phpcr handling will not solve the referrers issue. but for changing |
The PHPCR thing would solve the referrers issue, as we would save after creating the route (assuming the x Session doesn't support non-persisted referrers). Migration might be an option, but it really doesn't make any difference if we do a two step thing here, as we would delete in the flush, and create in the post flush, avoiding the order of operations problem. |
but if you need to flush, why not then use the dm then? operating on phpcr directly will make it much harder if somebody works with custom documents. |
If I save the session with PHPCR I only persist the changes for the Nodes that I have modified (because the DM will only persist to the PHPCR session when executing the flush, so the Phpcr "uow" is empty). But if I flush the DM prematurely that could cause problems and edge cases. Hmm, for the custom documents we would need to map the document to PHPCR, in which case it would be nice to refactor the UOW to use a document => node mapper of some sort that I could steal. But basically I would be encapsulating a big hack. Will try and implement the extra flush first anyway. |
$defunctRouteHandlerLength = $defunctRouteHandlerNodes->length; | ||
|
||
if (1 < $defunctRouteHandlerLength) { | ||
throw new \InvalidArgumentException(sprintf('There can only be one defunct route handler per mapping, %d given for "%s" in ""%s', $defunctRouteHandlerLength, $className, $path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wouterj why do we check this here when the loader validates the XML with a schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, this is indeed not needed. However, the current XML schema defines "unbounded" as maxOccurs for the <defunct-route-handler>
element. This should be updated to 1
if we don't support more than 1 per mapping.
$metadata = $this->metadataFactory->getMetadataForClass($realClassName); | ||
|
||
list($name, $options) = $metadata->getDefunctRouteHandler(); | ||
$defunctHandler = $this->serviceRegistry->getDefunctRouteHandler($name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wouterj this is always array('remove', array())
when we have configured: array('leave_direct', array())
. The class metadata is populated with leave_redirect
, but for some reason it gets reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, added Am planning to go full |
ok getting there. the next push should see the LeaveReditrectHandler in a working state then we can merge this and look to getting something in |
But needs an additional flush
LeaveRedirect now works, but it requires an additional Flush. I am not really too keen on using the I wonder if there is any scope for adding some sort of re-flush stack? So that listeners can add new flushes easily? Or is the idea generally that re-flushing is bad? (but in this case unavoidable). |
$this->getDm()->flush(); | ||
|
||
// additional flush -- maybe we should handle this with an event listener of some sort? | ||
$this->getDm()->flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional flush to flush the new Redirect Routes..
@wouterj if its OK with you I want to get this thing finished - the new version has feature parity now I believe - there is still an open issue about how to persist the new RedirectRoutes (doctrine/phpcr-odm#481) but as this is an additional feature, I don't think it should be a blocker. As for behat and phpspec -- lets just stick with PHPUnit for now - I will revert my phpspec's to phpunit. I really want to get this finished so I can concentrate on other stuff :) So basically I will try and get all this in master soon-ish and update the documentation and tutorials. |
@dantleech feel free to merge this PR when it's finished. I want to do one big fix commit fixing CS etc. after it and then I'm ok with merging it into master. We can still improve things (like behat & phpspec) on the master branch. |
hmm .. I am also torn between if we should carry on using PHPUnit or switch to PHPSpec - it doesn't make much sense to have them both, and PHPSpec is alot quicker to work with, whilst PHPUnit is more mature. |
@wouterj We should merge this now. The persisting of new redirect routes currnetly depends upon a non-existing ODM event (trying to get it added to the ORM before adding it to the ODM: doctrine/orm#1022 (comment)). If that doesn't work we can maybe do a temporary hack with the kernel/console terminate events. Also there is a single failing Mapping test realted to merging, which I wasn't sure about. So in summary, there should be about 2 failing tests, one mapping and one for redirects. I am only temporarily online now, could you merge if it looks ok? |
[WIP] Support for handling defunct routes
No description provided.