Alex Trofimov 11 лет назад
Родитель
Сommit
fe8b72a7b9

+ 5 - 4
inc/classes/BxDolAccount.php

@@ -242,8 +242,9 @@ class BxDolAccount extends BxDol
 
     /**
      * Delete profile.
+     * @param $bDeleteWithContent - delete associated profiles with all its contents
      */
-    function delete()
+    function delete($bDeleteWithContent = false)
     {
         $aAccountInfo = $this->_oQuery->getInfoById($this->_iAccountID);
         if (!$aAccountInfo)
@@ -251,7 +252,7 @@ class BxDolAccount extends BxDol
 
         // create system event before deletion
         $isStopDeletion = false;
-        bx_alert('account', 'before_delete', $this->_iAccountID, 0, array('stop_deletion' => &$isStopDeletion));
+        bx_alert('account', 'before_delete', $this->_iAccountID, 0, array('delete_with_content' => $bDeleteWithContent, 'stop_deletion' => &$isStopDeletion));
         if ($isStopDeletion)
             return false;
 
@@ -265,7 +266,7 @@ class BxDolAccount extends BxDol
             $oProfile = BxDolProfile::getInstance($iProfileId);
             if (!$oProfile)
                 continue;
-            $oProfile->delete(false, true);
+            $oProfile->delete(false, $bDeleteWithContent, true);
         }
 
         // delete profile
@@ -273,7 +274,7 @@ class BxDolAccount extends BxDol
             return false;
 
         // create system event
-        bx_alert('account', 'delete', $this->_iAccountID);
+        bx_alert('account', 'delete', $this->_iAccountID, 0, array ('delete_with_content' => $bDeleteWithContent));
 
         // unset class instance to prevent creating the instance again
         $this->_iAccountID = 0;

+ 8 - 3
inc/classes/BxDolProfile.php

@@ -242,10 +242,11 @@ class BxDolProfile extends BxDol implements iBxDolProfile
     /**
      * Delete profile.
      * @param $ID - optional profile id to delete
+     * @param $bDeleteWithContent - delete profile with all its contents
      * @param $bForceDelete - force deletetion is case of account profile deletion
      * @return false on error, or true on success
      */
-    function delete($ID = false, $bForceDelete = false)
+    function delete($ID = false, $bDeleteWithContent = true /*false*/, $bForceDelete = false)
     {
         $ID = (int)$ID;
         if (!$ID)
@@ -259,6 +260,10 @@ class BxDolProfile extends BxDol implements iBxDolProfile
         if (!$bForceDelete && 'system' == $aProfileInfo['type'])
             return false;
 
+        // delete actual profile
+        if ($sErrorMsg = BxDolService::call($aProfileInfo['type'] , 'delete_entity_service', array($aProfileInfo['content_id'], $bDeleteWithContent)))
+            return false;
+
         // switch profile context if deleted profile is active profile context
         bx_import('BxDolAccount');
         $oAccount = BxDolAccount::getInstance ($aProfileInfo['account_id']);
@@ -270,7 +275,7 @@ class BxDolProfile extends BxDol implements iBxDolProfile
 
         // create system event before deletion
         $isStopDeletion = false;
-        bx_alert('profile', 'before_delete', $ID, 0, array('stop_deletion' => &$isStopDeletion));
+        bx_alert('profile', 'before_delete', $ID, 0, array('delete_with_content' => $bDeleteWithContent, 'stop_deletion' => &$isStopDeletion));
         if ($isStopDeletion)
             return false;
 
@@ -295,7 +300,7 @@ class BxDolProfile extends BxDol implements iBxDolProfile
             return false;
 
         // create system event
-        bx_alert('profile', 'delete', $ID);
+        bx_alert('profile', 'delete', $ID, 0, array('delete_with_content' => $bDeleteWithContent));
 
         // unset class instance to prevent creating the instance again
         $this->_iProfileID = 0;

+ 3 - 4
inc/classes/BxDolViewQuery.php

@@ -62,12 +62,11 @@ class BxDolViewQuery extends BxDolDb
         }
     }
 
-    function deleteObjectViews($iObjectId)
+    public function deleteObjectViews($iObjectId)
     {
         $sQuery = $this->prepare("DELETE FROM {$this->_sTableTrack} WHERE `object_id` = ?", $iObjectId);
-        $this->query ($sQuery);
-
-        $this->query ("OPTIMIZE TABLE {$this->_sTableTrack}");
+        if ($this->query ($sQuery))
+            $this->query ("OPTIMIZE TABLE {$this->_sTableTrack}");
     }
 
     public function updateTriggerTable($iObjectId)

+ 19 - 0
modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php

@@ -240,6 +240,25 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         $oForm->initChecker($aContentInfo);
         return $oForm->getCode();
     }
+
+    protected function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
+    {
+        return '';
+    }
+
+    protected function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges)
+    {
+    }
+
+    protected function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile)
+    {
+        return '';
+    }
+
+    protected function onDataAddAfter ($iContentId)
+    {
+        return '';
+    }
 }
 
 /** @} */

+ 1 - 5
modules/base/general/classes/BxBaseModGeneralGridAdministration.php

@@ -46,17 +46,13 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
             exit;
         }
 
-        bx_import('FormsEntryHelper', $this->_oModule->_aModule);
-        $sClass = $this->_oModule->_oConfig->getClassPrefix() . 'FormsEntryHelper';
-        $oFormsHelper = new $sClass($this->_oModule);
-
         $aIdsAffected = array ();
         foreach($aIds as $iId) {
 			$aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
 	    	if($this->_oModule->checkAllowedDelete($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
 	    		continue;
 
-        	if($oFormsHelper->deleteData($iId) != '')
+        	if($this->_oModule->serviceDeleteEntity($iId) != '')
                 continue;
 
 			if(!$this->_onDelete($iId, $aParams))

+ 13 - 0
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -140,6 +140,19 @@ class BxBaseModGeneralModule extends BxDolModule
         return $this->_serviceEntityForm ('viewDataForm', $iContentId);
     }
 
+    /**
+     * Delete content entry
+     * @param $iContentId content id 
+     * @return error message or empty string on success
+     */
+    public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
+    {
+        bx_import('FormsEntryHelper', $this->_aModule);
+        $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
+        $oFormsHelper = new $sClass($this);
+        return $oFormsHelper->$sFuncDelete($iContentId);
+    }
+
     /**
      * Entry actions block
      */

+ 1 - 4
modules/base/profile/classes/BxBaseModProfileFormEntry.php

@@ -135,10 +135,7 @@ class BxBaseModProfileFormEntry extends BxBaseModGeneralFormEntry
                 $this->_deleteFile ($aContentInfo[$sField], $aVals['storage_object']);
         }
 
-        bx_import('BxDolView');
-        BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId)->onObjectDelete();
-
-        return parent::delete($iContentId);
+        return parent::delete($iContentId, $aContentInfo);
     }
 
     function _processFile ($sField, $iFileIdOld, &$sErrorString)

+ 12 - 2
modules/base/profile/classes/BxBaseModProfileFormsEntryHelper.php

@@ -40,15 +40,25 @@ class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
         return array ($oProfile, $aContentInfo);
     }
 
-    protected function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
+    public function deleteData ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
     {
+        if (!$aContentInfo)
+            list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
+
         // delete profile
-        if (!$oProfile->delete($aContentInfo['profile_id']))
+        bx_import('BxDolProfile');
+        $oProfile = BxDolProfile::getInstance($aContentInfo['profile_id']);
+        if (!$oProfile->delete())
             return _t('_sys_txt_error_entry_delete');
 
         return '';
     }
 
+    public function deleteDataService ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
+    {
+        return parent::deleteData ($iContentId, $aContentInfo, $oProfile, $oForm);
+    }
+
     protected function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;

+ 8 - 0
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -229,6 +229,14 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolPro
         return $s;
     }
 
+    /**
+     * For internal usage only.
+     */
+    public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
+    {
+        return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
+    }
+
     // ====== PERMISSION METHODS
 
     /**

+ 25 - 0
modules/base/text/classes/BxBaseModTextAlertsResponse.php

@@ -0,0 +1,25 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    BaseText Base classes for text modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxBaseModTextAlertsResponse extends BxDolAlertsResponse
+{
+    protected $MODULE;
+
+    public function response($oAlert)
+    {
+        if ('profile' != $oAlert->sUnit || 'delete' != $oAlert->sAction || !$oAlert->aExtras['delete_with_content'])
+            return;
+
+        BxDolService::call($this->MODULE, 'delete_entities_by_author', array($oAlert->iObject));
+    }
+}
+
+/** @} */

+ 7 - 1
modules/base/text/classes/BxBaseModTextDb.php

@@ -23,9 +23,15 @@ class BxBaseModTextDb extends BxBaseModGeneralDb
 
     public function getContentInfoById ($iContentId)
     {
-        $sQuery = $this->prepare ("SELECT `c`.* FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` AS `c` WHERE `c`.`id` = ?", $iContentId);
+        $sQuery = $this->prepare ("SELECT * FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` WHERE `" . $this->_oConfig->CNF['FIELD_ID'] . "` = ?", $iContentId);
         return $this->getRow($sQuery);
     }
+
+    public function getEntriesByAuthor ($iProfileId)
+    {
+        $sQuery = $this->prepare ("SELECT * FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` WHERE `" . $this->_oConfig->CNF['FIELD_AUTHOR'] . "` = ?", $iProfileId);
+        return $this->getAll($sQuery);
+    }
 }
 
 /** @} */

+ 0 - 9
modules/base/text/classes/BxBaseModTextFormsEntryHelper.php

@@ -81,15 +81,6 @@ class BxBaseModTextFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
         return array ($oProfile, $aContentInfo);
     }
 
-    protected function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
-    {
-        return '';
-    }
-
-    protected function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges)
-    {
-    }
-
     protected function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;

+ 18 - 0
modules/base/text/classes/BxBaseModTextModule.php

@@ -202,6 +202,24 @@ class BxBaseModTextModule extends BxBaseModGeneralModule
         return $oMenu ? $oMenu->getCode() : false;
     }
 
+    /**
+     * Delete all content by profile 
+     * @param $iProfileId profile id 
+     * @return number of deleted items
+     */
+    public function serviceDeleteEntitiesByAuthor ($iProfileId)
+    {
+        $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
+        if (!$a)
+            return 0;
+
+        $iCount = 0;
+        foreach ($a as $aContentInfo)
+            $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
+
+        return $iCount;
+    }
+
 	/**
      * Data for Notification
      */

+ 23 - 0
modules/boonex/albums/classes/BxAlbumsAlertsResponse.php

@@ -0,0 +1,23 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Albums Albums
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+bx_import('BxBaseModTextAlertsResponse');
+
+class BxAlbumsAlertsResponse extends BxBaseModTextAlertsResponse
+{
+    public function __construct()
+    {
+        $this->MODULE = 'bx_albums';
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 5 - 0
modules/boonex/albums/install/sql/disable.sql

@@ -36,3 +36,8 @@ DELETE FROM `sys_grid_actions` WHERE `object` IN ('bx_albums_administration', 'b
 -- UPLOADERS
 DELETE FROM `sys_objects_uploader` WHERE `object` IN('bx_albums_simple', 'bx_albums_html5');
 
+-- ALERTS
+SET @iHandler := (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = 'bx_albums' LIMIT 1);
+DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandler;
+DELETE FROM `sys_alerts_handlers` WHERE `id` = @iHandler;
+

+ 9 - 0
modules/boonex/albums/install/sql/enable.sql

@@ -334,3 +334,12 @@ INSERT INTO `sys_objects_uploader` (`object`, `active`, `override_class_name`, `
 ('bx_albums_simple', 1, 'BxAlbumsUploaderSimple', 'modules/boonex/albums/classes/BxAlbumsUploaderSimple.php'),
 ('bx_albums_html5', 1, 'BxAlbumsUploaderHTML5', 'modules/boonex/albums/classes/BxAlbumsUploaderHTML5.php');
 
+-- ALERTS
+
+INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `service_call`) VALUES 
+('bx_albums', 'BxAlbumsAlertsResponse', 'modules/boonex/albums/classes/BxAlbumsAlertsResponse.php', '');
+SET @iHandler := LAST_INSERT_ID();
+
+INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
+('profile', 'delete', @iHandler);
+

+ 23 - 0
modules/boonex/posts/classes/BxPostsAlertsResponse.php

@@ -0,0 +1,23 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Posts Posts
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+bx_import('BxBaseModTextAlertsResponse');
+
+class BxPostsAlertsResponse extends BxBaseModTextAlertsResponse
+{
+    public function __construct()
+    {
+        $this->MODULE = 'bx_posts';
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 5 - 0
modules/boonex/posts/install/sql/disable.sql

@@ -32,3 +32,8 @@ DELETE FROM `sys_objects_metatags` WHERE `object` = 'bx_posts';
 DELETE FROM `sys_objects_grid` WHERE `object` IN ('bx_posts_administration', 'bx_posts_moderation', 'bx_posts_common');
 DELETE FROM `sys_grid_fields` WHERE `object` IN ('bx_posts_administration', 'bx_posts_moderation', 'bx_posts_common');
 DELETE FROM `sys_grid_actions` WHERE `object` IN ('bx_posts_administration', 'bx_posts_moderation', 'bx_posts_common');
+
+-- ALERTS
+SET @iHandler := (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = 'bx_posts' LIMIT 1);
+DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandler;
+DELETE FROM `sys_alerts_handlers` WHERE `id` = @iHandler;

+ 10 - 0
modules/boonex/posts/install/sql/enable.sql

@@ -329,3 +329,13 @@ INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `icon
 ('bx_posts_common', 'single', 'edit', '_bx_posts_grid_action_title_adm_edit', 'pencil', 1, 0, 1),
 ('bx_posts_common', 'single', 'delete', '_bx_posts_grid_action_title_adm_delete', 'remove', 1, 1, 2),
 ('bx_posts_common', 'single', 'settings', '_bx_posts_grid_action_title_adm_more_actions', 'cog', 1, 0, 3);
+
+-- ALERTS
+
+INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `service_call`) VALUES 
+('bx_posts', 'BxPostsAlertsResponse', 'modules/boonex/posts/classes/BxPostsAlertsResponse.php', '');
+SET @iHandler := LAST_INSERT_ID();
+
+INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
+('profile', 'delete', @iHandler);
+