Accidentally sent this to the cgi-wiki list. doh!!
As promised to Kake last night, I've written some config file location code that isn't specific to my installation. Can people take a look and see what they think please?
Jody
On Fri 19 Sep 2003, Jody Belka belkajm-openguides-dev@aardvark-ss.com wrote:
As promised to Kake last night, I've written some config file location code that isn't specific to my installation. Can people take a look and see what they think please?
Jody,
Can you give a clear statement of the problem you're trying to solve with this? I know we discussed it briefly in the pub, but I'd been drinking, plus the other people on this list weren't all there.
Kake
On Sat, 20 Sep 2003, Kate L Pugh wrote:
Can you give a clear statement of the problem you're trying to solve with this? I know we discussed it briefly in the pub, but I'd been drinking, plus the other people on this list weren't all there.
No problem, and while i'm at it i'll include an updated diff file ;)
Problem Statement -----------------
I'm running two OpenGuides sites, Birmingham and Manchester. Because of this I wanted to unify the sites, so that they shared the same code. To do this i made changes to my local copy of the cgi scripts, so that:
1) The config files were located in a folder called 'config', at the same level as the script folder (thereby also removing the config files from the web root)
2) To determine which config file to load i extracted the first portion of the domain name and used that as the filename.
This solution, however, has two main problems:
1) Every time I want to update my OpenGuides installation to the latest version i have to reapply my changes.
2) This is obviously specific to my installation, and would not be suitable in many other cases.
Suggested Solution ------------------
The above led to the suggestion from Kake that I try to come up with a more general solution to the problem, that could (potentially) be included into the offical OpenGuides distribution, thereby solving my problems.
This led to the patch that I posted yesterday, to which I have made some further changes to this morning to simplify the simple case, and have therefore attached to this message.
My patch attempts to solve the problem in the following way:
1) As in my original code change, the config file(s) are moved into a folder called 'config', at the same level as the script folder. I feel that this is essential, due to the database username and password being stored in said file(s).
2) It requires a master config file that is called 'openguides'. This file is of the same style as the normal OpenGuides config file, but currently only has one item, named 'config'. This item is evaluated as a TT2 template, and has access to two lists, 'domain' and 'path', which contain the individual segments of their respective inputs.
For my installation, then, I would use this: config = [% domain.0 %]
This isn't the whole story, however. In order to make the simple case (that of a single OpenGuides site) easier, if:
a) the config item does not exist b) the config item is empty c) the config item contains 'openguides' d) the config item evaluates, through TT, to 'openguides'
Then the master config file itself is used, and no changes other than the location of the file need to be made to existing standard OpenGuides installations. Also, in all the above cases other than d, no TT object is even instantiated, keeping overhead to an absolute minimum.
Suggested Benefits ------------------
1) This makes OpenGuides installations multi-site capable out of the box.
2) It does so without making the simple case of a single-site installation any more complicated.
3) Although patches for the cgi scripts are not included (the changes required are very basic), it should hopefully be obvious that this centralises the knowledge of how to find and load the site config file, removing the need for that code to be in every cgi script.
I humbly submit my patch for examination,
Jody
On Sat 20 Sep 2003, Jody Belka belkajm-openguides-dev@aardvark-ss.com wrote:
I'm running two OpenGuides sites, Birmingham and Manchester. [...] 2) To determine which config file to load i extracted the first portion of the domain name and used that as the filename. [...] 2) It requires a master config file that is called 'openguides'. This file is of the same style as the normal OpenGuides config file, but currently only has one item, named 'config'. This item is evaluated as a TT2 template, and has access to two lists, 'domain' and 'path', which contain the individual segments of their respective inputs.
For my installation, then, I would use this: config = [% domain.0 %]
How about we allow for require'ing a module OpenGuides::Local::Config instead of this master config file. You will write that module yourself to suit your site-specific requirements, and install it wherever you normally install perl modules. If the module doesn't exist then the default is to a simple 'wiki.conf' file in the current directory.
Benefits of this over the master config file solution:
- It doesn't restrict you to only using $ENV{SERVER_NAME} and $ENV{SCRIPT_NAME} to work out where the config file is - you can use anything you can come up with to distinguish between sites.
- It's neater. I don't like the idea of using the sledgehammer of the Template toolkit to crack the nut of extracting the first element of an array.
- You can write tests for OpenGuides::Local::Config; trickier perhaps for a plain config file.
Thoughts?
Kake
openguides-dev@lists.openguides.org