Package Uninstall and Data Cleanup
PermalinkI have a question about how to handle certain data when uninstalling a package. I am in the process of writing a new package for a shipping type for the eCommerce add-on. Once installed, it is possible for the user to use this new shipping type in some of the core eCommerce components (for example the Free Shipping Discount). If I have set up a discount, but then choose to uninstall my shipping type package, the discount still references a shipping type that now no longer exists.
I know I can manually delete any discounts as part of the package uninstall, but I am wondering whether this is the best option. If it is, should my uninstall provide an alert to say that discounts have been deleted? Or, should my uninstall disable the discount and alert the user that this has been done and they should update the discount to choose a new shipping type? Or, do I do nothing (not sure this is the best option)?
I guess what I am asking is what is the best way to do this and still have a good user experience?
Would be interested in your thoughts.
James
Is there anyway to pop up an alert during the execution of my package controllers uninstall() method? At least then I could highlight to the user that I have deleted discounts (for example) as they were using the shipping type that has now been uninstalled
James
you _can_ stop the uninstall if records exist that use it though, just throw an exception after you do a check, I think I will add some package events,
on_before_package_install
on_package_install
on_before_package_update
on_package_update
on_before_package_uninstall
on_package_uninstall
Im sticking in the before's because I forsee the code being like this (pseudo code):
Events::fire('on_before_package_install', $pkg); $pkg = $pkg->install(); Events::fire('on_package_install', $pkg);
thoughts?
BTW, I like your idea of being able to intercept the process at various points.
James
(btw if you don't call parent::uninstall() then it won't preform any c5 uninstall methods)
That method populates $items, below is the code that you see in the dashboard.
foreach($items as $k => $itemArray) { if (count($itemArray) == 0) { continue; } ?> <h3><?=$text->unhandle($k)?></h3> <? foreach($itemArray as $item) { ?> <?=$pkg->getItemName($item)?><br/> <? } ?> <br/> <? } ?>
It might be nice if there was a way to plug into this uninstall page, even if it was just to show some plain text warning. In my case it would be good if I could show a message along the lines of...
"Warning: you are about to uninstall a shipping type that is still in use by enabled Free Shipping Discounts. Please modify these discounts and change the Shipping Method"
Also, in addition to just having events, there should be some way to provide messages or confirmations to users -- but this is probably a lot more work than just adding some event firings :)
$ret = Events::fire('on_package_uninstall', $pkg); if($ret) { throw new Exception $ret; }
basic example
I think ideally you would prevent the user from uninstalling the shipping type if any orders exist using it, but again there is no way currently to do this kind of prevention. So... I personally would just leave the data alone. If someone uninstalls the shipping type after orders exist using it, they're kind of screwed (from a data integrity point of view) one way or another, so why bother with extra effort?
Hopefully someone on the core team can chime in on this as I'd be very interested to hear their answer.