Alex Trofimov 12 лет назад
Родитель
Сommit
4a5ce95d2b

+ 14 - 0
inc/classes/BxDolProfileQuery.php

@@ -219,6 +219,20 @@ class BxDolProfileQuery extends BxDolDb implements iBxDolSingleton
         return $this->query($sSql);
     }
 
+    /**
+     * Reset deleted profile ids and assign system profile ids.
+     * Should be called after profiles module deletion.
+     * It can be called automatically if 
+     * @code
+     * 'process_deleted_profiles' => 1 
+     * @code
+     * is specified in module config.php file in 'uninstall' section.
+     */
+    public function processDeletedProfiles ()
+    {
+        $this->query("UPDATE  `sys_accounts` AS  `a` LEFT OUTER JOIN  `sys_profiles` AS  `p` ON  `a`.`profile_id` =  `p`.`id` SET  `a`.`profile_id` =0 WHERE  `p`.`id` IS NULL"); // reset deleted profiles
+        return $this->query("UPDATE  `sys_accounts` AS  `a` INNER JOIN  `sys_profiles` AS  `p` ON  `a`.`id` =  `p`.`account_id` AND  `p`.`type` =  'system' SET  `a`.`profile_id` =  `p`.`id`"); // assign system profile to reset accounts
+    }
 }
 
 /** @} */

+ 1 - 0
modules/boonex/english/data/langs/system.xml

@@ -1220,6 +1220,7 @@
 	<string name="_adm_txt_modules_password"><![CDATA[Password]]></string>
 	<string name="_adm_txt_modules_path_to_dolphin"><![CDATA[Path to Dolphin's folder]]></string>
 	<string name="_adm_txt_modules_process_action_success"><![CDATA[Done]]></string>
+	<string name="_adm_txt_modules_process_deleted_profiles"><![CDATA[Process deleted profiles:]]></string>
 	<string name="_adm_txt_modules_process_failed"><![CDATA[Failed]]></string>
 	<string name="_adm_txt_modules_process_success"><![CDATA[Done]]></string>
 	<string name="_adm_txt_modules_recompile_alerts"><![CDATA[Recompiling alerts:]]></string>

+ 1 - 0
modules/boonex/persons/install/config.php

@@ -53,6 +53,7 @@ $aConfig = array(
         'execute_sql' => 1,
         'update_languages' => 1,
         'clear_db_cache' => 1,
+        'process_deleted_profiles' => 1,
     ),
     'enable' => array(
         'execute_sql' => 1,

+ 11 - 0
studio/classes/BxDolStudioInstaller.php

@@ -723,6 +723,17 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
 
         return BX_DOL_STUDIO_INSTALLER_SUCCESS;
     }
+	function actionProcessDeletedProfiles($sOperation)
+    {
+        if(!in_array($sOperation, array('install', 'uninstall', 'enable', 'disable'))) 
+        	return BX_DOL_STUDIO_INSTALLER_FAILED;
+
+        bx_import('BxDolProfileQuery');
+        $o = BxDolProfileQuery::getInstance();
+        $o->processDeletedProfiles();
+
+        return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+    }
     function actionRecompileGlobalParamaters($sOperation)
     {
         $bResult = $this->oDb->cacheParamsClear();