Sfoglia il codice sorgente

#2021 - Accounts pruning if there are no attached profiles

RomanL 4 anni fa
parent
commit
735aad5b0c

+ 45 - 7
inc/classes/BxDolAccount.php

@@ -777,19 +777,57 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
     static public function pruning ()
     static public function pruning ()
     {
     {
         $iCount = 0;
         $iCount = 0;
+        $iTime = time() - getParam('sys_account_accounts_pruning_interval') * 86400;
+        $oAccountQuery = BxDolAccountQuery::getInstance();
+        $aAccounts = [];
+        $bSuspend = false;
         
         
-        if (getParam('sys_account_accounts_pruning_interval') != 0){
-            $oAccountQuery = BxDolAccountQuery::getInstance();
-            $iTime = time() - getParam('sys_account_accounts_pruning_interval') * 86400;
-            $aAccounts = $oAccountQuery->getAccountsForPruning($iTime);
+        switch(getParam('sys_account_accounts_pruning')) {
+ 
+            case 'no_login_delete':
+                $aAccounts = $oAccountQuery->getAccountsForPruning('no_login', $iTime);   
+                break;
+            
+            case 'no_login_suspend':
+                $bSuspend = true;
+                $aAccounts = $oAccountQuery->getAccountsForPruning('no_login', $iTime);   
+                break;  
+                
+    		case 'no_confirm_delete':
+                $aAccounts = $oAccountQuery->getAccountsForPruning('no_confirm', $iTime);
+                foreach ($aAccounts as $k => $aAccount) {
+                    $oAccount = BxDolAccount::getInstance($aAccount['id']);
+                    if($oAccount->isConfirmed()){
+                        unset($aAccounts[$k]);
+                    }
+                }
+                break;
+                
+            case 'no_profile_delete':
+                $aAccounts = $oAccountQuery->getAccountsForPruning('no_profile', $iTime);
+                break;
+        }
+
+        if ($bSuspend){
             foreach ($aAccounts as $k => $aAccount) {
             foreach ($aAccounts as $k => $aAccount) {
                 $oAccount = BxDolAccount::getInstance($aAccount['id']);
                 $oAccount = BxDolAccount::getInstance($aAccount['id']);
-                if(!$oAccount->isConfirmed() && $oAccount->getDisplayName() != 'Robot'){
-                    $iCount++;
-                    $oAccount->delete(true);
+                $oProfile = BxDolProfile::getInstanceAccountProfile($aAccount['id']);
+                $oProfile->suspend(BX_PROFILE_ACTION_AUTO, 0 ,false);
+                $aProfiles = $oAccount->getProfiles();
+                foreach($aProfiles as $aProfile){
+                    BxDolProfile::getInstance($aProfile['id'])->suspend(BX_PROFILE_ACTION_AUTO, 0 ,false);
                 }
                 }
+                $iCount++;
+            }
+        }
+        else{
+            foreach ($aAccounts as $k => $aAccount) {
+                $oAccount = BxDolAccount::getInstance($aAccount['id']);
+                $oAccount->delete(false);
+                $iCount++;
             }
             }
         }
         }
+
         return $iCount;
         return $iCount;
     }
     }
 
 

+ 22 - 8
inc/classes/BxDolAccountQuery.php

@@ -374,18 +374,32 @@ class BxDolAccountQuery extends BxDolDb implements iBxDolSingleton
         return $this->getAll($sQuery, $aBindings);
         return $this->getAll($sQuery, $aBindings);
     }
     }
     
     
-    public function getAccountsForPruning($iAdded)
+    public function getAccountsForPruning($sMode, $iAdded)
     {
     {
         $aBindings = array(
         $aBindings = array(
-    		'added' => $iAdded,
+    		'date_limit' => $iAdded,
     	);
     	);
         
         
-        $sQuery = "SELECT `sys_accounts`.`id`, COUNT(`sys_profiles`.`id`) AS `profiles_count` FROM `sys_accounts`
-        INNER  JOIN `sys_profiles` ON `sys_accounts`.`id` = `sys_profiles`.`account_id`
-        WHERE `added` < :added
-        GROUP BY `sys_profiles`.`account_id`
-        HAVING COUNT(`sys_profiles`.`id`) = 1
-        ";
+        $sQuery = '';
+        
+        switch($sMode) {
+    		case 'no_profile':
+    			$sQuery = "SELECT `sys_accounts`.`id`, COUNT(`sys_profiles`.`id`) AS `profiles_count` FROM `sys_accounts`
+                INNER  JOIN `sys_profiles` ON `sys_accounts`.`id` = `sys_profiles`.`account_id`
+                WHERE `added` < :date_limit AND name <> 'Robot'
+                GROUP BY `sys_profiles`.`account_id`
+                HAVING COUNT(`sys_profiles`.`id`) = 1 ";
+    			break;
+                
+            case 'no_login':
+    			$sQuery = "SELECT `sys_accounts`.`id` FROM `sys_accounts` WHERE `logged` < :date_limit AND `added` < :date_limit  AND name <> 'Robot' ";
+    			break;
+                
+            case 'no_confirm':
+    			$sWhereClause = "SELECT `sys_accounts`.`id` FROM `sys_accounts` WHERE `added` < :date_limit AND (phone_confirmed = 0 OR email_confirmed = 0) AND name <> 'Robot'";
+    			break;
+    	}
+        
         
         
         return $this->getAll($sQuery, $aBindings);
         return $this->getAll($sQuery, $aBindings);
     }
     }

+ 2 - 1
install/sql/system.sql

@@ -559,7 +559,8 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 
 
 (@iCategoryId, 'sys_account_allow_plus_in_email', '_adm_stg_cpt_option_sys_allow_plus_in_email', 'on', 'checkbox', '', '', '', 50),
 (@iCategoryId, 'sys_account_allow_plus_in_email', '_adm_stg_cpt_option_sys_allow_plus_in_email', 'on', 'checkbox', '', '', '', 50),
 
 
-(@iCategoryId, 'sys_account_accounts_pruning_interval', '_adm_stg_cpt_option_sys_accounts_pruning_interval', '0', 'digit', '', '', '', 55);
+(@iCategoryId, 'sys_account_accounts_pruning', '_adm_stg_cpt_option_sys_accounts_pruning', 'no', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:28:"get_options_pruning_interval";s:5:"class";s:18:"BaseServiceAccount";}', '', '', 55),
+(@iCategoryId, 'sys_account_accounts_pruning_interval', '_adm_stg_cpt_option_sys_accounts_pruning_interval', '0', 'digit', '', '', '', 56);
 --
 --
 -- CATEGORY: ACL
 -- CATEGORY: ACL
 --
 --

+ 11 - 2
modules/boonex/english/data/langs/system/en.xml

@@ -1522,7 +1522,16 @@
     <string name="_adm_stg_cpt_option_sys_account_disable_login_form"><![CDATA[Disable login form]]></string>
     <string name="_adm_stg_cpt_option_sys_account_disable_login_form"><![CDATA[Disable login form]]></string>
     <string name="_adm_stg_cpt_option_sys_account_disable_join_form"><![CDATA[Disable join form]]></string>
     <string name="_adm_stg_cpt_option_sys_account_disable_join_form"><![CDATA[Disable join form]]></string>
     <string name="_adm_stg_cpt_option_sys_allow_plus_in_email"><![CDATA[Allow to use plus sign ("+") in email address]]></string>
     <string name="_adm_stg_cpt_option_sys_allow_plus_in_email"><![CDATA[Allow to use plus sign ("+") in email address]]></string>
-    <string name="_adm_stg_cpt_option_sys_accounts_pruning_interval"><![CDATA[Delete accounts which didn't created any profiles and didn't confirm their email for N days (0 - do not delete)]]></string>
+    <string name="_adm_stg_cpt_option_sys_accounts_pruning"><![CDATA[Accounts pruning]]></string>
+    <string name="_adm_stg_cpt_option_sys_accounts_pruning_interval"><![CDATA[Accounts pruning period (in days)
+]]></string>
+    
+    <string name="_adm_stg_cpt_option_value_sys_account_pruning_no"><![CDATA[No pruning]]></string>
+    <string name="_adm_stg_cpt_option_value_sys_account_pruning_no_login_delete"><![CDATA[Delete accounts with no login for N days]]></string>
+    <string name="_adm_stg_cpt_option_value_sys_account_pruning_no_login_suspend"><![CDATA[Suspend accounts with no login for N days]]></string>
+    <string name="_adm_stg_cpt_option_value_sys_account_pruning_no_confirm_delete"><![CDATA[Delete accounts which didn't confirm email for N days]]></string>
+    <string name="_adm_stg_cpt_option_value_sys_account_pruning_no_profile_delete"><![CDATA[Delete account which didn't created any profiles for N days]]></string>
+    
     <string name="_adm_stg_cpt_option_value_sys_account_reset_password_redirect_home"><![CDATA[Home page]]></string>
     <string name="_adm_stg_cpt_option_value_sys_account_reset_password_redirect_home"><![CDATA[Home page]]></string>
     <string name="_adm_stg_cpt_option_value_sys_account_reset_password_redirect_profile"><![CDATA[View profile page]]></string>
     <string name="_adm_stg_cpt_option_value_sys_account_reset_password_redirect_profile"><![CDATA[View profile page]]></string>
     <string name="_adm_stg_cpt_option_value_sys_account_reset_password_redirect_profile_edit"><![CDATA[Edit profile page]]></string>
     <string name="_adm_stg_cpt_option_value_sys_account_reset_password_redirect_profile_edit"><![CDATA[Edit profile page]]></string>
@@ -3295,7 +3304,7 @@ If it is not enabled then please consider implement this optimization, since it
             <li><b>{2}</b> deleted expired keys</li>
             <li><b>{2}</b> deleted expired keys</li>
             <li><b>{3}</b> deleted expired storage tokens</li>
             <li><b>{3}</b> deleted expired storage tokens</li>
             <li><b>{4}</b> deleted outdated transcoded images</li>
             <li><b>{4}</b> deleted outdated transcoded images</li>
-            <li><b>{5}</b> deleted accounts without profiles</li>
+            <li><b>{5}</b> deleted/suspented accounts</li>
         </ul>]]></string>
         </ul>]]></string>
     <string name="_sys_pruning_files"><![CDATA[<h3>Files pruning:</h3>
     <string name="_sys_pruning_files"><![CDATA[<h3>Files pruning:</h3>
         <ul>
         <ul>

+ 10 - 2
modules/boonex/russian/data/langs/system/ru.xml

@@ -1512,7 +1512,15 @@
     <string name="_adm_stg_cpt_option_sys_account_disable_login_form"><![CDATA[Скрыть форму авторизации]]></string>
     <string name="_adm_stg_cpt_option_sys_account_disable_login_form"><![CDATA[Скрыть форму авторизации]]></string>
     <string name="_adm_stg_cpt_option_sys_account_disable_join_form"><![CDATA[Скрыть форму регистрации]]></string>
     <string name="_adm_stg_cpt_option_sys_account_disable_join_form"><![CDATA[Скрыть форму регистрации]]></string>
     <string name="_adm_stg_cpt_option_sys_allow_plus_in_email"><![CDATA[Разрешить использование знака плюс ("+") в адресе электронной почты]]></string>
     <string name="_adm_stg_cpt_option_sys_allow_plus_in_email"><![CDATA[Разрешить использование знака плюс ("+") в адресе электронной почты]]></string>
-    <string name="_adm_stg_cpt_option_sys_accounts_pruning_interval"><![CDATA[Удалять учетные записи, которые не создавали профили и не подтверждали свою электронную почту в течение N дней (0 - не удалять)]]></string>
+    <string name="_adm_stg_cpt_option_sys_accounts_pruning"><![CDATA[Удалять учетные записи]]></string>
+    <string name="_adm_stg_cpt_option_sys_accounts_pruning_interval"><![CDATA[Период удаления учетных записей (в днях)]]></string>
+    
+    <string name="_adm_stg_cpt_option_value_sys_account_pruning_no"><![CDATA[Не удалять]]></string>
+    <string name="_adm_stg_cpt_option_value_sys_account_pruning_no_login_delete"><![CDATA[Удалить учетные записи без входа в течение N дней]]></string>
+    <string name="_adm_stg_cpt_option_value_sys_account_pruning_no_login_suspend"><![CDATA[Приостановить учетные записи без входа в систему на N дней]]></string>
+    <string name="_adm_stg_cpt_option_value_sys_account_pruning_no_confirm_delete"><![CDATA[Удалить учетные записи, которые не подтверждали электронную почту в течение N дней]]></string>
+    <string name="_adm_stg_cpt_option_value_sys_account_pruning_no_profile_delete"><![CDATA[Удалить учетную запись, которая не создавала ни одного профиля в течение N дней]]></string>
+    
     <string name="_adm_stg_cpt_option_sys_acl_expire_notification_days"><![CDATA[За сколько дней до окончания членства оповестить пользователя об окончании (-1 = после окончания)]]></string>
     <string name="_adm_stg_cpt_option_sys_acl_expire_notification_days"><![CDATA[За сколько дней до окончания членства оповестить пользователя об окончании (-1 = после окончания)]]></string>
     <string name="_adm_stg_cpt_option_sys_acl_expire_notify_once"><![CDATA[Оповещать пользователей об окончании членства только одинажды (каждый день в противном случае)]]></string>
     <string name="_adm_stg_cpt_option_sys_acl_expire_notify_once"><![CDATA[Оповещать пользователей об окончании членства только одинажды (каждый день в противном случае)]]></string>
     <string name="_adm_stg_cpt_option_sys_add_nofollow"><![CDATA[Добавить атрибут "nofollow" для внешних ссылок]]></string>
     <string name="_adm_stg_cpt_option_sys_add_nofollow"><![CDATA[Добавить атрибут "nofollow" для внешних ссылок]]></string>
@@ -3259,7 +3267,7 @@
             <li><b>{2}</b> удалено просроченных ключей</li>
             <li><b>{2}</b> удалено просроченных ключей</li>
             <li><b>{3}</b> удалено просроченных токенов хранилища</li>
             <li><b>{3}</b> удалено просроченных токенов хранилища</li>
             <li><b>{4}</b> удалено просроченных транскодированных изображений</li>
             <li><b>{4}</b> удалено просроченных транскодированных изображений</li>
-            <li><b>{5}</b> удалено аккаунтов без профайлов</li>
+            <li><b>{5}</b> удалено/заблокировано аккаунтов</li>
         </ul>]]></string>
         </ul>]]></string>
     <string name="_sys_pruning_files"><![CDATA[<h3>Очистка Файлов:</h3>
     <string name="_sys_pruning_files"><![CDATA[<h3>Очистка Файлов:</h3>
         <ul>
         <ul>

+ 11 - 0
template/scripts/BxBaseServiceAccount.php

@@ -356,6 +356,17 @@ class BxBaseServiceAccount extends BxDol
 
 
         return $aResult;
         return $aResult;
     }
     }
+    
+    public function serviceGetOptionsPruningInterval()
+    {
+        $aResult = array();
+
+        $aChoices = array('no', 'no_login_delete', 'no_login_suspend', 'no_confirm_delete', 'no_profile_delete');
+        foreach($aChoices as $sChoice) 
+            $aResult[] = array('key' => $sChoice, 'value' => _t('_adm_stg_cpt_option_value_sys_account_pruning_' . $sChoice));
+
+        return $aResult;
+    }
             
             
     /**
     /**
      * @page service Service Calls
      * @page service Service Calls