Copy a set of userlevelpermissions to another userlevelid

Tips submitted by PHPMaker users
Post Reply
sticcino
User
Posts: 1043

Copy a set of userlevelpermissions to another userlevelid

Post by sticcino »

use the following script to easily copy one of your user level permissions to another userlevelid

INSERT INTO userlevelpermissions
(userlevelid, tablename, permission)
select
[NEW_userlevelid], tablename, permission
FROM
userlevelpermissions
WHERE
userlevelid = [FROM_userlevelid]

Where:
NEW_userlevelid = the new userlevelid that you want to create
FROM_userlevelid = the existing userlevelid that you want to copy

Example:

INSERT INTO userlevelpermissions
(userlevelid, tablename, permission)
SELECT
101, tablename, permission
FROM
userlevelpermissions
WHERE
userlevelid = 0

This will copy the "Default" userlevelid 0 into a new userlevelid 101

NOTES:

  • don't forget to create the new userlevelid in table: userlevels
  • be careful that the new userlevelid doesn't already exist, this script will not update existing records as there is no unique key in the userlevels table. if you have a custom userlevels table with a unique key, you can look at adding the ON DUPLICATE KEY UPDATE constraint

mishanian
User
Posts: 125

Post by mishanian »

thanks

Post Reply