Browse Source

#2021 - Accounts pruning if there are no attached profiles

RomanL 4 years ago
parent
commit
9da4dd05ca

+ 19 - 0
inc/classes/BxDolAccount.php

@@ -773,6 +773,25 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
 
         return CHECK_ACTION_RESULT_ALLOWED;
     }
+    
+    static public function pruning ()
+    {
+        $iCount = 0;
+        
+        if (getParam('sys_account_accounts_pruning_interval') != 0){
+            $oAccountQuery = BxDolAccountQuery::getInstance();
+            $iTime = time() - getParam('sys_account_accounts_pruning_interval') * 86400;
+            $aAccounts = $oAccountQuery->getAccountsForPruning($iTime);
+            foreach ($aAccounts as $k => $aAccount) {
+                $oAccount = BxDolAccount::getInstance($aAccount['id']);
+                if(!$oAccount->isConfirmed() && $oAccount->getDisplayName() != 'Robot'){
+                    $iCount++;
+                    $oAccount->delete(true);
+                }
+            }
+        }
+        return $iCount;
+    }
 
 }
 

+ 16 - 0
inc/classes/BxDolAccountQuery.php

@@ -373,6 +373,22 @@ class BxDolAccountQuery extends BxDolDb implements iBxDolSingleton
         $sQuery = "SELECT `c`.`id` AS `content_id`, `p`.`account_id`, `p`.`id` AS `profile_id`, `p`.`status` AS `profile_status` FROM `sys_accounts` AS `c` INNER JOIN `sys_profiles` AS `p` ON (`p`.`content_id` = `c`.`id` AND `p`.`type` = :system) WHERE `p`.`status` = :status AND (0 $sWhere) ORDER BY `added` DESC LIMIT :limit";
         return $this->getAll($sQuery, $aBindings);
     }
+    
+    public function getAccountsForPruning($iAdded)
+    {
+        $aBindings = array(
+    		'added' => $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
+        ";
+        
+        return $this->getAll($sQuery, $aBindings);
+    }
 }
 
 /** @} */

+ 5 - 2
inc/classes/BxDolCronPruning.php

@@ -40,7 +40,7 @@ class BxDolCronPruning extends BxDolCron
         $oAcl = BxDolAcl::getInstance();
         $iDeleteMemLevels = $oAcl ? $oAcl->maintenance() : 0;
 
-        //--- Clean sessions ---//
+        // clean sessions
         $oSession = BxDolSession::getInstance();
         $iSessions = $oSession ? $oSession->maintenance() : 0;
 
@@ -50,11 +50,14 @@ class BxDolCronPruning extends BxDolCron
         // clean outdated transcoded images
         $iDeletedTranscodedImages = BxDolTranscoderImage::pruning();
 
+        // clean accounts without profiles
+        $iDeletedAccounts = BxDolAccount::pruning();
+        
         // clean expired keys
         $oKey = BxDolKey::getInstance();
         $iDeletedKeys = $oKey ? $oKey->prune() : 0;
 
-        echo _t('_sys_pruning_db', $iDeleteMemLevels, $iSessions, $iDeletedKeys, $iDeletedExpiredTokens, $iDeletedTranscodedImages);
+        echo _t('_sys_pruning_db', $iDeleteMemLevels, $iSessions, $iDeletedKeys, $iDeletedExpiredTokens, $iDeletedTranscodedImages, $iDeletedAccounts);
     }
 
     /**

+ 2 - 1
install/sql/system.sql

@@ -557,8 +557,9 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_account_disable_login_form', '_adm_stg_cpt_option_sys_account_disable_login_form', '', 'checkbox', '', '', '', 40),
 (@iCategoryId, 'sys_account_disable_join_form', '_adm_stg_cpt_option_sys_account_disable_join_form', '', 'checkbox', '', '', '', 42),
 
-(@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);
 --
 -- CATEGORY: ACL
 --

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

@@ -1522,6 +1522,7 @@
     <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_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_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_edit"><![CDATA[Edit profile page]]></string>
@@ -3294,6 +3295,7 @@ If it is not enabled then please consider implement this optimization, since it
             <li><b>{2}</b> deleted expired keys</li>
             <li><b>{3}</b> deleted expired storage tokens</li>
             <li><b>{4}</b> deleted outdated transcoded images</li>
+            <li><b>{5}</b> deleted accounts without profiles</li>
         </ul>]]></string>
     <string name="_sys_pruning_files"><![CDATA[<h3>Files pruning:</h3>
         <ul>

+ 3 - 1
modules/boonex/russian/data/langs/system/ru.xml

@@ -1511,7 +1511,8 @@
     <string name="_adm_stg_cpt_option_sys_account_reset_password_redirect_custom"><![CDATA[URL для перенаправления 'Пользовательская страница']]></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_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_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_add_nofollow"><![CDATA[Добавить атрибут "nofollow" для внешних ссылок]]></string>
@@ -3258,6 +3259,7 @@
             <li><b>{2}</b> удалено просроченных ключей</li>
             <li><b>{3}</b> удалено просроченных токенов хранилища</li>
             <li><b>{4}</b> удалено просроченных транскодированных изображений</li>
+            <li><b>{5}</b> удалено аккаунтов без профайлов</li>
         </ul>]]></string>
     <string name="_sys_pruning_files"><![CDATA[<h3>Очистка Файлов:</h3>
         <ul>