Selaa lähdekoodia

Ticket #4890 - Privacy: Clean up unused custom privacy groups.

AntonLV 1 vuosi sitten
vanhempi
sitoutus
fc193cd1a1

+ 11 - 2
inc/classes/BxDolPrivacy.php

@@ -408,9 +408,13 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         return $this->_oDb->deleteGroupCustom(array('content_id' => $iContentId, 'object' => $this->_sObject));
     }
 
-    public function deleteGroupCustomByProfileId($iProfileId)
+    public function deleteGroupCustomByProfileId($iProfileId, $mixedContentId = false)
     {
-        $aGroups = $this->_oDb->getGroupCustom(array('type' => 'profile_id', 'profile_id' => $iProfileId));
+        $aParams = ['type' => 'profile_id', 'profile_id' => $iProfileId];
+        if($mixedContentId !== false)
+            $aParams['content_id'] = (int)$mixedContentId;
+
+        $aGroups = $this->_oDb->getGroupCustom($aParams);
         if(empty($aGroups) || !is_array($aGroups))
             return true;
 
@@ -420,6 +424,11 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         return true;
     }
 
+    public function deleteGroupCustomByProfileIdUnused($iProfileId)
+    {
+        return $this->deleteGroupCustomByProfileId($iProfileId, 0);
+    }
+
     public function addDynamicGroups($aValues, $iOwnerId, $aParams)
     {
         if (isset($aParams['dynamic_groups']) && is_array($aParams['dynamic_groups']))

+ 8 - 2
inc/classes/BxDolPrivacyQuery.php

@@ -230,11 +230,17 @@ class BxDolPrivacyQuery extends BxDolDb
                 break;
 
             case 'profile_id':
-            	$aMethod['params'][1] = array(
+            	$aMethod['params'][1] = [
                     'profile_id' => $aParams['profile_id']
-                );
+                ];
 
                 $sWhereClause = " AND `tg`.`profile_id`=:profile_id";
+
+                if(isset($aParams['content_id'])) {
+                    $aMethod['params'][1]['content_id'] = $aParams['content_id'];
+
+                    $sWhereClause .= " AND `tg`.`content_id`=:content_id";
+                }
                 break;
         }
 

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

@@ -275,10 +275,14 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
 
         // check and display form
         $oForm->initChecker();
-        if (!$oForm->isSubmittedAndValid())
+        if (!$oForm->isSubmittedAndValid()) {
+            if(!$oForm->isSubmitted() && isset($CNF['FIELD_ALLOW_VIEW_TO']) && ($oProfile = BxDolProfile::getInstance()) !== false && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
+                $oPrivacy->deleteGroupCustomByProfileIdUnused($oProfile->id());
+
             return $this->_bIsApi ? $this->prepareResponseAPI('form', $oForm->getCodeAPI(), ['request_uri' => 'entity_create']) : $this->prepareResponse($oForm->getCode($this->_bDynamicMode), $bAsJson, 'form', [
             	'form_id' => $oForm->getId()
             ]);
+        }
 
         // insert data into database
         $aValsToAdd = array ();

+ 6 - 2
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -3968,13 +3968,17 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             return $this->_prepareResponse(['message' => _t('_bx_timeline_txt_err_cannot_perform_action')], $bAjaxMode);
         }
 
-        if(bx_is_api())
+        $bSubmitted = $oForm->isSubmitted();
+        if(!$bSubmitted && ($oProfile = BxDolProfile::getInstance()) !== false && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
+            $oPrivacy->deleteGroupCustomByProfileIdUnused($oProfile->id());
+
+        if($this->_bIsApi)
             return ['form_object' => $oForm];
 
         $mixedResult = $this->_prepareResponse([
             'form' => $oForm->getCode($bDynamicMode), 
             'form_id' => $oForm->id
-        ], $bAjaxMode && $oForm->isSubmitted());
+        ], $bAjaxMode && $bSubmitted);
 
         if(is_array($mixedResult))
             $mixedResult['form_object'] = $oForm;