diff --git a/ChangeLog b/ChangeLog
index e6d061a58ac..849d8b38855 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -287,7 +287,9 @@ Following changes may create regression for some external modules, but were nece
exists, but if an external module need action on it, it must provides itself its trigger file.
* Use $conf->global->MULTICOMPANY_TRANSVERSE_MODE instead $conf->multicompany->transverse_mode. So, if you set var
$multicompany_transverse_mode to 1 into your conf file, you must remove this line and a new key into
- the Home - setup - other admin page.
+ the Home - setup - other admin page.
+* If you use Multicompany transverse mode, it will be necessary to check the activation of the modules in the children
+ entities and to review completely the rights of the groups and the users.
* Use getEntity('xxx') instead getEntity('xxx', 1) and use getEntity('xxx', 0) instead getEntity('xxx')
* Some other change were done in the way we read permission of a user when module multicompany is enabled. You can
retreive the old behavior by adding constant MULTICOMPANY_BACKWARD_COMPATIBILITY to 1.
diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php
index 7bf283f828d..8a8547a926a 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -366,14 +366,27 @@ if (! GETPOST('action','aZ09') || preg_match('/upgrade/i',GETPOST('action','aZ09
migrate_remise_except_entity($db,$langs,$conf);
}
- // Scripts for last version
- $afterversionarray=explode('.','5.0.9');
- $beforeversionarray=explode('.','6.0.9');
- if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0)
- {
- // No particular code
- }
- }
+ // Scripts for last version
+ $afterversionarray=explode('.','5.0.9');
+ $beforeversionarray=explode('.','6.0.9');
+ if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0)
+ {
+ if (! empty($conf->multicompany->enabled))
+ {
+ global $multicompany_transverse_mode;
+
+ // Only if the transverse mode is not used
+ if (empty($multicompany_transverse_mode))
+ {
+ // Migrate to add entity value into llx_user_rights
+ migrate_user_rights_entity($db, $langs, $conf);
+
+ // Migrate to add entity value into llx_usergroup_rights
+ migrate_usergroup_rights_entity($db, $langs, $conf);
+ }
+ }
+ }
+ }
// Code executed only if migrate is LAST ONE. Must always be done.
if (versioncompare($versiontoarray,$versionranarray) >= 0 || versioncompare($versiontoarray,$versionranarray) <= -3)
@@ -3967,6 +3980,158 @@ function migrate_remise_except_entity($db,$langs,$conf)
print '';
}
+/**
+ * Migrate to add entity value into llx_user_rights
+ *
+ * @param DoliDB $db Database handler
+ * @param Translate $langs Object langs
+ * @param Conf $conf Object conf
+ * @return void
+ */
+function migrate_user_rights_entity($db,$langs,$conf)
+{
+ print '
';
+
+ print ''.$langs->trans('MigrationUserRightsEntity')." \n";
+
+ $error = 0;
+
+ dolibarr_install_syslog("upgrade2::migrate_user_rights_entity");
+
+ $db->begin();
+
+ $sqlSelect = "SELECT u.rowid, u.entity";
+ $sqlSelect.= " FROM ".MAIN_DB_PREFIX."user as u";
+ $sqlSelect.= " WHERE u.entity > 1";
+ //print $sqlSelect;
+
+ $resql = $db->query($sqlSelect);
+ if ($resql)
+ {
+ $i = 0;
+ $num = $db->num_rows($resql);
+
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+
+ $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."user_rights SET";
+ $sqlUpdate.= " entity = " . $obj->entity;
+ $sqlUpdate.= " WHERE fk_user = " . $obj->rowid;
+
+ $result=$db->query($sqlUpdate);
+ if (! $result)
+ {
+ $error++;
+ dol_print_error($db);
+ }
+
+ print ". ";
+ $i++;
+ }
+ }
+ else
+ {
+ print $langs->trans('AlreadyDone')." \n";
+ }
+
+ if (! $error)
+ {
+ $db->commit();
+ }
+ else
+ {
+ $db->rollback();
+ }
+ }
+ else
+ {
+ dol_print_error($db);
+ $db->rollback();
+ }
+
+
+ print ' |
';
+}
+
+/**
+ * Migrate to add entity value into llx_usergroup_rights
+ *
+ * @param DoliDB $db Database handler
+ * @param Translate $langs Object langs
+ * @param Conf $conf Object conf
+ * @return void
+ */
+function migrate_usergroup_rights_entity($db,$langs,$conf)
+{
+ print '';
+
+ print ''.$langs->trans('MigrationUserGroupRightsEntity')." \n";
+
+ $error = 0;
+
+ dolibarr_install_syslog("upgrade2::migrate_usergroup_rights_entity");
+
+ $db->begin();
+
+ $sqlSelect = "SELECT u.rowid, u.entity";
+ $sqlSelect.= " FROM ".MAIN_DB_PREFIX."usergroup as u";
+ $sqlSelect.= " WHERE u.entity > 1";
+ //print $sqlSelect;
+
+ $resql = $db->query($sqlSelect);
+ if ($resql)
+ {
+ $i = 0;
+ $num = $db->num_rows($resql);
+
+ if ($num)
+ {
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+
+ $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."usergroup_rights SET";
+ $sqlUpdate.= " entity = " . $obj->entity;
+ $sqlUpdate.= " WHERE fk_usergroup = " . $obj->rowid;
+
+ $result=$db->query($sqlUpdate);
+ if (! $result)
+ {
+ $error++;
+ dol_print_error($db);
+ }
+
+ print ". ";
+ $i++;
+ }
+ }
+ else
+ {
+ print $langs->trans('AlreadyDone')." \n";
+ }
+
+ if (! $error)
+ {
+ $db->commit();
+ }
+ else
+ {
+ $db->rollback();
+ }
+ }
+ else
+ {
+ dol_print_error($db);
+ $db->rollback();
+ }
+
+
+ print ' |
';
+}
+
/**
* Migration directory
*
diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang
index 4bd1bba3e9a..ed5cdab1b99 100644
--- a/htdocs/langs/en_US/install.lang
+++ b/htdocs/langs/en_US/install.lang
@@ -193,6 +193,8 @@ MigrationCategorieAssociation=Migration of categories
MigrationEvents=Migration of events to add event owner into assignement table
MigrationRemiseEntity=Update entity field value of llx_societe_remise
MigrationRemiseExceptEntity=Update entity field value of llx_societe_remise_except
+MigrationUserRightsEntity=Update entity field value of llx_user_rights
+MigrationUserGroupRightsEntity=Update entity field value of llx_usergroup_rights
MigrationReloadModule=Reload module %s
ShowNotAvailableOptions=Show not available options
HideNotAvailableOptions=Hide not available options