Sfoglia il codice sorgente

Ticket #4829 - Execute 'delete account with content' in background.

AntonLV 1 anno fa
parent
commit
ebae8171cc

+ 11 - 1
inc/classes/BxDolAccount.php

@@ -740,9 +740,13 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
     /**
      * Delete profile.
      * @param $bDeleteWithContent - delete associated profiles with all its contents
+     * @param $bScheduled - delete account using background jobs.
      */
-    function delete($bDeleteWithContent = false)
+    function delete($bDeleteWithContent = false, $bScheduled = false)
     {
+        if ($bScheduled)
+            return BxDolBackgroundJobs::getInstance()->add('account_delete_' . $this->_iAccountID, ['system', 'account_delete', [$this->_iAccountID, $bDeleteWithContent], 'TemplServiceAccount']);
+
         $aAccountInfo = $this->_oQuery->getInfoById($this->_iAccountID);
         if (!$aAccountInfo)
             return false;
@@ -822,6 +826,12 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
 
         $this->isNeedChangePassword(false, $oInformer);
     }
+    
+    public function addInformerDeletionScheduled($oInformer)
+    {
+        if(BxDolBackgroundJobs::getInstance()->exists('account_delete_' . $this->_iAccountID))
+            $oInformer->add('sys-account-deletion-scheduled', _t('_sys_txt_account_deletion_scheduled'), BX_INFORMER_ALERT);
+    }
 
     /**
      * Get unsubscribe link for the specified mesage type

+ 10 - 0
inc/classes/BxDolBackgroundJobs.php

@@ -68,6 +68,16 @@ class BxDolBackgroundJobs  extends BxDolFactory implements iBxDolSingleton
         return true;
     }
 
+    public function exists($sName)
+    {
+        $aJob = $this->_oQuery->getJobs([
+            'sample' => 'name', 
+            'name' => $sName
+        ]);
+
+        return !empty($aJob) && is_array($aJob);
+    }
+
     public function process($mixedJob)
     {
         if(!empty($mixedJob) && !is_array($mixedJob))

+ 6 - 3
modules/base/profile/classes/BxBaseModProfilePageEntry.php

@@ -90,9 +90,9 @@ class BxBaseModProfilePageEntry extends BxBaseModGeneralPageEntry
         $this->addMarkers(array('display_name' => $this->_oProfile->getDisplayName())); // profile display name
         $this->addMarkers(array('profile_link' => $this->_oProfile->getUrl())); // profile link
 
-        $aInformers = array ();
-        $oInformer = BxDolInformer::getInstance($this->_oTemplate);
-        if($oInformer) {
+        if(($oInformer = BxDolInformer::getInstance($this->_oTemplate))) {
+            $aInformers = [];
+
             // display message to profile author if profile isn't active
             if ($bLoggedOwner && !empty($CNF['INFORMERS']['status'])) {
                 $sStatus = $this->_aContentInfo['profile_status'];
@@ -118,6 +118,9 @@ class BxBaseModProfilePageEntry extends BxBaseModGeneralPageEntry
             if ($aInformers)
                 foreach ($aInformers as $a)
                     $oInformer->add($a['name'], $this->_replaceMarkers($a['msg']), $a['type']);
+
+            if($bLoggedOwner || $bLoggedModerator)
+                $this->_oProfile->getAccountObject()->addInformerDeletionScheduled($oInformer);
         }
 
         // display message if it is possible to switch to this profile

+ 1 - 1
modules/boonex/accounts/classes/BxAccntGridAdministration.php

@@ -672,7 +672,7 @@ class BxAccntGridAdministration extends BxBaseModProfileGridAdministration
 
     protected function _doDelete($iId, $aParams = [])
     {
-        return BxDolBackgroundJobs::getInstance()->add('account_delete_' . $iId, ['system', 'account_delete', [$iId, isset($aParams['with_content']) && $aParams['with_content'] === true], 'TemplServiceAccount']);
+        return ($oAccount = BxDolAccount::getInstance($iId)) !== false && $oAccount->delete(isset($aParams['with_content']) && $aParams['with_content'] === true, true);
     }
 
     protected function _addJsCss()

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

@@ -3909,6 +3909,7 @@ If it is not enabled then please consider implement this optimization, since it
     <string name="_sys_txt_account_profile_system"><![CDATA[Please <a href="{0}">create a profile</a> to start using the site.]]></string>
     <string name="_sys_txt_account_need_to_change_password"><![CDATA[Your password has been expired. Please <a href="{0}">change your password</a>.]]></string>
     <string name="_sys_txt_account_cannot_delete"><![CDATA[Cannot delete the only Operator account]]></string>
+    <string name="_sys_txt_account_deletion_scheduled"><![CDATA[Account deletion was scheduled and would be done in a few minutes.]]></string>
     
     <string name="_sys_txt_captcha_not_available"><![CDATA[CAPTCHA not available]]></string>
     <string name="_sys_txt_categories_button_caption_add"><![CDATA[Add]]></string>

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

@@ -3844,6 +3844,7 @@
     <string name="_sys_txt_account_profile_system"><![CDATA[Пожалуйста, <a href="{0}">создайте профиль</a>, чтобы начать пользоваться сайтом.]]></string>
     <string name="_sys_txt_account_need_to_change_password"><![CDATA[Ваш пароль устарел. Пожалуйста <a href="{0}">измените Ваш пароль</a>.]]></string>
     <string name="_sys_txt_account_cannot_delete"><![CDATA[Невозможно удалить единственную учетную запись оператора.]]></string>
+    <string name="_sys_txt_account_deletion_scheduled"><![CDATA[Удаление аккаунта запланировано и будет выполнено через несколько минут.]]></string>
 
     <string name="_sys_txt_captcha_not_available"><![CDATA[CAPTCHA недоступна]]></string>
     <string name="_sys_txt_change_image"><![CDATA[Изменить картинку]]></string>

+ 3 - 5
template/scripts/BxBaseAccountForms.php

@@ -267,18 +267,16 @@ class BxBaseAccountForms extends BxDolProfileForms
             unset($aAccountInfo['password']);
 
         $oForm->initChecker($aAccountInfo);
-
         if (!$oForm->isSubmittedAndValid())
             return $bIsApi ? $oForm->getCodeAPI() : $oForm->getCode();
 
         // delete account
-        $oAccount = BxDolAccount::getInstance($aAccountInfo['id']);
-        if (!$oAccount->delete(false === bx_get('delete_content') ? true : (int)$oForm->getCleanValue('delete_content') != 0))
+        if (($oAccount = BxDolAccount::getInstance($aAccountInfo['id'])) !== false && !$oAccount->delete(false === bx_get('delete_content') ? true : (int)$oForm->getCleanValue('delete_content') != 0, true))
             return $bIsApi ? _t('_sys_txt_error_account_delete') : MsgBox(_t('_sys_txt_error_account_delete'));
 
         // logout from deleted account
-        if($iAccountId == getLoggedId())
-        	bx_logout();
+        if ($iAccountId == getLoggedId())
+            bx_logout();
 
         // redirect to homepage
         $this->_redirectAndExit('', false);