I wanted to create my first extension so I went about trying to do a simple one to prevent a topic view count increasing if viewed by the topic creator. But as far as I can tell this is impossible. There is no way to modify any specific database query. And you can't modify the files direction anymore.
What if every database query had a unique identity number attached to it? Then all you need is one hook in the database abstraction function and extensions can target specific database queries to modify and/or perform their own functions whenever that specific query is called. So now every database query will look like: sql_query($sql, 3745) and all an extension needs to do is specify if($query_id = 3745){do stuff}.
Allowing Extensions to Modify Any Database Query
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.
If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.
If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
- Pony99CA
- Registered User
- Posts: 986
- Joined: Sun Feb 08, 2009 2:35 am
- Location: Hollister, CA
- Contact:
Re: Allowing Extensions to Modify Any Database Query
That's not strictly true. phpBB is Open Source, so you are free to modify the code any way that you like. You won't get an Extension approved by the Extensions team if you do that, however.BondGamer wrote:There is no way to modify any specific database query. And you can't modify the files direction anymore.
To get back to your point, there are places in phpBB where the query is built up from smaller pieces, so maybe you need an extension there (if there isn't one already). For example, displaying posts in a topic probably creates the SQL
ORDER BY
clause as a piece using the user's currently selected sorting preference.Not increasing the view count if a topic creator views the topic would probably be adding an AND clause something like
AND user_id <> topic_creator
as another piece of the query.Steve
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
Re: Allowing Extensions to Modify Any Database Query
I disagree with the initial proposal. If you want to edit an SQL query just require an event where the query is built and use this event to transmit and alter the query
Member of the phpBB Development-Team
No Support via PM
No Support via PM
Re: Allowing Extensions to Modify Any Database Query
Pretty sure the OP is talking about this within viewtopic.php
not sure how one edits a SQL query UPDATE?
Code: Select all
// Update topic view and if necessary attachment view counters ... but only for humans and if this is the first 'page view'
if (isset($user->data['session_page']) && !$user->data['is_bot'] && (strpos($user->data['session_page'], '&t=' . $topic_id) === false || isset($user->data['session_created'])))
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_views = topic_views + 1, topic_last_view_time = ' . time() . "
WHERE topic_id = $topic_id";
$db->sql_query($sql);
// Update the attachment download counts
if (sizeof($update_count))
{
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
SET download_count = download_count + 1
WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
$db->sql_query($sql);
}
}
Do not hire Christian Bullock he won't finish the job and will keep your money
Re: Allowing Extensions to Modify Any Database Query
But then you would need an event at every single location where a SQL query is built. That is currently not the case. Putting events all over will bloat the files and duplicate code. It would be much cleaner for it to be part of the query function.Nicofuma wrote:I disagree with the initial proposal. If you want to edit an SQL query just require an event where the query is built and use this event to transmit and alter the query
In this extension's case I would have it cancel the entire SQL query by putting in a return to exit the function so it skips executing the database command.RMcGirr83 wrote:not sure how one edits a SQL query UPDATE?
Re: Allowing Extensions to Modify Any Database Query
Not really... The event may be in the DBAL instead of in every place in the source code.BondGamer wrote:But then you would need an event at every single location where a SQL query is built. That is currently not the case. Putting events all over will bloat the files and duplicate code. It would be much cleaner for it to be part of the query function.Nicofuma wrote:I disagree with the initial proposal. If you want to edit an SQL query just require an event where the query is built and use this event to transmit and alter the query
The issue here is that many events will be called unnecessarily if the dispatcher is in that place (inside DBAL). This means phpBB would easily become dead slow. That's definitely not what we want.
- Pony99CA
- Registered User
- Posts: 986
- Joined: Sun Feb 08, 2009 2:35 am
- Location: Hollister, CA
- Contact:
Re: Allowing Extensions to Modify Any Database Query
I think what the OP wants is a master routine where each possible SQL query is identified by a unique ID and you can change the FROM, WHERE, SET, etc. clauses based on your needs.
For example, in the code snippet that RMcGirr83 posted, you have two queries, possibly named UPDATE_TOPIC_VIEW_COUNT and UPDATE_ATTACHMENT_DOWNLOAD_COUNT. Parameters might be the current values of the SET, FROM and WHERE clauses. For the OP's example, he could do one of two things (in pseudo-code):
Steve
For example, in the code snippet that RMcGirr83 posted, you have two queries, possibly named UPDATE_TOPIC_VIEW_COUNT and UPDATE_ATTACHMENT_DOWNLOAD_COUNT. Parameters might be the current values of the SET, FROM and WHERE clauses. For the OP's example, he could do one of two things (in pseudo-code):
- Append an AND condition to the WHERE clause like I suggested --
IF $query = UPDATE_TOPIC_VIEW_COUNT THEN $where_clause = $where_clause & "AND" & %user_id & "<>" & topic_creator
- Cancel the execution of the SQL completely --
IF $user_ID = $topic_starter THEN return
Steve
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
Re: Allowing Extensions to Modify Any Database Query
Yeah, Pony explained it better than I did. It was just an idea to allow extensions the ability to execute code or add/modify database queries any place there is activity with the database. I don't know how useful this would be overall.
- nickvergessen
- Former Team Member
- Posts: 733
- Joined: Sun Oct 07, 2007 11:54 am
- Location: Stuttgart, Germany
- Contact:
Re: Allowing Extensions to Modify Any Database Query
That is somewhat impossible. What if 2 Pull Requests add queries, they create a conflict and one needs to be rebased.BondGamer wrote:What if every database query had a unique identity number attached to it?
Also the idea of having a map for the queries somewhere is somewhat scary
Member of the Development-Team — No Support via PM