Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2007, 07:22 PM
711 711 is offline
 
Join Date: Oct 2006
Location: CT
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Need help with MySQL Query

I would like to run a mysql query to copy the exact forum permissions from one usergroup to another. Ideally, when query is complete, the two usergroups will have identical permissions for all forums and subforums.



I am far from a SQL guru but I maybe my feeble attempt can give some idea of what I would like to do:



usergroupid = 2 {source usergroup whose permissions I would like to copy}

usergroupid = 83 {target usergroup whose permissions I would like to overwrite}



Step 1:

PHP Code:

SELECT forumpermissions FROM forumpermission WHERE usergroupid 
2


Step 2: This is where I am stuck

PHP Code:

UPDATE forumpermission SET forumpermissions 
= {the ones selected aboveWHERE usergroupid 83


Any help would be greatly appreciated.



Thanks!
Reply With Quote
  #2  
Old 11-22-2007, 07:32 PM
WhaLberg's Avatar
WhaLberg WhaLberg is offline
 
Join Date: Nov 2006
Location: Dersaadet
Posts: 569
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
<?php

$query 
$db->query_read("SELECT forumpermissions FROM forumpermission WHERE usergroupid = 2");
$result $db->fetch_array($query);
$secondquery $db->query_write("UPDATE forumpermission SET forumpermissions = " $result['forumpermissions'] . " WHERE usergroupid = 83");

?>
Reply With Quote
  #3  
Old 11-22-2007, 07:38 PM
711 711 is offline
 
Join Date: Oct 2006
Location: CT
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, I should have specified, can you give the code in pure SQL format? I will run the query directly from MySQL query Browser, not within a vBulletin or php script.

Thanks for the quick reply!!!!
Reply With Quote
  #4  
Old 11-22-2007, 10:32 PM
Analogpoint's Avatar
Analogpoint Analogpoint is offline
 
Join Date: Feb 2007
Posts: 656
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Something like this should do: (Back up your board first)
[sql]UPDATE forumpermission as permwrite, forumpermission as permread
SET permwrite.forumpermissions = permread.forumpermissions
WHERE permwrite.usergroupid = 83 AND permread.usergroupid = 2[/sql]

That should change usergroup 83's forum permissions to match usergroup 2's.
Reply With Quote
  #5  
Old 11-22-2007, 10:57 PM
711 711 is offline
 
Join Date: Oct 2006
Location: CT
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That query returns an error.

Even when I try just this:

PHP Code:
UPDATE forumpermissions as permwriteforumpermissions as permread 
or this

PHP Code:
UPDATE forumpermissions as permwrite
All return errors.

I am using MySQL 4.1.22, perhaps 'UPDATE ... AS' is not supported in that version?

I couldn't find reference to that contruction anywhere in the mysql online documentation (not even for mysql 5).

Thanks for trying in any case!

Any ideas?
Reply With Quote
  #6  
Old 11-23-2007, 01:18 PM
Analogpoint's Avatar
Analogpoint Analogpoint is offline
 
Join Date: Feb 2007
Posts: 656
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I tested it on MySQL 5.0.21.

Now, what do you want to do, just update forum permissions one usergroup and make it the same as another one, or do you need to do this for many usergroups?
Reply With Quote
  #7  
Old 11-23-2007, 04:27 PM
711 711 is offline
 
Join Date: Oct 2006
Location: CT
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Analogpoint View Post
I tested it on MySQL 5.0.21.

Now, what do you want to do, just update forum permissions one usergroup and make it the same as another one, or do you need to do this for many usergroups?
I would like to copy all forum permissions from one usergroup (usergroupid = 2) to another (usergroupid = 54).

I need to copy those permissions for several usergroups, but if we can get the query to work successfully on group 54, then I can simply run the query again for the others.
Reply With Quote
  #8  
Old 11-23-2007, 07:07 PM
Analogpoint's Avatar
Analogpoint Analogpoint is offline
 
Join Date: Feb 2007
Posts: 656
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The table is actually `forumpermission` (with no s, my bad). Can you try this again?
[sql]UPDATE forumpermission as permwrite, forumpermission as permread
SET permwrite.forumpermissions = permread.forumpermissions
WHERE permwrite.usergroupid = 83 AND permread.usergroupid = 2[/sql]
Reply With Quote
  #9  
Old 11-25-2007, 08:44 PM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by 711 View Post
That query returns an error.

Any ideas?
One idea, please let us know exactly what error it returns. The more detail you provide, the more help we can provide.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:08 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05106 seconds
  • Memory Usage 2,249KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete