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

API Throw deprecation warnings for bad configuration #10702

Conversation

GuySartorelli
Copy link
Member

@michalkleiner
Copy link
Contributor

michalkleiner commented Feb 23, 2023

With the number of items we want to alert people to and the potential to have more of them in the future, do we want to create a new final class where these would be homed and just call it from wherever needed?
Or any other place other than inside the HTTPApplication class, it just doesn't feel right here.

Comment on lines 55 to 57
Deprecation::withNoReplacement(function () {
Deprecation::notice('4.12.0', 'Will be replaced with symfony/mailer', Deprecation::SCOPE_CLASS);
});
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 figure this is the appropriate message rather than "Will be removed without equivalent functionality" because symfony/mailer comes with a suported sendmail DSN config out of the box: sendmail://default

Copy link
Member

Choose a reason for hiding this comment

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

Just realised this is for MailTransport - yeah no replacement here, there is no mail() support in symfony/mailer

Message should be along the lines of "There is no mail() in CMS 5, use sendmail or SMTP instead"

Copy link
Member

Choose a reason for hiding this comment

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

Should probably put the same deprecation notices in the MailInvoker + SimpleMailInvoker __construct() as well

Copy link
Member Author

@GuySartorelli GuySartorelli Feb 28, 2023

Choose a reason for hiding this comment

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

Ooohhh, I thought this was for sendmail, didn't realise it was for mail().
Updated messages.


if (!$hasDeprecatedStrategy && method_exists($protectedResolutionStrat, 'getResolutionFileIDHelpers')) {
foreach ($protectedResolutionStrat->getResolutionFileIDHelpers() as $helper) {
if ($helper instanceof NaturalFileIDHelper) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't just check for !($helper instanceof HashFileIDHelper) here because that will raise deprecation warnings for people doing their own crazy magic and having their own custom file resolution strategies. We're pretty much just trying to catch people who started a new project before 4.5 when installer first slapped in the new strategy config override.

src/Control/HTTPApplication.php Outdated Show resolved Hide resolved
@GuySartorelli
Copy link
Member Author

With the number of items we want to alert people to and the potential to have more of them in the future, do we want to create a new final class where these would be homed and just call it from wherever needed?

I expect this method to just be thrown away when we merge up to 5.0, since at that point this behaviour should all be removed and there's no sense having the method around doing a no-op. And I can't think of any reason we'd need to call it from anywhere else - the whole point of putting it here is that we know it's only going to be called the one time for each request. We don't want duplicate deprecation warnings.

@GuySartorelli GuySartorelli force-pushed the pulls/4/deprecated-misconfigurations branch from 0817fcc to 6ec8820 Compare February 23, 2023 23:47
@michalkleiner
Copy link
Contributor

I expect this method to just be thrown away when we merge up to 5.0, since at that point this behaviour should all be removed and there's no sense having the method around doing a no-op.

And when CMS6 comes by, we will be reintroducing something similar and end up with something different again. I know CMS6 is relatively far, but at the same time it's not, it will fly by faster than we think.
I'm just thinking since you find a good place where to call it from and how to handle these things, the mechanism is worth preserving I'd say.

And I can't think of any reason we'd need to call it from anywhere else - the whole point of putting it here is that we know it's only going to be called the one time for each request. We don't want duplicate deprecation warnings.

The point where it's called from is fine.

@GuySartorelli
Copy link
Member Author

GuySartorelli commented Feb 23, 2023

And when CMS6 comes by, we will be reintroducing something similar and end up with something different again

I honestly don't see that as a problem. Two years from now we might not even remember this mechanism is here, and we risk having dead code and doing the same thing in a different way anyway. That said, if you still think this is worth keeping, I'll add a "Do not remove this method even if it's doing a no-op" to the phpdoc for it and update our docs about how to add deprecation notices in hopes we look there come CMS 6.

Edit: Actually with the change to docs it seems likely we will reuse this and the more I think about it the more you're right. I'll do that.

@GuySartorelli GuySartorelli force-pushed the pulls/4/deprecated-misconfigurations branch 2 times, most recently from b464ff0 to e01670f Compare February 24, 2023 00:03
@michalkleiner
Copy link
Contributor

Appreciate the reflection on this 👍. Could possibly add a note to the Deprecation class itself that this warning mechanism exists so we have one more place to remind us of it.

@GuySartorelli GuySartorelli force-pushed the pulls/4/deprecated-misconfigurations branch from e01670f to 0c07750 Compare February 24, 2023 00:07
@GuySartorelli
Copy link
Member Author

Could possibly add a note to the Deprecation class itself that this warning mechanism exists so we have one more place to remind us of it.

I've opted to instead link to the docs about deprecation notices in general, which is where I'll mention the mechanism. Link to the docs seems more useful overall I think.

I've also updated that class's phpdoc quite a bit since it was very out of date.


// This change of defaults has no other deprecation notice being emitted currently.
$project = new Module(BASE_PATH, BASE_PATH);
if (RESOURCES_DIR !== '_resources' && $project->getResourcesDir() !== RESOURCES_DIR) {
Copy link
Member

Choose a reason for hiding this comment

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

This is confusing me. The PUBLIC_DIR if statement above uses || which is intuitive. However the if statement for RESOURCES_DIR uses && which is not intuitive.

Copy link
Member

@emteknetnz emteknetnz Feb 27, 2023

Choose a reason for hiding this comment

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

Also the logic in Module::getResourcesDir() is

        return isset($this->composerData['extra']['resources-dir'])
            ? $this->composerData['extra']['resources-dir']
            : '';

So, are we deprecating NOT specifying what the resources-dir is in composer.json? Just having a quick look at a composer.json for a cms 5 install I have locally and I don't have it specified here and everything works normally.

Seems like we should be doing the opposite and simply not care what's in composer.json, cos it'll always be _resources going forward?

Copy link
Member Author

Choose a reason for hiding this comment

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

The PUBLIC_DIR if statement above uses || which is intuitive. However the if statement for RESOURCES_DIR uses && which is not intuitive.

These conditions are doing two different things.

if (PUBLIC_DIR !== 'public' || Director::publicDir() !== PUBLIC_DIR) {

If PUBLIC_DIR isn't public, we have a problem. If Director::publicDir() is giving a value other than PUBLIC_DIR, we have a problem.

if (RESOURCES_DIR !== '_resources' && $project->getResourcesDir() !== RESOURCES_DIR) {

RESOURCES_DIR is allowed to be "_resources", and $project->getResourcesDir() is allowed to not match RESOURCES_DIR (e.g. if not set) - but if RESOURCES_DIR isn't "_resources" then $project->getResourcesDir() must match that value. If it doesn't, it means they're probably using the old default value and haven't explicitly declared they want to keep it.

Copy link
Member Author

@GuySartorelli GuySartorelli Feb 27, 2023

Choose a reason for hiding this comment

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

So, are we deprecating NOT specifying what the resources-dir is in composer.json?

Only if they're using something other than the default, but yes.

Copy link
Member

Choose a reason for hiding this comment

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

RESOURCES_DIR gets set in constants.php, where it'll read composer.json resources-dir or default to resources (CMS 4) or _resources (CMS 5)

Maybe I'm reading this wrong, though maybe all we need here is

if ($project->getResourcesDir() === '')

Meaning you haven't specified it in composer.json and are still using the old 'resources' default? But is that actually a problem? If you don't specify it in CMS 5 and it'll nicely use the _resources default.

So, people will be upgrading from 4.13 to 5.0.0, they turn on deprecation notices, and we then asking people to specifying resources-dir ... only to then not require it in CMS 5?

What happens when you upgrade from CMS 4 -> CMS 5 and you haven't specified resources-dir in composer.json? Does the old resources dir get nuked and a new _resources dir get populated?

I have some feeling that not specifying _resources in composer.json causes them to break right now anyway

I'm not sure we need this deprecation warning here? Maybe we need to split this off to another card here to explore this further?

Copy link
Contributor

Choose a reason for hiding this comment

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

It was a reaction to Steve's "the message ... needs to tell users they need to set the value..." where it seemed to me that suggesting resources could be there to reduce upgrade pain.

Offer its configurability via composer.json, suggest _resources, and discourage resources (if needs to be mentioned at all).

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 think the simplified if ($project->getResourcesDir() === '') has much better intent

I disagree, but it's really not worth holding up the PR for this so I've made the change.

The message in the Deprecation::notice() needs to be changed tell users that they need to set this value in composer.json, preferably to _resources, but realistically resources to reduce upgrade pain?

I don't think it does. It includes a link to the changelog, which is the source of truth for whatever advice we want to give about how to handle this scenario. If you think the information in the changelog is insufficient please note what specific changes should be made in the changelog (note it in the issue since you've already merged the docs PR) and I'll update the changelog.

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah I remember the "pages named resources" thing from years ago. Yeah, really bad to have it called 'resources' because it's a common name for a page, would be ideal if anyone still on that migrated off that.

we shouldn't exercise the option of coming back to resources

Yeah that would be great, should just force it to be _resources and that's it, but probably too late now that we're in the beta.

The changelog is a bit confusing in this context because they're on a 4.13 project, but the changelog is for 5.0.0. In 4.13 we ideally want them to add "_resources" to their composer.json, though in the 5.0.0 changelog we say "If your composer.json file has its extra.resources-dir key set to _resources, you can remove that now." ... so that's confusing

I'd like to just make the message be "add _resources to your composer.json now" - but I've got no idea what happens when you do that - we probably should split this off as a new card to investigate the amount of friction there is around the resources folder

Copy link
Member Author

@GuySartorelli GuySartorelli Feb 28, 2023

Choose a reason for hiding this comment

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

we probably should split this off as a new card to investigate the amount of friction there is around the resources folder

Whether the readme needs to be updated or further investigation is required as a separate card, that should not hold up this PR.

Copy link
Member

@emteknetnz emteknetnz Feb 28, 2023

Choose a reason for hiding this comment

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

Yeah I'll raise a card to investigate further, keep as is for now

#10710

@GuySartorelli GuySartorelli force-pushed the pulls/4/deprecated-misconfigurations branch from 7903c88 to 60f1457 Compare February 28, 2023 03:26
Comment on lines 55 to 57
Deprecation::withNoReplacement(function () {
Deprecation::notice('4.12.0', 'Will be replaced with symfony/mailer', Deprecation::SCOPE_CLASS);
});
Copy link
Member

Choose a reason for hiding this comment

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

Just realised this is for MailTransport - yeah no replacement here, there is no mail() support in symfony/mailer

Message should be along the lines of "There is no mail() in CMS 5, use sendmail or SMTP instead"

@emteknetnz emteknetnz merged commit 5295ba6 into silverstripe:4 Feb 28, 2023
@emteknetnz emteknetnz deleted the pulls/4/deprecated-misconfigurations branch February 28, 2023 22:36
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.

3 participants