Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Add an AddWhere call to every DB access?

edited May 2006 in Vanilla 1.0 Help
Can anyone tell me if it would be possible to write an extension that will add an AddWhere database call to every single DB access? For example, when the Discssions page is displayed, the extension will check that each discussion is older/newer than a certain date. Is that possible, if so, how? Excellent piece of software by the way, and a breath of fresh air.


  • I might be very tired and a shade drunk, but I'm totally not understanding what you're asking.

    If you need to change stuff to do with database accessing my guess is that you need to checkout the database classes and possibly create an extension to modify the functions within them but depending what exactly it is you're trying to do there might be an easier way round it. Dont forget that any increases in DB calls will slow down the load times and whatnot.
  • What I actually want to do is to create multiple instances of Vanilla but using the same scripts and the same database. If I add a column to each table: "InstanceID" where an InstanceID is the ID of an instant of Vanilla, which is its own forum; all I then need to do is ensure that when Vanilla looks up an entry of any kind from the database, it checks that that entry has the correct InstanceID. I have played with the code and know I could modify the source of each file to do it, but I would rather implement it into an extension. For example, I added the following to the GetCategoryBuilder function of the Vanilla.Class.CategoryManager.php file: $s->AddWhere('c', 'InstanceID', '', 1, '='); and this then displayed only the Categories with the InstanceID of 1. I hope you get what I mean. Cheers.
  • *bump* Anyone please?? Is this possible, or do I have to modify the source?
  • lechlech Chicagoland
    I still don't follow exactly what it is that you want to do...
  • I think i understand what he wants to do though i'm not entirely sure why. Seems to me it'd be much easier to just setup a number of vanilla datasets on different prefixes, and just use the same users table if necessary. Unless he's *that* desperate for space?
  • But if I end up with thousands of vanilla instances, that can take up a lot of space and will be a nightmare to manage when it comes to upgrades and improvments. All I want to know is how I can modify each DB select to use an extra WHERE statement: $s->AddWhere('c', 'InstanceID', '', 1, '=');
  • Thousands? Crikey.
    Well if you know what needs doing to the code you should just be able to make an extension which replaces the functions you need changing. I'm not sure if there's a more efficient way to do it but obviously doing that would be preferable to actually hacking at the source code. Mark?
  • lechlech Chicagoland
    I think this is where the serverfarm settings come in, don't they?
  • I would think the overhead for extra database tables would be minimal; it's the data inside them that takes up so much space, and you'd need to store that whether you used one set of vanilla tables or a thousand.
  • edited May 2006
    serverfarm settings?? care to share what they do? bergamot: what about DB upgrades though?
  • If you used numbers in your table prefixes, you could write a simple SQL script to loop through them and make changes.

    Extra work? Yeah, but so is managing 1000 forums out of one set of tables.
  • i don't think you can do what you're asking without changing the core.
  • Well he could certainly write an extension that subclassed a database class (Framework.Class.SqlBuilder.php?) and added a where clause to each query.
  • [quote]Well he could certainly write an extension that subclassed a database class (Framework.Class.SqlBuilder.php?) and added a where clause to each query.[/quote] That is exactly what I am trying to do. Now why didn't I say it like that!
  • MarkMark Vanilla Staff
    There are many ways to do this. Your first idea could work (where you add your where clause to the necessary queries), but I might need to add some more delegates to the DiscussionManager class so you can alter the queries where necessary. You could also do what bergamot just suggested and write your own MySQL class that automatically adds the where to all selects, but I wouldn't recommend that since there are so many queries you will most certainly run into aliasing conflicts. Finally you could just put all of the different forums in the same database with numbered prefixes like mini suggested. Then your conf/database.php file for each one would need to declare the new table names - but you'd probably keep all of them pointing at the single user table.
  • OK thanks Mark. Hey, care to shed some light on the "FARM_DATABASE" settings?
  • MarkMark Vanilla Staff
    If you specify a different data source using the FARM_ configuration settings, it will change the way that the database object uses the two different databases. Whenever the database object inserts, updates, or deletes, it will perform those actions on the FARM_ database. If, on the other hand, you select data, it will pull everything from the main database.

    This way if you've got a datafarm setup where you have data going to a single source and then being spawned across various sources, Vanilla can integrate into it seamlessly. 99% of people will never need to use this feature - but it didn't slow anything down to add it in there and I had a client that needed it.
This discussion has been closed.