AntonLV 7 ani în urmă
părinte
comite
5a46643d24

+ 12 - 2
modules/base/general/classes/BxBaseModGeneralAlertsResponse.php

@@ -85,8 +85,18 @@ class BxBaseModGeneralAlertsResponse extends BxDolAlertsResponse
                 return;
         }
 
-        if((int)$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'active'), array($CNF['FIELD_ID'] => $iContentId)) > 0)
-            $this->_oModule->onPublished($iContentId);
+        if(!$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'active'), array($CNF['FIELD_ID'] => $iContentId))) 
+            return;
+        
+        $this->_oModule->onPublished($iContentId);
+
+        /*
+         * Process metas.
+         * Note. It's essential to process metas a the very end, 
+         * because all data related to an entry should be already
+         * processed and are ready to be passed to alert. 
+         */
+        $this->_oModule->processMetasAdd($iContentId);
     }
 }
 

+ 25 - 34
modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php

@@ -196,6 +196,14 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         if($sResult)
             return array('code' => 4, 'message' => $sResult);
 
+        /*
+         * Process metas.
+         * Note. It's essential to process metas a the very end, 
+         * because all data related to an entry should be already
+         * processed and are ready to be passed to alert. 
+         */
+        $this->_oModule->processMetasAdd($iContentId);
+
         list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
         return array('code' => 0, 'message' => '', 'content' => $aContentInfo);
     }
@@ -248,6 +256,14 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         if ($sResult)
             return $this->prepareResponse($sResult, $bAsJson, 'msg');
 
+        /*
+         * Process metas.
+         * Note. It's essential to process metas a the very end, 
+         * because all data related to an entry should be already
+         * processed and are ready to be passed to alert. 
+         */
+        $this->_oModule->processMetasAdd($iContentId);
+
         // perform action
         $this->_oModule->$sCheckFunction(true);
 
@@ -317,6 +333,14 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         if ($sResult)
             return $sResult;
 
+        /*
+         * Process metas.
+         * Note. It's essential to process metas a the very end, 
+         * because all data related to an entry should be already
+         * processed and are ready to be passed to alert. 
+         */
+        $this->_oModule->processMetasEdit($iContentId);
+        
         // perform action
         $this->_oModule->$sCheckFunction($aContentInfo, true);
         
@@ -470,21 +494,9 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         if(isset($CNF['FIELD_PHOTO']))
             $oForm->processFiles ($CNF['FIELD_PHOTO'], $iContentId, false);
 
-        if(!empty($CNF['OBJECT_METATAGS'])) { // && isset($aTrackTextFieldsChanges['changed_fields'][$CNF['FIELD_TEXT']])) { // TODO: check if aTrackTextFieldsChanges works 
-            $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
-            $oMetatags->metaAddAuto($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
-            if (isset($CNF['FIELD_LOCATION_PREFIX']) && isset($oForm->aInputs[$CNF['FIELD_LOCATION_PREFIX']]) && $oMetatags->locationsIsEnabled())
-                $oMetatags->locationsAddFromForm($aContentInfo[$CNF['FIELD_ID']], empty($CNF['FIELD_LOCATION_PREFIX']) ? '' : $CNF['FIELD_LOCATION_PREFIX']);
-
-            if (!empty($CNF['FIELD_LABELS']) && ($aLabels = bx_get($CNF['FIELD_LABELS'])) && $oMetatags->keywordsIsEnabled()) {
-                foreach ($aLabels as $sLabel)
-                    $oMetatags->keywordsAddOne($aContentInfo[$CNF['FIELD_ID']], $sLabel, false);
-            }
-        }
-
         if(isset($CNF['FIELD_STATUS']) && ($aTrackResult = $oForm->isTrackFieldChanged($CNF['FIELD_STATUS'], true)) !== false)
             if($aTrackResult['old'] == 'failed' && $aTrackResult['new'] == 'active')
-                $this->_alertAfterAdd($aContentInfo);
+                $this->_oModule->alertAfterAdd($aContentInfo);
 
         return '';
     }
@@ -498,30 +510,9 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
                 $oForm->processFiles($CNF['FIELD_PHOTO'], $iContentId, true);
         }
 
-        $this->_processMetas($iAccountId, $iContentId);
-
         return '';
     }
 
-    protected function _processMetas($iAccountId, $iContentId)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        if (!empty($CNF['OBJECT_METATAGS'])) {
-            list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
-            $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
-            if ($aContentInfo)
-                $oMetatags->metaAddAuto($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
-            if ($oMetatags->locationsIsEnabled() && $aContentInfo)
-                $oMetatags->locationsAddFromForm($aContentInfo[$CNF['FIELD_ID']], $CNF['FIELD_LOCATION_PREFIX']);
-
-            if ($aContentInfo && !empty($CNF['FIELD_LABELS']) && ($aLabels = bx_get($CNF['FIELD_LABELS'])) && $oMetatags->keywordsIsEnabled()) {
-                foreach ($aLabels as $sLabel)
-                    $oMetatags->keywordsAddOne($aContentInfo[$CNF['FIELD_ID']], $sLabel, false);
-            }
-        }
-    }
-
     protected function prepareCustomRedirectUrl($s, $aContentInfo)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;

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

@@ -1405,6 +1405,57 @@ class BxBaseModGeneralModule extends BxDolModule
 
     public function onFailed($iContentId) {}
 
+    public function processMetasAdd($iContentId)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(empty($CNF['OBJECT_METATAGS'])) 
+            return;
+
+        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+
+        $bFldStatus = isset($CNF['FIELD_STATUS']);
+        $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
+        $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
+        if(!$bContentInfo)
+            return;
+
+        $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
+        $oMetatags->metaAddAuto($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
+
+        if($oMetatags->locationsIsEnabled())
+            $oMetatags->locationsAddFromForm($aContentInfo[$CNF['FIELD_ID']], $CNF['FIELD_LOCATION_PREFIX']);
+
+        if(!empty($CNF['FIELD_LABELS']) && ($aLabels = bx_get($CNF['FIELD_LABELS'])) && $oMetatags->keywordsIsEnabled())
+            foreach ($aLabels as $sLabel)
+                $oMetatags->keywordsAddOne($aContentInfo[$CNF['FIELD_ID']], $sLabel, false);
+    }
+    
+    public function processMetasEdit($iContentId)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(empty($CNF['OBJECT_METATAGS']))
+            return;
+
+        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+
+        $bFldStatus = isset($CNF['FIELD_STATUS']);
+        $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
+        $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
+        if(!$bContentInfo)
+            return;
+
+        $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
+        $oMetatags->metaAddAuto($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
+        if(isset($CNF['FIELD_LOCATION_PREFIX']) && isset($oForm->aInputs[$CNF['FIELD_LOCATION_PREFIX']]) && $oMetatags->locationsIsEnabled())
+            $oMetatags->locationsAddFromForm($aContentInfo[$CNF['FIELD_ID']], empty($CNF['FIELD_LOCATION_PREFIX']) ? '' : $CNF['FIELD_LOCATION_PREFIX']);
+
+        if(!empty($CNF['FIELD_LABELS']) && ($aLabels = bx_get($CNF['FIELD_LABELS'])) && $oMetatags->keywordsIsEnabled())
+            foreach ($aLabels as $sLabel)
+                $oMetatags->keywordsAddOne($aContentInfo[$CNF['FIELD_ID']], $sLabel, false);
+    }
+
     public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
     {
         if(empty($aTranscoders))

+ 0 - 4
modules/base/profile/classes/BxBaseModProfileFormsEntryHelper.php

@@ -110,7 +110,6 @@ class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
 
     public function onDataAddAfter ($iAccountId, $iContentId)
     {
-        // parent method isn't processing metas, so we are processing it below
         if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
             return $s;
 
@@ -132,9 +131,6 @@ class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
             $iAclLevel = !isset($CNF['PARAM_DEFAULT_ACL_LEVEL']) ? MEMBERSHIP_ID_STANDARD : 
                (isAdmin() ? MEMBERSHIP_ID_ADMINISTRATOR : getParam($CNF['PARAM_DEFAULT_ACL_LEVEL']));
         BxDolAcl::getInstance()->setMembership($iProfileId, $iAclLevel, 0, true);
-
-        // process metas
-        $this->_processMetas($iAccountId, $iContentId);
         
         // process uploaded files
         $oForm = $this->getObjectFormAdd();

+ 2 - 51
modules/base/text/classes/BxBaseModTextFormsEntryHelper.php

@@ -83,7 +83,7 @@ class BxBaseModTextFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
             $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
 
         // alert
-        $this->_alertAfterEdit($aContentInfo);
+        $this->_oModule->alertAfterEdit($aContentInfo);
 
         return '';
     }
@@ -110,7 +110,7 @@ class BxBaseModTextFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
         }
 
         // alert
-        $this->_alertAfterAdd($aContentInfo);
+        $this->_oModule->alertAfterAdd($aContentInfo);
 
         return '';
     }
@@ -125,55 +125,6 @@ class BxBaseModTextFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
 
         return '';
     }
-
-    protected function _alertAfterAdd($aContentInfo)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
-        $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
-
-        $sAction = 'added';
-        if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'awaiting')
-            $sAction = 'deferred';
-
-        $aParams = $this->_alertParams($aContentInfo);
-        bx_alert($this->_oModule->getName(), $sAction, $iId, $iAuthorId, $aParams);
-    }
-
-    protected function _alertAfterEdit($aContentInfo)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
-
-        $aParams = $this->_alertParams($aContentInfo);
-        bx_alert($this->_oModule->getName(), 'edited', $iId, false, $aParams);
-    }
-
-    /**
-     * Get array of params to be passed in Add/Edit Alert.
-     */
-    protected function _alertParams($aContentInfo)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
-        $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
-
-        $aParams = array(
-            'object_author_id' => $iAuthorId
-        );
-        if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
-            $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
-        if(!empty($CNF['OBJECT_METATAGS']))
-            $aParams['timeline_group'] = array(
-                'by' => $this->_oModule->_oConfig->getName() . '_' . $iAuthorId . '_' . $iId,
-                'field' => 'owner_id'
-            );
-
-        return $aParams;
-    }
 }
 
 /** @} */

+ 50 - 4
modules/base/text/classes/BxBaseModTextModule.php

@@ -272,10 +272,7 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         if(!$aContentInfo)
             return;
 
-        $aParams = array('object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]);
-        if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
-            $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
-
+        $aParams = $this->_alertParams($aContentInfo);
         bx_alert($this->getName(), 'added', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
     }
 
@@ -294,6 +291,55 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
     }
 
+    public function alertAfterAdd($aContentInfo)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
+        $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
+
+        $sAction = 'added';
+        if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'awaiting')
+            $sAction = 'deferred';
+
+        $aParams = $this->_alertParams($aContentInfo);
+        bx_alert($this->getName(), $sAction, $iId, $iAuthorId, $aParams);
+    }
+
+    public function alertAfterEdit($aContentInfo)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
+
+        $aParams = $this->_alertParams($aContentInfo);
+        bx_alert($this->getName(), 'edited', $iId, false, $aParams);
+    }
+
+    /**
+     * Get array of params to be passed in Add/Edit Alert.
+     */
+    protected function _alertParams($aContentInfo)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
+        $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
+
+        $aParams = array(
+            'object_author_id' => $iAuthorId
+        );
+        if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
+            $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
+        if(!empty($CNF['OBJECT_METATAGS']))
+            $aParams['timeline_group'] = array(
+                'by' => $this->getName() . '_' . $iAuthorId . '_' . $iId,
+                'field' => 'owner_id'
+            );
+
+        return $aParams;
+    }
+
     public function isEntryActive($aContentInfo)
     {
         $CNF = &$this->_oConfig->CNF;

+ 7 - 0
modules/boonex/channels/classes/BxCnlModule.php

@@ -43,6 +43,13 @@ class BxCnlModule extends BxBaseModGroupsModule
         if(empty($oModule))
             return;
 
+        /*
+         * Use content's author profile when Author ID wasn't provided. 
+         * Usually it happens when tags were processed with cron.
+         */
+        if(empty($iAuthorId))
+            $iAuthorId = BxDolService::call($sModuleName, 'get_author', array($iContentId));
+
         $aCheck = checkActionModule($this->_iProfileId, 'create channel auto', $this->getName(), false);
         $mixedCnlId = $this->_oDb->getChannelIdByName($sHashtag);
         if (empty($mixedCnlId) && ($aCheck[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)){