Skip to content

Generic multi-apptype support, for #535 - #574

Merged
rfay merged 11 commits into
ddev:masterfrom
rfay:20171212_multi_cms_experiments
Dec 27, 2017
Merged

rfay merged 11 commits into
ddev:masterfrom
rfay:20171212_multi_cms_experiments

Conversation

@rfay

@rfay rfay commented Dec 13, 2017 •

Copy link
Copy Markdown
Member

The Problem/Issue/Bug:

We have code scattered all over that does if Drupal7 else if Drupal8 etc. We have to standardize the approach so it's easy to fully support an arbitrary apptype.

How this PR Solves The Problem:

The fundamental approach is in pkg/ddevapp/apptypes.go: A map of apptype->struct-with-funcs is provided, and that routes all custom actions to appropriate actions for the given apptype. Then generic routing functions are used to route through it.

All pkg/cms/* move into pkg/ddevapp as well.

Manual Testing Instructions:

All ddev functionality should work unchanged.

Automated Testing Overview:

  • Many tests have been altered to match new signatures and approaches
  • The drupal and wordpress settings tests have been consolidated and now use the new master functions via apptype index.

Related Issue Link(s):

OP #535

Release/Deployment notes:

There are a number of followup PRs for this, but I think it's important to get this in. Followups include:

  • Add detector function by apptype so detection can easily be in isolated code (thanks @cweagans ) Make the apptype detection a suggestion instead of just going with it.
  • Add post-import warning function (currently only for wordpress, but better than inline code)
  • Test review. We should be accessing per-CMS functionality via the functions in apptypes.go
  • Backdrop support
  • Typo3 support
  • New ddev commands to create settings file (and/or delete it?) - We've talked about the import-db not explicitly doing the creation, or alternately continuing to do it but also adding an explicit settings creator command to ddev.

@rfay rfay self-assigned this Dec 13, 2017
@rfay
rfay force-pushed the 20171212_multi_cms_experiments branch from d486854 to a0952ca Compare December 14, 2017 23:09
Comment thread pkg/ddevapp/apptypes.go

// AppTypeFuncs struct defines the functions that can be called (if populated)
// for a given appType.
type AppTypeFuncs struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would be in favor of adding a detect member here. That way, each app type would define logic for how to detect that type of app, so app type detection becomes a matter of looping through AppTypeMatrix and calling the detect() function for each one. The only downside here is that php could be detected for any more-specific PHP applications, so I guess php would just need to be the last item in AppTypeMatrix?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I like it. I was thinking of a single detector, but this may be a better approach.

Comment thread pkg/ddevapp/apptypes.go Outdated
// for each apptype (CMS).
// Example: AppTypeMatrix["drupal"]["7"] == { settingsCreator etc }
var AppTypeMatrix = map[string]AppTypeFuncs{
"php": AppTypeFuncs{},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For normal PHP applications, since we're not writing a settings file, where would a user look in order to find database connection details? Do we set environment variables that have this information? Or should we have some default place to write this data so that a user can just require_once a file and call it a day?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The normal way to find out database settings is ddev describe.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right. My question is - are we okay explicitly saying that if you don't use one of our predefined app types, you're on your own for database configuration? Or can we help them out a little bit by making the credentials available somewhere in a machine readable way?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would say we're not committed to settings config at any point for any of these. Currently we only do it on db import, but I'm in favor of a new command that does it explicitly (if we have that functionality for the given apptype). We have so many internal conflicts on settings.php on Drupal alone that we're quite stretched on how to do it. We haven't sorted out authoritatively what you do if settings.php exists. We create a settings.local.php, but without checking to see if settings.php includes it. And we don't know what to do if there's already a settings.local.php. It's kind of a rathole. Hard to solve for just Drupal.

Comment thread pkg/ddevapp/apptypes.go Outdated
}

// UploadDirFunc returns the upload (public files) directory for the given app
func UploadDirFunc(l *DdevApp) string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there ever a case where we need > 1 upload dir? For instance, if we eventually support Drupal multisite, do we need an upload dir for each site? Would it be worthwhile to make this a list of strings rather than a single value to make it easy to expand in the future?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I dearly hope we'll never support any kind of multisite, don't think we will.

However, we do have the problem of public and private. We currently have no support at all for Drupal's private files.

I'd say this is probably out of scope for this PR, but it's a good place to think about it anyway.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FWIW I just got a question about multisite yesterday. I'm in the same boat as @rfay though, I'd prefer not to support it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Multisite is so tremendously evil. I've never understood why in the world it cumbers the earth. I discovered back in 4.6 or something that you can't safely upgrade one of your multisites without breaking the others during the code upgrade, and it's never changed. Never have figured out what problem it solves (unless a MB of code is a storage problem for you).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't particularly want to support multisite either, but it was an immediately obvious use for multiple upload dirs. Does changing this function's signature have a bigger impact? Because if it's a simple change, I think it's important to do this now so that we don't have a breaking change later down the road.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

My bet is the problem is not the func's signature, but rather our assumptions in code. You're right to question the assumption, but I don't think we should change it now because I'd rather aim at simple approaches that match our current thinking. For example, I'd expect we'll have a file_upload_dir in the config.yaml before very long at all, that this would return. If we start to make it plural ahead of the thinking, it implies things that aren't true. file_upload_dir could be a yaml array, but I'd rather see us grow into that in a later PR.

The way I see it right now, we're not committing to much with these signatures (although best to have them as good as they can be). It's not a lot of work to finesse for all the types they represent.

Comment thread pkg/ddevapp/apptypes.go Outdated

// GetHookSuggestions gets the actual text of the config.yaml hook suggestions
// for a given apptype
func GetHookSuggestions(apptype string) []byte {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not super clear on what this returns. Is this something that's going to be different for each app type?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I see, looking down at the implementation, this is for suggested hook settings (so drush cr after a db import or whatever). Given that "hook suggestions" is a phrase that has some pretty specific meaning to Drupal developers, can we rename this to something else? Maybe GetSuggestedHooks or GetDefaultHooks or something like that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes great sense.

@rfay
rfay force-pushed the 20171212_multi_cms_experiments branch 3 times, most recently from 188308e to 77ad6cf Compare December 21, 2017 01:06
@rfay rfay changed the title WIP: Generic multi-apptype support, fixes #535 Generic multi-apptype support, for #535 Dec 21, 2017
@rfay

rfay commented Dec 22, 2017

Copy link
Copy Markdown
Member Author

I'd like to go head and get this reviewed and in, rather than keep growing it. Hopefully it's not too hard to understand now, but if we do smaller PRs to add to it after it goes in, things will be better.

  • Add detector function by apptype so detection can easily be in isolated code (thanks @cweagans ) Make the apptype detection a suggestion instead of just going with it.
  • Add post-import warning function (currently only for wordpress, but better than inline code)
  • Test review. We should be accessing per-CMS functionality via the functions in apptypes.go
  • Backdrop support
  • Typo3 support

@rickmanelius

Copy link
Copy Markdown
Contributor

@rfay I know that @beeradb left some feedback but given that he and @tannerjfco are out of town this week, I'm assuming you've addressed any nits in a way that you believe Brad would support so that we can make forward progress, correct?

@rfay

rfay commented Dec 27, 2017

Copy link
Copy Markdown
Member Author

@rickmanelius I'm pretty sure all feedback from Brad and Tanner has been incorporated, except for the things that should be done in additional PRs.

@rfay
rfay force-pushed the 20171212_multi_cms_experiments branch from 10104e6 to 76f2d27 Compare December 27, 2017 14:28
@rfay
rfay merged commit 5e015d2 into ddev:master Dec 27, 2017
@rfay
rfay deleted the 20171212_multi_cms_experiments branch December 27, 2017 18:12
rfay added a commit that referenced this pull request Jan 3, 2018
* Add per-app apptype detection

* Change prompt to always prompt instead of default to detected apptype

* Add test of apptype detection

* Remove backdrop and typo3 for now, since we'll want to do a release without them
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.

4 participants