1 (edited by pedrotuga 2006-08-12 04:12)

Topic: data model question

i am developing a rss newsbot, basicaly it will post on item fetched from an RSS per new topic on a forum.

I went an look at the data model and i got an existencial question:

the table "topics" contais a field called "last_post", while the table "posts" contains a fiels called "topic".
Ok... this a biderectional relationship... what da heck.. in wich table should i insert first a row?
If i insert a topic witch message should i relate its last message to?
If i insert a message wich topic should it belong to?

I didnt went into punbb code... but i guess i have to use mysql_insert_id() or something similar.. the problem is that both tables have forigner key on each other...

any help?

EDIT:
this is related to the above subject.... i am writing the script in php and access it using a cronjob. How should i protect my php script so nobody access it for DDoS or other malicious purpose?
Also... it doesnt sound sooooo eficient... i wil fetch news from about 150, maybe 200 feeds... the average should be like 3 new item a day.... wont it be to heavy? do php files have an execution timeout set on apache?

sorry... so many question... thanks in advance

2 (edited by Frank H 2006-08-12 05:17)

Re: data model question

Might be worth looking into post.php, as the more you 'know' how PunBB works, the better the result usually is. Rickard has written a very clean and easily understandable code, so you shouldn't have any problems looking at it. smile

There's several kind of ways to make sure 'only' the cronjob can run, one alternative is to make a 'get' variable with a loooooong randomized key ... and if it doesn't match, just exit the script.

depends on how often you run the cronjob, and how you keep track on your already inserted rss feeds

yes, Apache and PHP has timeouts, the PHP timeout is possible to fiddle with inside the .php file, just add set_time_limit, the Apache might interfer with it's CGI timeout (you probably need to check their manual for info on this one, I've forgot wink)

Re: data model question

the table "topics" contais a field called "last_post", while the table "posts" contains a fiels called "topic".
Ok... this a biderectional relationship... what da heck.. in wich table should i insert first a row?
If i insert a topic witch message should i relate its last message to?
If i insert a message wich topic should it belong to?

last_post is a timestamp, not a post ID smile
http://punbb.org/docs/dev.html#dbtables
last_post_id, on the other hand, is a post ID. What you do is insert a topic, not giving a value for last_post_id. Use $db->insert_id() to get the topic ID. Then you insert a post, giving it the topic ID you got. Use $db->insert_id() to get the post ID. Update the topic with the post ID you got for last_post_id wink

Re: data model question

Ops... i missed that. LOL

I went and browse the code of post.php, thogh i didnt read it line by line.
I dont usualy use so much POO PHP programming. I see the advantage os using the database class in order to make punbb compatible with many database systems.

I am thinking of writing my script only for mysql ( my host doenst suport any other ) using native php fynctions.
But.. thats a bit shitty...

lets see... where is the database class defined in punbb?

Re: data model question

The file `include/dblayer/common_db.php` will include the right file based on what database is being used. The other files in `include/dblayer` contain the actual DBLayer class for that particular database.

Re: data model question

let me have a look on that...

allow me to make yeat another dummy question:

If i want to use the dblayer, can i just

include "include/dblayer/common_db.php"

and have the dblayer ready to use to whatever i want?
let me give another into the code

Re: data model question

The dblayer is already included in a plugin wink
Just use $db like this:

$result = $db->query("SELECT * FROM table");

Re: data model question

[5 minutes...]

cool!!! very simple and well written code... i love this piece of software...