Override jdatabase

38 views
Skip to first unread message

Stephen Tredrea

unread,
Dec 18, 2009, 3:15:37 AM12/18/09
to joomla-dev-general
Hi, just wanting a bit of feedback on the direction of my thinking
with this (or reference pointers if it has already been discussed).

It pertains to J1.5 and concerns a common issue, access control.

Setting the scene...

Assuming I already have a means to classifying users according to
which I want to control access to articles, it's easy enough to write
a plugin that stops content being accessed when it's being loaded. If
we take an article as an example, the problem is in the many ways an
article makes its appearance in search results, category and section
layouts and all manner of modules: the title and/or intro text is
still visible even though the plugin would prevent access to the full
article. Writing a further check into template overrides is not an
option because it doesn't cover all bases and would mess with page
result numbering.

My thinking...

The one thing everything has in common is setQuery. If I can override
the setQuery function and adjust queries to include access checks in
the where clause then prehaps I have a solution. I realise adjusting
queries will pose it's own technical challenge and complexities but
before I consider that I'd first like to know if it's possible to
override the setQuery function.

What I'm thinking is a plugin that loads a JDatabaseExteded class that
extends JDatabase and then overrides what is returned by
JFactory::getDBO() after it has initial been set.

Possible? Workable?

Robert

unread,
Dec 18, 2009, 3:48:55 AM12/18/09
to Joomla! General Development
Hi,

basicly I think it is possible. Two problems come in my mind:

1) Conflicts with Joomfish. Joomfish goes on the way you have mention.
2) Performance. You need some regexp to make it possible and you are
in an area that is often used. So if you code is not very good you can
make a site very slow.

Robert

Mitch Pirtle

unread,
Dec 18, 2009, 2:09:58 PM12/18/09
to joomla-de...@googlegroups.com
On Fri, Dec 18, 2009 at 3:15 AM, Stephen Tredrea
<stephen...@gmail.com> wrote:
> Hi, just wanting a bit of feedback on the direction of my thinking
> with this (or reference pointers if it has already been discussed).
>
> The one thing everything has in common is setQuery. If I can override
> the setQuery function and adjust queries to include access checks in
> the where clause then prehaps I have a solution. I realise adjusting
> queries will pose it's own technical challenge and complexities but
> before I consider that I'd first like to know if it's possible to
> override the setQuery function.
>
> What I'm thinking is a plugin that loads a JDatabaseExteded class that
> extends JDatabase and then overrides what is returned by
> JFactory::getDBO() after it has initial been set.

I did the exact samething for several sites in the past that had
either massive scale or deep customization needs. Instead of a plugin
though I just copied mysqli.php to mysqlie.php (Mysqli-Extended! hehe)
and went from there. This is also how I managed to build my own
master-slave functionality as stock Joomla only has one connection.

Agreed you will need to be careful with your code, as performance is
only one of your issues ;-)

-- Mitch

Louis Landry

unread,
Dec 21, 2009, 9:06:57 PM12/21/09
to joomla-de...@googlegroups.com
Hi Stephen,

That is certainly a way to approach your problem.  In fact, in the beginning of the Nooku project when I was working on it with Johan that is exactly how we approached the multilingual problem.

In that case, all the specified "content based tables" would be replicated for each language and the database driver was wrapped with a system plugin and a few of the methods were wrapped such as the setQuery() method.  With that approach in mind we were able to achieve some pretty cool results without a lot of trouble.

I have no idea if the Nooku code base still uses this approach but I imagine that it probably does.  I'm attaching a very early copy of that system plugin so you can sort of see it in action.  This probably is a little more complicated than necessary depending upon your particular needs, but hopefully its helpful.

Also, I am attaching an early version of the mysqlie driver that Mitch mentioned.  It was originally designed to do two things, provide the capability to use prepared statements and separate the read/write connections.  This driver was for a very specific code base in a controlled environment so it isn't necessarily perfect, but it did what was advertised.  I don't know if Mitch rewrote it after I left that project, but this is an early copy I found from when I first put it together.

The approaches are very different, and also dependent upon whether you are in a controlled environment or not you should consider different options.  Anyway, I hope its helpful and best of luck solving your problems.

Cheers,
Louis





--

You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.





--
Development Coordinator
Joomla! ... because open source matters.
http://www.joomla.org
plg_system_nooku.zip
mysqlie.php.zip

Alex Kempkens

unread,
Dec 22, 2009, 10:37:37 AM12/22/09
to joomla-de...@googlegroups.com

Am 18.12.2009 um 09:48 schrieb Robert:

> Hi,
>
> basicly I think it is possible. Two problems come in my mind:
>
> 1) Conflicts with Joomfish. Joomfish goes on the way you have mention.

Joomfish does the same kind of aggregation that the normal Joomla JDatabase class does. So in the case you have a special driver it should be possible to add a simple wrapper in Joomfish as well and then use your driver too.


In general if we separated JDatabase from the real database drivers which again inherit JDatabase and use it more like a concept that is used by JDBC we could simplify these issues quite a lot. But I think this is a different discussion.

Alex

Reply all
Reply to author
Forward
0 new messages