woocommerce / woocommerce-product-tables-feature-plugin

Implements new data-stores and moves product data into custom tables, with a new, normalised data structure.
GNU General Public License v3.0
192 stars 32 forks source link

Should we keep the download limit and download expiration change? #89

Closed rodrigoprimo closed 6 years ago

rodrigoprimo commented 6 years ago

WC core lets users set download limit and download expiration per product. When we designed the custom product tables schema, we decided to change that and let users set download limit and download expiration per file. I think that this is a nice feature to add to WC, but I'm not sure if we should have added it to this plugin before adding it to WC core.

The main problem with supporting download limit and download expiration per file in this plugin and not in WC core is that they can't share the same product API. For example, what should $product->get_download_limit() return if each product file can now have a different download limit? IMHO, if we keep this change, it will force us to keep two different versions of all the code that touches product downloads. It will also make it harder for anyone that wants to use this plugin (they will have to update code that uses product downloads and make sure that the extensions that they are using are compatible with this plugin).

There are four WC core unit tests that are failing because of the download limit and download expiration change:

Those failing tests illustrate some of the challenges that we will have to address if we decide to keep download limit and download expiration per file.

I suggest that we remove this change from the plugin for now and reintroduce it only after it is introduced to WC core (probably only in WC 4.0 as it is a breaking change). @kloon mentioned that the original idea when this was added to the plugin was to add it first to WC core anyway.

I'm opening this issue to ask for input from others and to continue the conversation we started earlier today before we make a decision. @claudiosanches mentioned that he thinks we should simply hide the new interface in the product edit page and keep the new data structure. Claudio, could you please elaborate on how that would work and why do you prefer this approach over waiting until WC core implements this feature to add it to this plugin?

kloon commented 6 years ago

Been thinking about this and agree we should rather add this to core first. On that I have thought about the blocker namely $product->get_download_limit() and what if we return an array of id=>value pairs if the product has different limits for each individual file.

Yes there is still potential to break, but ultimately a good developed plugin should be checking for an integer anyway, and with this change can just introduce an array check?

claudiosanches commented 6 years ago

My idea it's simple, we don't include that new interface anymore and we should handle the posted data almost like before, we get all _download_limit and _download_expiry from $_POST in admin and include it into wc_product_downloads database instead of use metadata or include new fields for it into wc_products database.

This is very easy to handle, we can keep using set_download_limit and set_download_expiry to set it for all downloads at the same time.

In summary: we'll only keep the wc_product_downloads structure, but all things will be like before.

And why? At least having the database set for all downloads, should be easy to migrate in the future. But do what you folks think that is best for it, I don't want to fight to keep this, or say where is the best place to break compatibility. But compatibility will break unless we never implement this feature.

rodrigoprimo commented 6 years ago

Thanks for your input, @kloon and @claudiosanches. Claudio, thanks as well for clarifying your idea.

Balancing avoiding breaking changes and easiness to implement given the advanced stage of this plugin development, I'm inclined to agree that simply removing the interface to set download limit and download expiration per file is the way to go. I just have two remaining concerns:

Thoughts? Maybe I'm worrying too much about issues that might happen only to a limit number of users?

rodrigoprimo commented 6 years ago

As I'm still unsure about this and worried that keeping this change might present some issues that we still have considered besides the two issues that I mentioned above, I created #91 which removes download limit and download expiry per file and creates two new fields to store this information in the wp_wc_products table. I decided to do this to see how complex it would be to implement this change and it was pretty straightforward. In my opinion, merging #91 is the best option we have now. We can revisit this idea later (I suggest after this change is done in core), but I don't oppose to closing the PR without merging it in case we decide to keep download limit and download expiry per file.

rodrigoprimo commented 6 years ago

See https://github.com/woocommerce/woocommerce-product-tables-feature-plugin/pull/91#issuecomment-384764927