[Pmwiki-users] PmWikiDataStore - Using a class for page file i/o.

Greg Morgan Cybie
Mon Mar 22 00:30:44 CST 2004


Patrick R. Michaud wrote:

>On Sun, Mar 21, 2004 at 09:17:17PM -0800, Greg Morgan wrote:
>  
>
>>   [1]http://www.pmichaud.com/wiki/Development/PmWikiDataStore
>>   I've  just  finished  a  patch  for  PmWiki  that  I was hoping to get
>>   included in the next release.
>>    
>>
>
>More comments--
>
>I probably sent my previous message a bit prematurely and need to
>think about the overall approach a bit more before rejecting the OO
>approach outright.  However, one other item that probably needs to be 
>considered in changing PmWiki's storage model is that it should be possible
>for a single site to access pages from a variety of storage
>mechanisms and not be restricted to a single medium.  For example, 
>a site could use an SQL backend for some pages but still 
>seamlessly access the pages that are stored as files in wiki.d, 
>wikilib.d, and other custom directories that may have created.  
>This makes it much easier to convert a site from one storage medium
>to another without having to do a lot of page conversions.
>  
>
That was pretty much my goal in doing this.

>My expectation has been that $WikiDir and $WikiLibDirs could grow 
>smarter to allow someone to specify places other than file directories 
>to look; i.e., one could do something like:
>
>   $WikiDir = 'sql:PmWikiTable';
>   $WikiLibDirs = array(&$WikiDir,'wikilib.d');
>
>and the existing ReadPage/WritePage would call other user-supplied
>functions based on the string type.  On the other hand, taking
>an OO-based model we could potentially do something like:
>
>   $WikiDir = new FBStore('wiki.d');
>   $WikiLibDirs = array(&$WikiDir,new FBStore('wikilib.d');
>
>with ReadPage(), WritePage(), etc., calling methods of $WikiDir and
>$WikiLibDirs.  Then, when an SQL-based model is available, one can do:
>
>   $WikiDir = new SQLStore('PmWikiTable');
>   $WikiLibDirs = 
>     array($&WikiDir,new FBStore('wiki.d'),new FBStore('wikilib.d'));
>
>and all of the sites existing pages in wiki.d continue to work with 
>new edits being stored in the SQL table.
>
>This is also important so that people will continue to be able to
>get the latest pages from wikilib.d/ when upgrading, and so we
>won't need lots of admin scripts/functions to import/export pages 
>between formats.
>
>Pm
>  
>
This sort of thing is exactly why I went with the OO approach.  However 
I was reluctant to change what was stored in $WikiDir or $WikiLibDirs, 
since that might break existing code.  Instead creating the 
$WikiDataStore global variable to contain the currently used data store 
object.
In practice how things would probably look like is this
*WikiDataStore *- This is an abstract class which has all of the need 
methods to read/write and find which pages a datastore has.
Once PmWiki starts up the global variable $WikiDataStore is assigned an 
object that descends from the WikiDataStore class.  $WikiDataStore is 
the object used by PmWiki for all page i/o.

*filebasedwikidatastore *- This class descends from WikiDataStore. It 
implements all of the methods in WikiDataStore.  (The code is basically 
cut & pasted from your existing ReadPage and WritePage functions)
*SQLDataStore *- (Not written yet) Also descends from WikiDataStore.. 
Implements the same functions.. but gets it's data from SQL tables... 
Even though it's using table, it's important to remember that 
SQLDataStore->ReadPage($pagename) still returns an associative array 
just like the old fashioned ReadPage.
*DataStoreCollection *- (not written yet) Descends from WikiDataStore.  
This object is a little different.  It designed to contain one or more 
objects that are descended from WikiDataStore.  It will have a method 
called AddDataStore($datastore).  This method gets passed another object 
which is also descended from WikiDataStore, like so.
$WikiLibDirs = array(&$WikiDir,'wikilib.d');
$WikiDataStore= new DataStoreCollection();
foreach ($WikiLibDirs as $dir) {
    $tmp = new filebasedwikidatastore($dir);  #note: my current code 
doesn't support the "new filebasedwikidatastore($dir)", but I can fix that.
    $WikiDataStore->AddDataStore($tmp);
}
$tmp = new SQLDataStore('MyDatabase');
$WikiDataStore->AddDataStore($tmp);
When *DataStoreCollection* is ask to read or write to a page. It calls 
the ReadPage or WritePage method for each datastore in it's collection 
until it's successful.

It's getting late, so I may not be explaining this very well...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://contra.vosn.net/pipermail/pmwiki-users_pmichaud.com/attachments/20040321/8fabc801/attachment.htm


More information about the pmwiki-users mailing list