Prevent multiple custom logs

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
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.
Post Reply
User avatar
Un1matr1x
Registered User
Posts: 48
Joined: Mon Sep 07, 2009 10:18 pm

Prevent multiple custom logs

Post by Un1matr1x »

Hi,

since I had some time and was willing to test 3.1 a2 extension stuff and how to develop an extension by try & error and then I stuck @ the point phpBB-Logs

@ phpbb 3 I just added a line in the constants.php around

Code: Select all

// Log types
define('LOG_ADMIN', 0);
define('LOG_MOD', 1);
define('LOG_CRITICAL', 2);
define('LOG_USERS', 3);
and added a new log type. If define('LOG_FOE', 4); already exists, I increased the number by one and it's all fine.

How should this be done in 3.1?
  1. How do I add new constants? Since I'm really new with events, I have to ask stupidly: Do I need a new event for this?
  2. How can I make sure that f.e. anti-spam-mod-logs are not the same log type like my mod?
User avatar
Pony99CA
Registered User
Posts: 986
Joined: Sun Feb 08, 2009 2:35 am
Location: Hollister, CA
Contact:

Re: Prevent multiple custom logs

Post by Pony99CA »

This is why PHP needs an Enum type. :D

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.
User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: Prevent multiple custom logs

Post by nickvergessen »

in my opinion we should just change log_type from int to string and store the mode directly in that column, instead of translating it back and forth
However this might have negative effect on performance, so we should have a look at that aswell while working on a solution.
Member of the Development-TeamNo Support via PM
User avatar
tbackoff
Registered User
Posts: 180
Joined: Sat Jun 12, 2010 3:25 am

Re: Prevent multiple custom logs

Post by tbackoff »

Un1matr1x wrote:How should this be done in 3.1?
  1. How do I add new constants? Since I'm really new with events, I have to ask stupidly: Do I need a new event for this?
I don't have the code in front of me as I'm my work-study, but for the custom tables my extension adds, I global-ed the $table_prefix var and then defined my constants that way. I'll post my code tonight when I get home. It should get you started on defining constants in your extension.
User avatar
tbackoff
Registered User
Posts: 180
Joined: Sat Jun 12, 2010 3:25 am

Re: Prevent multiple custom logs

Post by tbackoff »

Here's the code I used in my listener.php file to get the constants I needed defined.

Code: Select all

public function user_setup($event)
{
    global $table_prefix;
    define('KB_ARTICLES_TABLE', $table_prefix . 'kb_articles');
    define('KB_CATEGORIES_TABLE', $table_prefix . 'kb_categories');

    $this->user->add_lang_ext('tbackoff/knowledgebase', 'kb');
} 
User avatar
Pico88
Registered User
Posts: 73
Joined: Tue Apr 12, 2011 2:32 pm

Re: Prevent multiple custom logs

Post by Pico88 »

It is better not to use global vars in listener.
You can call for tables by using services and tables.

Example:
create table https://github.com/Pico88/phpBB-Reputat ... tables.yml
call it in services https://github.com/Pico88/phpBB-Reputat ... rvices.yml
use in listner https://github.com/Pico88/phpBB-Reputat ... stener.php

If you want to use table in other files, which doesn't call from services, you can use $table_name = $phpbb_container->getParamete('table_name')r f.e. $reputation_table = $phpbb_container->getParameter('tables.reputations');
User avatar
Un1matr1x
Registered User
Posts: 48
Joined: Mon Sep 07, 2009 10:18 pm

Re: Prevent multiple custom logs

Post by Un1matr1x »

Pony99CA wrote:This is why PHP needs an Enum type. :D
Steve
I guess if I want to create a phpBB 3.1 extension with Enum I have to wait a lil' bit too long.
nickvergessen wrote:in my opinion we should just change log_type from int to string and store the mode directly in that column, instead of translating it back and forth
However this might have negative effect on performance, so we should have a look at that aswell while working on a solution.
Would this changes be an option for 3.1 or would this go into 3.2?
I'm not sure how big the performance impact might be on large boards, but could it be really that big?
Pico88 wrote:It is better not to use global vars in listener.
You can call for tables by using services and tables.
Why is it not good to use global vars in listener?
Maybe the correct manner about table creation/use should be defined in the coding guidelines for 3.1 extensions.
User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: Prevent multiple custom logs

Post by nickvergessen »

Un1matr1x wrote:Would this changes be an option for 3.1 or would this go into 3.2?
I'm not sure how big the performance impact might be on large boards, but could it be really that big?
Should be possible for 3.1
Un1matr1x wrote:Why is it not good to use global vars in listener?
Because globals in general are bad.
That's why we use dependency injection. It makes it easier to replace stuff/functionality/objects, for example to test your functions/classes later.
Member of the Development-TeamNo Support via PM
User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

Re: Prevent multiple custom logs

Post by naderman »

nickvergessen wrote:in my opinion we should just change log_type from int to string and store the mode directly in that column, instead of translating it back and forth
However this might have negative effect on performance, so we should have a look at that aswell while working on a solution.
I think strings would be fine, they'll be short enough and can be indexed without too big an impact.
User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: Prevent multiple custom logs

Post by nickvergessen »

so 32 char it is?
Member of the Development-TeamNo Support via PM
Post Reply