{"id":9167,"date":"2024-09-19T08:37:34","date_gmt":"2024-09-19T08:37:34","guid":{"rendered":"https:\/\/www.infinitivehost.com\/knowledge-base\/?p=9167"},"modified":"2024-09-19T10:00:13","modified_gmt":"2024-09-19T10:00:13","slug":"how-to-regenerate-user_privileges-files-easily-in-vtiger","status":"publish","type":"post","link":"https:\/\/www.infinitivehost.com\/knowledge-base\/how-to-regenerate-user_privileges-files-easily-in-vtiger\/","title":{"rendered":"How to Regenerate user_privileges Files Easily in vTiger"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 2,076<\/span><span class='epvc-label'> Views<\/span><\/div>\n<p class=\"wp-block-paragraph\">In <strong>vTiger CRM<\/strong>, the <code>user_privileges<\/code> files store the access permissions for each user. If these files become corrupted or you need to regenerate user_privileges Files (for example, after updating roles or profiles), you can do so through the following methods:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>Using vTiger&#8217;s Recalculate Permissions Option<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The simplest way to regenerate <code>user_privileges<\/code> files is through the <strong>Recalculate Permissions<\/strong> option in the UI.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Steps:<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Go to CRM Settings<\/strong>:<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>From the vTiger dashboard, click on the <strong>gear icon<\/strong> in the top-right corner to access <strong>CRM Settings<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">    2. <strong>Navigate to User Management<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Under the <strong>Users &amp; Access Control<\/strong> section, click on <strong>Users<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">    3. <strong>Recalculate Permissions<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Select the user whose privileges need to be recalculated.<\/li>\n\n\n\n<li>In the user detail view, you&#8217;ll see an option to <strong>Recalculate Permissions<\/strong> (typically near the bottom of the page).<\/li>\n\n\n\n<li>Click on this option to regenerate the privileges file for the user.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>Manually Regenerate the Privileges Files<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If the above method doesn&#8217;t work or you want to regenerate the files for all users, you can do it programmatically.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Steps:<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Access vTiger Directory<\/strong>:<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Navigate to your <strong>vTiger CRM<\/strong> installation directory on the server, usually under <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">public_html<\/mark><\/code>, or wherever the CRM files are stored.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">    2. <strong>Run the PHP Script to Regenerate Files<\/strong>:<br>You can use vTiger&#8217;s built-in function to regenerate <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">user_privileges<\/mark><\/code> files for all users.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the file <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">includes\/utils\/UserInfoUtil.php<\/mark><\/code>.<\/li>\n\n\n\n<li>Find the function <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">createUserPrivilegesfile($userId)<\/mark><\/code>. This function is responsible for generating the user privileges file for a specific user. To regenerate the files for all users, you can write a small script to loop through the users and regenerate their privileges.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">include_once('includes\/utils\/UserInfoUtil.php');\n   global $adb;\n\n   $result = $adb-&gt;pquery(\"SELECT id FROM vtiger_users WHERE status = ?\", array('Active'));\n   while ($row = $adb-&gt;fetch_array($result)) {\n       $userId = $row&#91;'id'];\n       createUserPrivilegesfile($userId);  \/\/ Regenerate privileges for this user\n       echo \"Regenerated user_privileges for user: \" . $userId . \"\\n\";\n   }<\/mark><\/code><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Save this script as <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">regenerate_privileges.php<\/mark><\/code> and upload it to the root directory of your vTiger installation.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">     3. <strong>Run the Script<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the script in your browser by visiting <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">http:\/\/yourdomain.com\/vtigercrm\/regenerate_privileges.php<\/mark><\/code>.<\/li>\n\n\n\n<li>The script will loop through all active users and regenerate the <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">user_privileges<\/mark><\/code> files.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">    4. <strong>Delete the Script<\/strong>:<br>After successfully regenerating the files, delete the script from the server for security reasons.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Regenerating for Specific Users via Code<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to regenerate the <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">user_privileges<\/mark><\/code> files for a specific user via code:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log in to your server.<\/li>\n\n\n\n<li>Execute the following PHP code in the vTiger CRM environment:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">include_once('includes\/utils\/UserInfoUtil.php');\n   $userId = 1; \/\/ Replace with the ID of the user you want to regenerate\n   createUserPrivilegesfile($userId);<\/mark><\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will force the system to recreate the <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">user_privileges<\/mark><\/code> file for that specific user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>Regenerating via SQL (For Advanced Users)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If the above methods fail and you&#8217;re familiar with SQL, you can delete specific entries related to user privileges and let the system regenerate them the next time the user logs in.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">DELETE FROM vtiger_user2role WHERE userid = '1';  \/\/ Replace '1' with the user's ID.<\/mark><\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure you have a backup before performing SQL operations directly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Conclusion<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In\u00a0the case of vTiger CRM, the user_privileges files store the access permissions for every single user. If all these files become automatically ruined or you want to regenerate user_privileges files (for instance, after updating profiles or roles), you can do it with the help of the above-mentioned methods by having the <a href=\"https:\/\/www.infinitivehost.com\/managed-vtiger-solutions\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\"><strong>best Vtiger hosting solutions<\/strong><\/mark><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2,076 Views In vTiger CRM, the user_privileges files store the access permissions for each user. If these files become corrupted or you need to regenerate user_privileges Files (for example, after updating roles or profiles), you can do so through the following methods: 1. Using vTiger&#8217;s Recalculate Permissions Option The simplest way to regenerate user_privileges files [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[204],"tags":[],"class_list":["post-9167","post","type-post","status-publish","format-standard","hentry","category-vtiger-solutions"],"_links":{"self":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=9167"}],"version-history":[{"count":2,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9167\/revisions"}],"predecessor-version":[{"id":9172,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9167\/revisions\/9172"}],"wp:attachment":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=9167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=9167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=9167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}