Some updates (diff)

Synchronizes various aspects of your Roster with your phpBB forum

Moderator: jaffa

Some updates (diff)

Postby trelis » Fri Dec 03, 2010 4:56 pm

Here are the updates/fixes I made to get phpBB Sync working the way I wanted.

My current setup:
phpbb3 3.0.8 (http://www.phpbb.com/)
wowroster SVN 2199 (http://code.google.com/p/wowroster/)
wowroster-addons SVN 520 (http://code.google.com/p/wowroster-addons/)

Changes:
  • Bugfixes (I think the only thing that was working was ranks when I started)
  • Ability to suspend accounts implemented for phpBB3 (it was only implemented for Dragonfly before) (configured in RosterCP)
  • Suspended accounts are re-enabled if they rejoin the guild (only if they were deactivated by this mod, it sets a unique deactivated type in the database)
  • Ability to assign a group that everyone who is in the guild on wowroster gets assigned to and removed from if they disappear from the guild on roster (configured in RosterCP)

None of my changes effect Dragonfly. I only touched phpbb3.

Code: Select all
Index: locale/enUS.php
===================================================================
--- locale/enUS.php   (revision 520)
+++ locale/enUS.php   (working copy)
@@ -52,6 +52,8 @@
 $lang['admin']['forum_type']='Set forum type|Select Dragonfly or phpBB3';
 $lang['admin']['char_field']='Set field for character name|Select the field name to use for character names.<br />Options you could use are username, name (real name in DF), or a user created field.';
 $lang['admin']['default_group']='Set default group|This will set the guild rank group as the default group for that user.<br />This only affects phpBB3.';
+$lang['admin']['guild_assign']='Assign Members to group|Allow phpBBSync to assign members to a group.';
+$lang['admin']['guild_assign_group']='Select a group to put members in|Create a group in your forum to put members in and set permissions accordingly.';
 
 $lang['admin']['use_multirank']='Use the mutirank addon for phpBB forums|Leave fields blank if you don\'t wish to update that rank.<br />Otherwise fill in with either members.[field] or players.[field] <br />depending on which table you wish to draw your data from. <br />Common fields to use might be members.guild_title, members.class, players.race or players.sex.<br />Expect errors if you enable this and don\'t have it installed.';
 $lang['admin']['multirank_1']='Field to use for Rank 1|This is the built in rank and is often used for the post count ranks.<br />Leave blank if you wish to use it for that purpose.';
@@ -79,6 +81,7 @@
 $lang['RankUpdated']='User rank(s) updated';
 $lang['SuspUpdated']='Suspensions updated';
 $lang['GroupUpdated']='Groups updated';
+$lang['AssignUpdated']='Assigned group updated';
 
 $lang['Hearth']='Hearth';
 $lang['Zone']='Zone';
@@ -108,4 +111,4 @@
 /*phpBB Specific Settings*/
 $lang['Stars']='1#star.gif';
 $lang['Suspended']='Suspended'; /*If you want to change your suspended group title, change this.*/
-?>
\ No newline at end of file
+?>
Index: admin/config.func.php
===================================================================
--- admin/config.func.php   (revision 520)
+++ admin/config.func.php   (working copy)
@@ -21,8 +21,8 @@
    global $roster;
    global $addon;
    
-   if($addon['config']['phbb_db']!=''){
-      $phpbbdb=$this->data['config']['phbb_db'].".";
+   if($addon['config']['phpbb_db']!=''){
+      $phpbbdb=$this->data['config']['phpbb_db'].".";
    }else{
       $phpbbdb="";
    }
Index: inc/update_hook.php
===================================================================
--- inc/update_hook.php   (revision 520)
+++ inc/update_hook.php   (working copy)
@@ -75,8 +75,8 @@
       global $roster;
       global $addon;
       
-      if($this->data['config']['phbb_db']!=''){
-         $phpbbdb=$this->data['config']['phbb_db'].".";
+      if($this->data['config']['phpbb_db']!=''){
+         $phpbbdb=$this->data['config']['phpbb_db'].".";
       }else{
          $phpbbdb="";
       }
@@ -146,6 +146,14 @@
                      ";
                }
                if ($this->data['config']['forum_type'] == 1) /*phpBB3*/{
+                  // Add to Forums user_group
+                  // Table with
+                  // All Roster member name = memberlog name
+                  // and All forum username = memberlog name
+                  // and Roster guild title = Forum guild name
+                  // Plus added data:
+                  // All forum groups those users are in
+                  // Where Forum user is not in guild_protected_group
                   $query = "insert into {$phpbbdb}{$this->data['config']['forum_prefix']}user_group (group_id, user_id, group_leader, user_pending)
                       SELECT distinct g.group_id, u.user_id, 0, 0 from {$roster->db->prefix}memberlog ml
                      inner join {$roster->db->prefix}members m on m.name=ml.name
@@ -171,6 +179,81 @@
 
                
             }
+          if ($this->data['config']['guild_assign'] == true){
+             if ($this->data['config']['forum_type'] == 0) /*DF*/{
+               $query="select 'nothing'";
+            }
+            if ($this->data['config']['forum_type'] == 1) /*phpBB3*/{
+               // Remove members from the assigned group if they are no longer in the Guild roster
+
+               // Take Forum users
+               // That are in the assigned group
+               // Compare to roster members
+               // only keep forum members that weren't in roster members
+               // Then make sure they aren't in the guild protected group
+               $query = "SELECT DISTINCT u.user_id, u.username
+                     FROM {$phpbbdb}{$this->data['config']['forum_prefix']}users u
+                     inner join {$phpbbdb}{$this->data['config']['forum_prefix']}user_group ug on ug.group_id={$this->data['config']['guild_assign_group']} and u.user_id = ug.user_id
+                     LEFT JOIN {$roster->db->prefix}members m ON ucase(m.name) = ucase(u.{$this->data['config']['char_field']})
+                     WHERE m.name IS NULL
+                     and u.user_id not in
+                     (select ug1.user_id from {$phpbbdb}{$this->data['config']['forum_prefix']}user_group ug1
+                     where ug1.group_id={$this->data['config']['guild_protected_group']})
+                     ";
+               $result = $roster->db->query ( $query );
+               if( $result && $roster->db->num_rows($result) > 0 )
+               {
+                  $members = $roster->db->fetch_all();
+                  foreach ( $members as $member )
+                  {
+                     $query = "DELETE from {$phpbbdb}{$this->data['config']['forum_prefix']}user_group
+                           where group_id={$this->data['config']['guild_assign_group']}
+                           and user_id={$member['user_id']}
+                           ";
+                     $result = $roster->db->query ( $query );
+                     if ($result) {
+                        $this->messages .= "Remove {$member[$this->data['config']['char_field']]} from assigned group<br>\n";
+                     } else {
+                        $this->messages .= "Delete failed for {$member[$this->data['config']['char_field']]}<br>\n";
+                     }
+                  }
+               }
+
+               // Place all members in assigned group
+
+               // Add to Forums ['config'][guild_assign_group]
+               // Table with
+               // and All forum username = Roster member name
+               // Where Forum user is not in guild_assign_group
+               // Where Forum user is not in guild_protected_group
+               $query = "SELECT distinct u.user_id, u.{$this->data['config']['char_field']} from {$roster->db->prefix}members m
+                     inner join {$phpbbdb}{$this->data['config']['forum_prefix']}users u on ucase(u.{$this->data['config']['char_field']})=ucase(m.name)
+                     where u.user_id not in /*makes sure user is not already in the assigned group or protected group*/
+                        (select ug.user_id from {$phpbbdb}{$this->data['config']['forum_prefix']}user_group ug
+                        where ug.group_id={$this->data['config']['guild_assign_group']}
+                        or ug.group_id={$this->data['config']['guild_protected_group']})
+                     ";
+               $result = $roster->db->query ( $query );
+               if( $result && $roster->db->num_rows($result) > 0 )
+               {
+                  $members = $roster->db->fetch_all();
+                  foreach ( $members as $member )
+                  {
+                     $query = "insert into {$phpbbdb}{$this->data['config']['forum_prefix']}user_group (group_id, user_id, group_leader, user_pending)
+                           values ({$this->data['config']['guild_assign_group']}, {$member['user_id']}, 0, 0)
+                           ";
+                     $result = $roster->db->query ( $query );
+                     if ($result) {
+                        $this->messages .= "Adding {$member[$this->data['config']['char_field']]} to assigned group<br>\n";
+                     } else {
+                        $this->messages .= "Insert failed for {$member[$this->data['config']['char_field']]}<br>\n";
+                     }
+                  }
+               }
+            }
+
+            $this->messages .= "<span class=\"green\">{$roster->locale->act['AssignUpdated']}</span><br />\n";
+         }
       
           //Suspend members after leaving the guild. May have to add in something to unsuspend if they rejoin
          if ($this->data['config']['guild_suspend'] == 1){
@@ -183,12 +266,91 @@
                   and m.name is null
                   and u.user_id not in /*makes sure user is not protected*/
                      (select ug1.user_id from {$phpbbdb}{$this->data['config']['forum_prefix']}bbuser_group ug1 left outer join {$phpbbdb}{$this->data['config']['forum_prefix']}bbgroups g1 on g1.group_id=ug1.group_id where g1.group_id={$this->data['config']['guild_protected_group']})";
+               $result = $roster->db->query ( $query );
             }
             if ($this->data['config']['forum_type'] == 1) /*phpBB3*/{
-               //want to 'deactivate' - need to test how this works.
-                  $query="select 'nothing'";
+               // We only want to move people from type 0 to type 1
+               // type = 0 (normal)
+               // type = 1 (inactive)
+               // type = 2 (ignore)
+               // type = 3 (Found)
+               // We are going to use a custom inactive reason (5), so that we can determine
+               // which accounts this has suspended
+
+               // Take Forum users
+               // Compare to roster members
+               // only keep forum members that weren't in roster members
+               // Check to see that they are currently type normal
+               // Then make sure they aren't in the guild protected group
+               $query = "SELECT DISTINCT u.user_id, u.username
+                     FROM {$phpbbdb}{$this->data['config']['forum_prefix']}users u
+                     LEFT JOIN {$roster->db->prefix}members m ON ucase( m.name ) = ucase( u.username )
+                     WHERE m.name IS NULL
+                     AND u.user_type =0
+                     AND u.user_id NOT IN (
+                     SELECT ug.user_id
+                     FROM {$phpbbdb}{$this->data['config']['forum_prefix']}user_group ug
+                     WHERE ug.group_id ={$this->data['config']['guild_protected_group']})
+                     ";
+
+               $result = $roster->db->query ( $query );
+
+               if( $result && $roster->db->num_rows($result) > 0 )
+               {
+                  $members = $roster->db->fetch_all();
+                  foreach ( $members as $member )
+                  {
+                     $time = time();
+                     $query = "UPDATE {$phpbbdb}{$this->data['config']['forum_prefix']}users SET
+                        user_type=1,
+                        user_inactive_reason=5,
+                        user_inactive_time='{$time}'
+                        where user_id={$member['user_id']}
+                        ";
+                     $result = $roster->db->query ( $query );
+                     if ($result) {
+                        $this->messages .= "Suspended {$member[$this->data['config']['char_field']]}<br>\n";
+                     } else {
+                        $this->messages .= "Suspend failed for {$member[$this->data['config']['char_field']]}<br>\n";
+                     }
+                  }
+               }
+
+               // Re-enable any accounts we have suspended
+               // This only touches accounts with inactive_reason=5 (not used by base phpbb3 at least)
+               $query = " SELECT distinct u.user_id, u.username from {$roster->db->prefix}members m
+                     inner join {$phpbbdb}{$this->data['config']['forum_prefix']}users u on ucase(u.username)=ucase(m.name)
+                     where u.user_type=1
+                     AND u.user_inactive_reason=5
+                     AND u.user_id NOT IN (
+                     SELECT ug.user_id
+                     FROM {$phpbbdb}{$this->data['config']['forum_prefix']}user_group ug
+                     WHERE ug.group_id =10)
+                     ";
+
+               $result = $roster->db->query ( $query );
+
+               if( $result && $roster->db->num_rows($result) > 0 )
+               {
+                  $members = $roster->db->fetch_all();
+                  foreach ( $members as $member )
+                  {
+                     $time = time();
+                     $query = "UPDATE {$phpbbdb}{$this->data['config']['forum_prefix']}users SET
+                        user_type=0,
+                        user_inactive_reason=0,
+                        user_inactive_time='0'
+                        where user_id={$member['user_id']}
+                        ";
+                     $result = $roster->db->query ( $query );
+                     if ($result) {
+                        $this->messages .= "Activated {$member[$this->data['config']['char_field']]}<br>\n";
+                     } else {
+                        $this->messages .= "Activate failed for {$member[$this->data['config']['char_field']]}<br>\n";
+                     }
+                  }
+               }
             }
-            $result = $roster->db->query ( $query );
             $this->messages .= "<span class=\"green\">{$roster->locale->act['SuspUpdated']}</span><br />\n";
          }
          //Move members to a different group after leaving.
@@ -515,4 +677,4 @@
       return true;
    }
 
-}
\ No newline at end of file
+}
Index: inc/install.def.php
===================================================================
--- inc/install.def.php   (revision 520)
+++ inc/install.def.php   (working copy)
@@ -29,7 +29,7 @@
    var $active = true;
    var $icon = 'phpbb.png';
 
-   var $version = '1.2.0.5';
+   var $version = '1.2.0.6';
    var $wrnet_id = 128;
 
    var $fullname = 'phpbbsync';
@@ -82,6 +82,8 @@
       $installer->add_config("'1306','guild_protected_group','0','function{getGroups','phpbb_menu_guild'");
       $installer->add_config("'1307','guild_ranks','0','radio{yes^1|no^0','phpbb_menu_guild'");
       $installer->add_config("'1308','default_group','0','radio{yes^1|no^0','phpbb_menu_guild'");      
+      $installer->add_config("'1309','guild_assign','0','radio{yes^1|no^0','phpbb_menu_guild'");
+      $installer->add_config("'1310','guild_assign_group','0','function{getGroups','phpbb_menu_guild'");
       
       $installer->add_config("'1401','use_multirank','0','radio{yes^1|no^0','phpbb_menu_multirank'");
       $installer->add_config("'1402','multirank_1',NULL,'text{1000|30','phpbb_menu_multirank'");
@@ -146,6 +148,11 @@
       {
          $installer->add_config("'1106','phpbb_db','','text{1000|30','phpbb_menu_main'");
       }
+      if( version_compare('1.2.0.6', $oldversion,'>') == true )
+      {
+         $installer->add_config("'1309','guild_assign','0','radio{yes^1|no^0','phpbb_menu_guild'");
+         $installer->add_config("'1310','guild_assign_group','0','function{getGroups','phpbb_menu_guild'");
+      }
       return true;
    }
 
@@ -162,4 +169,4 @@
       $installer->remove_all_menu_button();
       return true;
    }
-}
\ No newline at end of file
+}
trelis
WR.net Apprentice
WR.net Apprentice
 
Posts: 19
Joined: Fri Nov 26, 2010 1:14 pm

Return to phpBB Sync

Who is online

Users browsing this forum: No registered users and 0 guests

cron