I have different domain names which I would like to be recognised as the same "domain record" in domain access... for example: one.com, sub.one.com and dub.one.com all acting as the same "domain record" that is same site title, same shared tables etc.
My first approach was to just strip anything up to the first dot (.) and try to match the remaining part as well... that worked fairly well, adding OR '%s' LIKE CONCAT('%%.', subdomain)
as conditions to the sql-statements in domain_init() and settings_domain_prefix() already did the job. After reading agentrickard's comment in this issue I'm not too sure it's a good idea to just strip the first part of the url... (apart from the fact that such a feature would of course need a configurable option in the domain settings and shouldn't just be added to that db query). Also another thing is that I would actually want to be able to use entirely different domains (like example.com, example.de and example.org) to all match one an the same domain record which would not work with above code...
One idea to provide that functionality is to develop a separate module which allows to create synonyms, possibly similiar to the user module. This might work but it seems a bit silly to have different domain records when all the "record data" (sitename, table-prefixing etc.) is the same and we'd to have to keep everything synchronised. Also as far as I can see we would have to change the table prexixing module to load the right set of tables in _domain_prefix_load(), so it also wouldn't be an entirely separate module after all ;-)
Another idea which I like best so far, is to implement this feature directly in the domain module... in order to this I'm suggesting the following changes/additions:
- New file domain_bootstrap.inc: functions to remove duplicate code in domain_init(), _domain_prefix_load() etc.
- get $_subdomain: that is removing host protocols from host name (that part that is marked as "cribbed from bootstrap.inc" at the moment)
- retrieve domain_id from database: use new table & pattern matching, see below
- this would remove duplicate code and could be used to reduce the number of sql queries by one or two (caching)
- Create a new database table 'domain_synonyms'
- Schema (int dsid, int domain_id, varchar subdomain, varchar pattern)
- use table in domain matching process (domain_bootstrap.inc); query "SELECT domain_id FROM {domain_synonyms} WHERE subdomain = '%subdomain'"
- would also allow to add synonyms for the default domain without changes to the {domains} table
- Add configuration options on the domain settings page to allow specification of synonyms
If the whole domain synonym thing doesn't fit into the domain module (agentrickard?) then maybe just introducing that bootstrap file and providing some ways for the user to change/determine the domain record themselves (hooks won't work as module system might be loaded at runtime, but we could call some custom_domain_bootstrap() function if defined) might open up a way...
What do people think?
Comment | File | Size | Author |
---|---|---|---|
#49 | bootstrap_new.patch | 35.84 KB | agentrickard |
#46 | domain_boot.zip | 12.19 KB | agentrickard |
#39 | domain_bootstrap.patch | 18.84 KB | agentrickard |
#37 | domain_bootstrap.patch | 29.58 KB | bforchhammer |
#35 | domain_bootstrap.patch | 29.01 KB | bforchhammer |
Comments
Comment #1
agentrickardI like it. This makes a lot of sense to me, and it would not be too hard to implement.
Note that the patch here will get in to the final release for D6: http://drupal.org/node/270983
Comment #2
bforchhammer CreditAttribution: bforchhammer commentedYou're right, it wasn't too hard to implement... attached is a patch with pretty much all the things I suggested above; please review! :)
Patch details:
Comment #3
agentrickardThat is all probably too much for one patch, especially since it incorporates other changes.
I think the Alias part should be split off into a separate module.
Comment #4
agentrickardI would break the patch into pieces:
1) Domain Alias module. Includes all the management functions for domain aliasing.
2) domain_bootstrap.inc. Includes the new file and changes to existing settings includes. My preference would be to run this from hook_init(), if possible, to avoid having to put items into settings.php.
Comment #5
bforchhammer CreditAttribution: bforchhammer commentedI didn't divide them because the aliasing part is tied into the domain core fairly deep, but it's probably better to separate the code... I'll give it a try later.
Yes, I actually thought about that as well... the earliest hook that gets called is
hook_boot()
duringDRUPAL_BOOTSTRAP_LATE_PAGE_CACHE
, which is after the config/variables and database phases... is that too late for domain_conf and domain_prefix?If that works we wouldn't need a bootstrap file anymore as domain.module needs to be loaded for domain_boot... (still good for more clarity though, I guess)
Comment #6
agentrickardhook_boot is too late. It looks like we'll need to put something in settings.php -- but I would prefer not to, simply to make installation easier. Not sure we have a choice. We could, I think put some code into domain.module that gets executed when the module is loaded, but that seems like a bad idea.
The core module should have the hooks you need to integrate the features through a separate module.
Comment #7
agentrickardNote that today I moved domain_init() to domain_boot() for a separate reason.
See http://drupal.org/node/277046
Comment #8
bforchhammer CreditAttribution: bforchhammer commentedOkay, thanks... I hope I'll manage to rewrite the code and produce a new patch by the beginning of next week.
Comment #9
agentrickardThere is a larger issue, uncovered by http://drupal.org/node/277046
If we move the domain lookup function out of hook_init(), we break hook_domainload(), because it seems that Drupal does not know what modules are installed when hook_boot() runs.
Comment #10
bforchhammer CreditAttribution: bforchhammer commentedYes...
It might be a good idea to have different version of the domain_load function...
What do you think?
-------------------
for reference (taken from drupal_bootstrap documentation):
Comment #11
agentrickardAt the moment, I'm hip deep in http://drupal.org/node/278582, and in striving for E_ALL compliance.
My early tests for moving functions out of domain_init() into a bootstrap file did not go very well.
However, it looks like we _can_ do something like this:
Or, use:
Then we pick up the $_domain global in the other include functions. And in domain_init(), we run the full domain_domainload().
In either case, the domain aliasing functions should stay part of the core domain module -- which is a reverse of what I said in #3.
All that said, these changes might not really buy us that much -- sure having the code overhead in Domain Conf and Domain Prefix is annoying, but it isn't that bad.
Comment #12
agentrickardBe sure to test / patch against HEAD. I have been committing code steadily all weekend.
Comment #13
agentrickardNote that rc4 is up to date as of 06 July.
Comment #14
bforchhammer CreditAttribution: bforchhammer commentedI'm checking out HEAD now and working from there...
Comment #15
bforchhammer CreditAttribution: bforchhammer commentedAttached is a new patch introducing only domain_bootstrap.inc (patch against HEAD).
Feedback please... :)
Comment #16
bforchhammer CreditAttribution: bforchhammer commentedI have attached a slightly modified version, mainly adding better comments and improving code quality.
To use the patch, apply it and change your settings.php to only include domain/settings.inc instead of those two settings includes for domain_conf and domain_prefix.
It would be great to just receive at least a little feedback if this is going to work as is (especially with those two "hooks"), so I can start developing the domain_alias submodule. (and if not I'm willing to keep working on it however long it takes until some version of this can be applied to the module) :)
Comment #17
agentrickardSorry, I am dealing with some personal matters and may not get to review this week.
Looking through without testing, some quick notes:
Just use if TRUE in both statements?
Name could be clearer. DNRESOLVE? Do we mean DNS_RESOLVE?
There is obviously some debug stuff here -- timer_start() for instance. Mark what can be removed after testing.
Use full, proper sentences (with Caps) for comments.
Not sure about registering modules in domain_settings.inc -- seems like a burden on the user. We can derive this information from the {system} table.
Comment #18
bforchhammer CreditAttribution: bforchhammer commentedThanks for your reply :)
From php.net/strpos:
Because I'm using it to check whether the "www." substring exists I'm only interested in whether it's not FALSE; the integer number zero is usually interpreted as FALSE as well which is the reason for the strict comparison.
Yes, that's not very clear... the idea behind the naming was "domain name resolve". (DNS = "domain name server" doesn't seem fitting.)
I'm renaming it to DOMAIN_BOOTSTRAP_DOMAINNAME_RESOLVE.
The idea behind that "registering" was to only load modules that implement those two domain_bootstrap (that is domain_prefix and domain_conf at the moment) hooks; this information is not stored in the {system} table. Just loading all modules doesn't seem like a good idea because it's actually too early in drupal's bootstrap phase. And just loading all modules that are marked for "bootstrap" might not include the relevant modules either.
The list of registered modules wouldn't have to be changed by the user, if a module can't be loaded it's just ignored. So that's only something that module developers would have to change by adding their modules if they implement one of the bootstrap "hooks".
An option to this would be to scan all modules for implementations of those hooks once in a while and cache the list somewhere (new database table?), but that seems much effort for probably no more than 3 or 4 modules using them. (This solution would be similiar to what drupal does -- marking modules implementing hook_boot in the {system} table.)
I admit it can be a little confusing to call them "hooks" while they are actually just a cheap copy of drupal's hooks... unfortunately we can't use drupal's hook system without initiating the whole module system (which I think can't be done without initiating those other early drupal bootstrap phases which we were trying to avoid in the first place...).
Comment #19
agentrickardYou can force module authors to declare this using hook_enable() and hook_disable(), then store it in a small table or variable that you query directly. Or we could store an array somewhere in the main module?
I agree with the other answers -- the boolean FALSE bit is just my preference, but it is appropriate here. I do a few odd things codewise, like return -1 on lookup failures, because I just prefer the method. But your approach seems fine.
Comment #20
bforchhammer CreditAttribution: bforchhammer commentedhook_enable() and hook_disable() is a good idea, I'll try that. Storing in a variable wouldn't work I think because domain bootstrap happens before variable_init()... So it's probably going to be a new table: {domain_system}
I thought about altering the {system} table instead (just adding a new column domain_bootstrap would be enough) but it's probably better not to change drupal core stuff as long as it's not necessary, right?
Comment #21
agentrickardDon't change the core, right. And if you store the variable, you could just query the table directly instead of waiting for $conf init.
Then you have to unserialize the result, since variable_get() does that for you.
I think using the {variable} table is probably better. We have enough db tables already :-p
Then in hook_enable/disable, you have code like so:
Note that we have to rely on other modules to use enalbe/disable, since there is no built in way for Domain module to act on module activation. We could, alternately or additionally, have this variable reset every time someone goes to the DOmain configuration screen.
Comment #22
bforchhammer CreditAttribution: bforchhammer commentedRight, I didn't think about that... that's better than creating yet another new table.
Thanks, I'll quickly merge that with my code, do some tests and then I'll upload the new version...
Comment #23
bforchhammer CreditAttribution: bforchhammer commentedOkay, I've implemented a version as you suggested, using the variable table and manually querying it. Other modules have to call domain_bootstrap_register('modulename') and domain_bootstrap_unregister('modulename') in their hook_enable() and hook_disable() implementations. By specifying a second parameter on domain_bootstrap_register they can also specify a weight.
I liked the idea of cleaning up the variable on the config screen, so I added a function domain_bootstrap_modules_cleanup() and a respective call to the hook implementation domain_domaininstall().
I also cleaned up all the comments again and removed debugging code.
Comment #24
bforchhammer CreditAttribution: bforchhammer commentedSplitting this issue and moving the subdomain alias part to #284422: Subdomain Aliases...
Comment #25
agentrickardI very much appreciate the work on this patch, and simply have not had time for proper review during the recent release cycle.
I really want to get this some thorough review, and now that rc5 is out, I may be able to.
Patch may need testing against HEAD.
In the D5 branch, this is the core of a 5.x.2 release.
Comment #26
bforchhammer CreditAttribution: bforchhammer commentedNew patch against current HEAD...
Comment #27
agentrickardSee also the new i18n patch, which will affect how this is implemented.
http://drupal.org/node/266071#comment-941928
Comment #28
bforchhammer CreditAttribution: bforchhammer commentedFrom quickly looking through the i18n patch I spotted at least two things that need to be adjusted:
This definately needs some thorough testing... I probably won't get a chance to work on it during the next 2-3 weeks.
Maybe it would be good though to test and integrate this patch first before adding another feature... or the other way round ;-)
Comment #29
agentrickardAgreed.
Which one is more important to you?
Comment #30
bforchhammer CreditAttribution: bforchhammer commentedPersonally this one (domain_bootstrap) as the domain alias module depends on it...
Comment #31
agentrickardAgreed. The i18n stuff is interesting, but here at Palantir.net, we need the aliasing first.
Comment #32
agentrickardPatch does not apply, since the filepaths are odd. Any way you can fix that?
Comment #33
bforchhammer CreditAttribution: bforchhammer commentedHm, I'm not sure I understand what you mean but here's a new patch against HEAD... hope this one works :)
Comment #34
agentrickardThe fact that you patch against a named folder causes the patch to fail on other systems.
It would work if you used a CVS checkout and did CVS diff, or if you put your patched files in a domain-new folder and left my originals in a domain folder. In which case you would have:
Which should apply cleanly. (The issue is that my install cannot find your base directory, since it is named incorrectly.)
Comment #35
bforchhammer CreditAttribution: bforchhammer commentedHm, and I thought that it would work anyway... thanks for the lessson. :)
Attached is the patch following your naming example..
Comment #36
agentrickardYes. That one applies cleanly. (It took me a long time to figure out patches as well; it is usually easier to use CVS diff.)
Comment #37
bforchhammer CreditAttribution: bforchhammer commentedNew Version patched against current HEAD and fixed an issue that resulted in the www. redirection not working properly.
How's the review process going? ;-)
Comment #38
agentrickardIt is on hold until after Szeged, likely.
This introduces a large enough change that it will call for an x.2.0 release. I am hoping to have 6.x.1.0 stable -- if people would check the outstanding issues :-) -- very shortly.
After 1.0 is stable, this gets tested and released as 2.0.
Comment #39
agentrickardHere is a new version of the patch against HEAD. I have only just begun review -- this patch is HUGE, and I think that's a big problem.
Please DO NOT delete existing files with patches. We haven't decided whether to remove them or not.
Some other minor changes:
-- Cleaned up a few lines of grammar and punctuation (minor).
-- Moved custom_url_rewrite_outbound() into settings.inc -- this seems wise, so now there is only one include in settings.php.
-- Fixed a logic error with www redirects that caused infinite looping.
Comment #40
agentrickardComment #41
bforchhammer CreditAttribution: bforchhammer commentedI got some spare time this weekend, tell me if you need any help... :)
Comment #42
agentrickardI just need to go through the code and figure it out. You do some things differently than I would. But "different is not wrong." I just need to see if the code fits and is something I can maintain.
We are also doing a big install with Domain Alias, which will allow for a good amount of testing of both patches, so we should be in good shape.
Comment #43
agentrickardHm. I don't think the new patch creates the domain_bootstrap.inc and settings.inc files.
Comment #44
agentrickardIt looks like either this patch or Domain Alias breaks domain_user() in some way.
Nevermind.
Comment #45
agentrickarddomain_bootstrap.inc needs to be renamed domain.bootstrap.inc according to Drupal convention.
Comment #46
agentrickardHere's a file batch, with patch and new files. Unzip in your domain directory and then apply the patch.
Comment #47
bforchhammer CreditAttribution: bforchhammer commentedApplys nicely and everything seems to work... on a clean drupal6.4 anyway :)
Comment #48
agentrickardI had an issue trying to install Domain Alias at the same time as DA on a server, but I think that can be worked out. It looks good, I just need to comprehend the code before it gets committed.
Comment #49
agentrickardNew patch, up to date with HEAD -- plus now it creates the files for you.
Comment #50
bforchhammer CreditAttribution: bforchhammer commentedA few "finishing" thoughts:
1. I don't really like the current implementation of
domain_settings_setup_ok()
...I think it might be cleaner to rename it to something like "domain_check_settings_include" and have it handle the error message or error logging as well... At the moment, the same error message is sent from within bootstrap_full hooks in domain_prefix and domain_conf.
2. I haven't checked recently but I also remember having issues with error handling in the bootstrap file, because drupal_set_message and watchdog aren't loaded yet. We could handle that by storing errors in a static variable somewhere and handing them over to drupal's error handling during
domain_boot()
ordomain_init()
.3. Readme file(s) haven't been updated yet.
4. Bootstrap-hook comments (implementations and API.php) still include the following line:
In order for this hook to work your module needs to be registered in domain/settings.inc.
This should now be something like:
In order for this hook to work your module needs to be registered as a domain bootstrap module by calling domain_bootstrap_register("modulename") in your hook_install implementation.
Comment #51
agentrickardNoted. I just thought to run the patch through some benchmarking, and here's what I found.
The difference is negligible. .02 requests per second for an anonymous view of the homepage (less than 1%). .07 for a story page (less than 2%). So the new code should be fast enough to accept.
Comment #52
agentrickardThis has been committed to HEAD for further testing.
Let's open new issues as needed.
Comment #53
bforchhammer CreditAttribution: bforchhammer commentedWonderful, thank you very much! :)
Comment #54
agentrickardNo. Thank you. This is a great patch. It just needs lots of testing.
Hoping to get 6.x.2.0-beta1 out next week.
Comment #55
agentrickardFYI -- I just did the first batch of code review and cleanup. Mostly personal style issues. I also fixed the error message problem.
See HEAD for the newest revisions.
Comment #56
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.