Parcourir la source

Ticket #2128 - Fixes related to delayed publishing in Posts module.

AntonLV il y a 7 ans
Parent
commit
21f1633e9d

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

@@ -177,7 +177,22 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
     {
     	return true;
     }
-    
+
+    protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if(!in_array($aRow[$CNF['FIELD_STATUS']], array('active', 'hidden'))) {
+            $sStatusKey = '_sys_status_' . $aRow[$CNF['FIELD_STATUS']];
+            if(!empty($CNF['T']['txt_status_' . $aRow[$CNF['FIELD_STATUS']]]))
+                $sStatusKey = $CNF['T']['txt_status_' . $aRow[$CNF['FIELD_STATUS']]];
+
+            return parent::_getCellDefault(_t($sStatusKey), $sKey, $aField, $aRow);
+        }
+
+        return parent::_getCellSwitcher ($mixedValue, $sKey, $aField, $aRow);
+    }
+
     protected function _getCellHeaderReports ($sKey, $aField)
     {
         $s = parent::_getCellHeaderDefault($sKey, $aField);

+ 0 - 10
modules/base/text/classes/BxBaseModTextGridAdministration.php

@@ -66,16 +66,6 @@ class BxBaseModTextGridAdministration extends BxBaseModGeneralGridAdministration
         return  $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
     }
 
-    protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        if(!in_array($aRow[$CNF['FIELD_STATUS']], array('active', 'hidden')))
-            return parent::_getCellDefault(_t('_sys_status_' . $aRow[$CNF['FIELD_STATUS']]), $sKey, $aField, $aRow);
-
-        return parent::_getCellSwitcher ($mixedValue, $sKey, $aField, $aRow);
-    }
-
     protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;

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

@@ -219,6 +219,7 @@
 	<string name="_bx_timeline_txt_or_jump_to"><![CDATA[... или перейти к:]]></string>
 	<string name="_bx_timeline_txt_jump_to_n_year"><![CDATA[Перейти к {0} году]]></string>
 	<string name="_bx_timeline_txt_jump_to_recent"><![CDATA[Перейти к недавним сообщениям]]></string>
+        <string name="_bx_timeline_txt_status_deleted"><![CDATA[Удалено]]></string>
 	<string name="_bx_timeline_txt_hot"><![CDATA['Горячее' событие]]></string>
 	<string name="_bx_timeline_txt_pinned"><![CDATA[Приколотое событие]]></string>
         <string name="_bx_timeline_txt_sticked"><![CDATA[Событие приколотое для всех]]></string>

+ 3 - 0
modules/boonex/timeline/classes/BxTimelineConfig.php

@@ -74,6 +74,8 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
             'FIELD_ADDED' => 'date',
             'FIELD_TITLE' => 'title',
             'FIELD_TEXT' => 'description',
+            'FIELD_STATUS' => 'status',
+            'FIELD_DATE' => 'date',
             'FIELD_ANONYMOUS' => 'anonymous',
             'FIELD_CONTROLS' => 'controls',
             'FIELD_LOCATION_PREFIX' => 'location',
@@ -98,6 +100,7 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
 
             // some language keys
             'T' => array (
+                'txt_status_deleted' => '_bx_timeline_txt_status_deleted',
                 'txt_sample_single' => '_bx_timeline_txt_sample',
                 'txt_sample_single_ext' => '_bx_timeline_txt_sample_ext',
             	'txt_sample_comment_single' => '_bx_timeline_txt_sample_comment_single',

+ 36 - 0
modules/boonex/timeline/classes/BxTimelineCronPublishing.php

@@ -0,0 +1,36 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Posts Posts
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxTimelineCronPublishing extends BxDolCron
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    public function __construct()
+    {
+        parent::__construct();
+
+    	$this->_sModule = 'bx_timeline';
+    	$this->_oModule = BxDolModule::getInstance($this->_sModule);
+    }
+
+    function processing()
+    {
+        $mixedIds = $this->_oModule->_oDb->publish();
+        if($mixedIds === false)
+            return;
+
+        foreach($mixedIds as $iId)
+            $this->_oModule->onPost($iId);
+    }
+}
+
+/** @} */

+ 42 - 26
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -44,36 +44,36 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
     public function deleteModuleEvents($aData)
     {
-    	foreach($aData['handlers'] as $aHandler) {
-    		//Delete system events.
+        foreach($aData['handlers'] as $aHandler) {
+            //Delete system events.
             $this->deleteEvent(array('type' => $aHandler['alert_unit'], 'action' => $aHandler['alert_action']));
 
             //Delete reposted events.
-    		$aEvents = $this->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aHandler['alert_unit'], 'action' => $aHandler['alert_action']));
-			foreach($aEvents as $aEvent) {
-				$aContent = unserialize($aEvent['content']);
-				if(isset($aContent['type']) && $aContent['type'] == $aHandler['alert_unit'] && isset($aContent['action']) && $aContent['action'] == $aHandler['alert_action'])
-					$this->deleteEvent(array('id' => (int)$aEvent['id']));
-			}
-    	}
+            $aEvents = $this->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aHandler['alert_unit'], 'action' => $aHandler['alert_action']));
+                foreach($aEvents as $aEvent) {
+                    $aContent = unserialize($aEvent['content']);
+                    if(isset($aContent['type']) && $aContent['type'] == $aHandler['alert_unit'] && isset($aContent['action']) && $aContent['action'] == $aHandler['alert_action'])
+                        $this->deleteEvent(array('id' => (int)$aEvent['id']));
+                }
+        }
     }
 
     public function activateModuleEvents($aData, $bActivate = true)
     {
-    	$iActivate = $bActivate ? 1 : 0;
+        $iActivate = $bActivate ? 1 : 0;
 
-    	foreach($aData['handlers'] as $aHandler) {
-    		//Activate (deactivate) system events.
+        foreach($aData['handlers'] as $aHandler) {
+            //Activate (deactivate) system events.
             $this->updateEvent(array('active' => $iActivate), array('type' => $aHandler['alert_unit'], 'action' => $aHandler['alert_action']));
 
-			//Activate (deactivate) reposted events.
-			$aEvents = $this->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aHandler['alert_unit'], 'action' => $aHandler['alert_action']));
-			foreach($aEvents as $aEvent) {
-				$aContent = unserialize($aEvent['content']);
-				if(isset($aContent['type']) && $aContent['type'] == $aHandler['alert_unit'] && isset($aContent['action']) && $aContent['action'] == $aHandler['alert_action'])
-					$this->updateEvent(array('active' => $iActivate), array('id' => (int)$aEvent['id']));
-			}
-    	}
+            //Activate (deactivate) reposted events.
+            $aEvents = $this->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aHandler['alert_unit'], 'action' => $aHandler['alert_action']));
+            foreach($aEvents as $aEvent) {
+                $aContent = unserialize($aEvent['content']);
+                if(isset($aContent['type']) && $aContent['type'] == $aHandler['alert_unit'] && isset($aContent['action']) && $aContent['action'] == $aHandler['alert_action'])
+                    $this->updateEvent(array('active' => $iActivate), array('id' => (int)$aEvent['id']));
+            }
+        }
     }
 
     public function getMaxDuration($aParams)
@@ -123,14 +123,14 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 		if($bSystem && (empty($aReposted) || !is_array($aReposted))) {
 			$iOwnerId = 0;
 			$iDate = 0;
-			$iHidden = 1;
+			$sStatus = BX_TIMELINE_STATUS_DELETED;
 
 			$mixedResult = $this->_oConfig->getSystemDataByDescriptor($sType, $sAction, $iObjectId);
 			if(is_array($mixedResult)) {
                             $iOwnerId = !empty($mixedResult['owner_id']) ? (int)$mixedResult['owner_id'] : 0;
                             $iDate = !empty($mixedResult['date']) ? (int)$mixedResult['date'] : 0;
                             if($this->_oConfig->isUnhideRestored() && !empty($iOwnerId) && !empty($iDate))
-                                $iHidden = 0;
+                                $sStatus = BX_TIMELINE_STATUS_ACTIVE;
 			}
 
 			$iId = $this->insertEvent(array(
@@ -143,7 +143,7 @@ class BxTimelineDb extends BxBaseModNotificationsDb
                             'title' => '',
                             'description' => '',
                             'date' => $iDate,
-                            'hidden' => $iHidden
+                            'status' => $sStatus
 			));
 
 			$aReposted = $this->getEvents(array('browse' => 'id', 'value' => $iId));
@@ -458,6 +458,23 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
     }
 
+    public function publish()
+    {
+        $CNF = $this->_oConfig->CNF;
+
+        $aEvents = $this->getAll("SELECT `" . $CNF['FIELD_ID'] . "`, `" . $CNF['FIELD_DATE'] . "`  FROM `" . $this->_sTable . "` WHERE `" . $CNF['FIELD_STATUS'] . "`='" . BX_TIMELINE_STATUS_AWAITING . "'");
+        if(empty($aEvents) || !is_array($aEvents))
+            return false;
+
+        $iNow = time();
+        $aResult = array();
+        foreach($aEvents as $aEvent)
+            if($aEvent[$CNF['FIELD_DATE']] <= $iNow) 
+                $aResult[] = $aEvent[$CNF['FIELD_ID']];
+
+        return count($aResult) == (int)$this->query("UPDATE `" . $this->_sTable . "` SET `" . $CNF['FIELD_STATUS'] . "`='" . BX_TIMELINE_STATUS_ACTIVE . "' WHERE `id` IN (" . $this->implode_escape($aResult) . ")") ? $aResult : false;
+    }
+
     protected function _getFilterAddon($iOwnerId, $sFilter)
     {
         switch($sFilter) {
@@ -597,9 +614,8 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
     	$sJoinClause = $sWhereClause = "";
 
-        $sWhereClauseStatus = "AND `{$this->_sTable}`.`hidden`='0' ";
-        if(isset($aParams['active']))
-            $sWhereClauseStatus .= $this->prepareAsString("AND `{$this->_sTable}`.`active`=? ", (int)$aParams['active']);
+        $sWhereClauseStatus = "AND `{$this->_sTable}`.`active`='1' ";
+        $sWhereClauseStatus .= $this->prepareAsString("AND `{$this->_sTable}`.`status`=? ", isset($aParams['status']) ? $aParams['status'] : BX_TIMELINE_STATUS_ACTIVE);
 
         //--- Apply filter
         $sWhereClauseFilter = "";

+ 5 - 5
modules/boonex/timeline/classes/BxTimelineGridAdministration.php

@@ -16,22 +16,22 @@ class BxTimelineGridAdministration extends BxBaseModGeneralGridAdministration
     	$this->MODULE = 'bx_timeline';
         parent::__construct ($aOptions, $oTemplate);
     }
-    
+
     protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
     {
         return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
     }
-    
+
     protected function _switcherChecked2State($isChecked)
     {
-        return $isChecked ? '1' : '0';
+        return $isChecked ? 'active' : 'hidden';
     }
 
     protected function _switcherState2Checked($mixedState)
     {
-        return '1' == $mixedState ? true : false;
+        return 'active' == $mixedState ? true : false;
     }
-    
+
     public function performActionDelete($aParams = array())
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;

+ 29 - 16
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -32,6 +32,11 @@ define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
 define('BX_TIMELINE_PARSE_TYPE_REPOST', 'repost');
 define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
 
+define('BX_TIMELINE_STATUS_ACTIVE', 'active');
+define('BX_TIMELINE_STATUS_AWAITING', 'awaiting');
+define('BX_TIMELINE_STATUS_HIDDEN', 'hidden');
+define('BX_TIMELINE_STATUS_DELETED', 'deleted');
+
 define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
 define('BX_TIMELINE_MEDIA_VIDEO', 'video');
 
@@ -2013,18 +2018,18 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
     /** 
      * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
      */
-	public function serviceGetMenuAddonManageTools()
-	{
-		bx_import('SearchResult', $this->_aModule);
+    public function serviceGetMenuAddonManageTools()
+    {
+        bx_import('SearchResult', $this->_aModule);
         $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
-        $o = new $sClass();
-        $o->fillFilters(array(
-			'active' => 0
+        $oSearch = new $sClass();
+        $oSearch->fillFilters(array(
+            'status' => BX_TIMELINE_STATUS_HIDDEN
         ));
-        $o->unsetPaginate();
+        $oSearch->unsetPaginate();
 
-        return $o->getNum();
-	}
+        return $oSearch->getNum();
+    }
 
     /*
      * COMMON METHODS
@@ -2147,11 +2152,17 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
 
             //--- Process Date ---//
+            $iNow = time();
             $iDate = 0;
             if(isset($oForm->aInputs['date']))
                 $iDate = $oForm->getCleanValue('date');
             if(empty($iDate))
-                $iDate = time();
+                $iDate = $iNow;
+            
+            //--- Process Status ---//
+            $sStatus = BX_TIMELINE_STATUS_ACTIVE;
+            if($iDate > $iNow)
+                $sStatus = BX_TIMELINE_STATUS_AWAITING;
 
             /**
              * Unset 'text' input because its data was already processed 
@@ -2167,7 +2178,8 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
                 'content' => serialize($aContent),
                 'title' => $sTitle,
                 'description' => $sDescription,
-                'date' => $iDate
+                'date' => $iDate,
+                'status' => $sStatus
             ));
 
             if(!empty($iId)) {
@@ -2743,6 +2755,8 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
     public function onPost($iId)
     {
+        $CNF = &$this->_oConfig->CNF;
+
         $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
 
         if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
@@ -2758,7 +2772,8 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         }
 
         //--- Event -> Post for Alerts Engine ---//
-        bx_alert($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
+        $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'schedule' : 'post') . '_' . $sPostType;
+        bx_alert($this->_oConfig->getObject('alert'), $sAction, $iId, $iSenderId, array(
             'owner_id' => $aEvent['owner_id'],
             'object_author_id' => $iObjectAuthorId,
             'privacy_view' => $aEvent['object_privacy_view'],
@@ -3269,8 +3284,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
         $aParams = array_merge($aParams, array(
             'browse' => 'list',
-            'active' => 1,
-            'hidden' => 0
+            'status' => BX_TIMELINE_STATUS_ACTIVE
         ));
 
         return $aParams;
@@ -3315,8 +3329,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
         $aParams = array_merge($aParams, array(
             'browse' => 'list',
-            'active' => 1,
-            'hidden' => 0,
+            'status' => BX_TIMELINE_STATUS_ACTIVE,
             'dynamic_mode' => true,
         ));
 

+ 2 - 1
modules/boonex/timeline/classes/BxTimelineSearchResult.php

@@ -21,10 +21,11 @@ class BxTimelineSearchResult extends BxBaseModNotificationsSearchResult
             'object_metatags' => 'bx_timeline',
             'title' => _t('_bx_timeline_page_title_browse'),
             'table' => 'bx_timeline_events',
-            'ownFields' => array('id', 'owner_id', 'type', 'action', 'object_id', 'object_privacy_view', 'content', 'title', 'description', 'views', 'rate', 'votes', 'score', 'sc_up', 'sc_down', 'comments', 'reports', 'reposts', 'date', 'active', 'hidden', 'pinned', 'sticked', 'promoted'),
+            'ownFields' => array('id', 'owner_id', 'type', 'action', 'object_id', 'object_privacy_view', 'content', 'title', 'description', 'views', 'rate', 'votes', 'score', 'sc_up', 'sc_down', 'comments', 'reports', 'reposts', 'date', 'status', 'pinned', 'sticked', 'promoted'),
             'searchFields' => array('title'),
             'restriction' => array(
                 'internal' => array('value' => 'timeline_common_post', 'field' => 'type', 'operator' => '='),
+                'status' => array('value' => BX_TIMELINE_STATUS_ACTIVE, 'field' => 'status', 'operator' => '='),
                 'active' => array('value' => '1', 'field' => 'active', 'operator' => '='),
             ),
             'paginate' => array('perPage' => getParam('bx_timeline_events_per_page'), 'start' => 0),

+ 2 - 1
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -1912,7 +1912,7 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
             }
         }
 
-        foreach($aVideos as $iVideo => $aVideo)
+        foreach($aVideos as $iVideo => $aVideo) {
             if(!$bMain || $sVap == BX_TIMELINE_VAP_OFF)
                 $aTmplVarsVideos[] = array(
                     'style_prefix' => $sStylePrefix,
@@ -1929,6 +1929,7 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
                         'src' => $sVapSrc . $iVideo . '/'
                     )) 
                 );
+        }
 
         return array( 
             'display' => $sDisplay,

+ 2 - 1
modules/boonex/timeline/install/langs/en.xml

@@ -219,7 +219,8 @@
 	<string name="_bx_timeline_txt_or_jump_to"><![CDATA[... or jump to:]]></string>
 	<string name="_bx_timeline_txt_jump_to_n_year"><![CDATA[Jump to {0} year]]></string>
 	<string name="_bx_timeline_txt_jump_to_recent"><![CDATA[Jump to recent posts]]></string>
-	<string name="_bx_timeline_txt_hot"><![CDATA[Hot post]]></string>
+        <string name="_bx_timeline_txt_status_deleted"><![CDATA[Deleted]]></string>
+        <string name="_bx_timeline_txt_hot"><![CDATA[Hot post]]></string>
 	<string name="_bx_timeline_txt_pinned"><![CDATA[Pinned post]]></string>
         <string name="_bx_timeline_txt_sticked"><![CDATA[Pinned for all post]]></string>
 	<string name="_bx_timeline_txt_promoted"><![CDATA[Promoted]]></string>

+ 3 - 2
modules/boonex/timeline/install/sql/enable.sql

@@ -302,7 +302,7 @@ INSERT INTO `sys_objects_search` (`ObjectName`, `Title`, `Order`, `ClassName`, `
 
 -- GRIDS: moderation tools
 INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `field_id`, `field_order`, `field_active`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_fields_translatable`, `filter_mode`, `sorting_fields`, `sorting_fields_translatable`, `visible_for_levels`, `override_class_name`, `override_class_file`) VALUES
-('bx_timeline_administration', 'Sql', 'SELECT * FROM `bx_timeline_events` WHERE 1 ', 'bx_timeline_events', 'id', 'date', 'active', '', 20, NULL, 'start', '', 'title,description', '', 'like', 'reports', '', 192, 'BxTimelineGridAdministration', 'modules/boonex/timeline/classes/BxTimelineGridAdministration.php');
+('bx_timeline_administration', 'Sql', 'SELECT * FROM `bx_timeline_events` WHERE 1 AND `active`=''1'' ', 'bx_timeline_events', 'id', 'date', 'status', '', 20, NULL, 'start', '', 'title,description', '', 'like', 'reports', '', 192, 'BxTimelineGridAdministration', 'modules/boonex/timeline/classes/BxTimelineGridAdministration.php');
 
 INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `translatable`, `chars_limit`, `params`, `order`) VALUES
 ('bx_timeline_administration', 'checkbox', '_sys_select', '2%', 0, '', '', 1),
@@ -330,7 +330,8 @@ INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `B
 
 -- CRON
 INSERT INTO `sys_cron_jobs` (`name`, `time`, `class`, `file`, `service_call`) VALUES
-('bx_timeline_hot', '0 * * * *', 'BxTimelineCronHot', 'modules/boonex/timeline/classes/BxTimelineCronHot.php', '');
+('bx_timeline_hot', '0 * * * *', 'BxTimelineCronHot', 'modules/boonex/timeline/classes/BxTimelineCronHot.php', ''),
+('bx_timeline_publishing', '* * * * *', 'BxTimelineCronPublishing', 'modules/boonex/timeline/classes/BxTimelineCronPublishing.php', '');
 
 
 -- PRELOADER

+ 2 - 2
modules/boonex/timeline/install/sql/install.sql

@@ -21,8 +21,8 @@ CREATE TABLE IF NOT EXISTS `bx_timeline_events` (
   `reports` int(11) unsigned NOT NULL default '0',
   `reposts` int(11) unsigned NOT NULL default '0',
   `date` int(11) NOT NULL default '0',
-  `active` tinyint(4) NOT NULL default '1',
-  `hidden` tinyint(4) NOT NULL default '0',
+  `status` enum ('active', 'awaiting', 'hidden', 'deleted') NOT NULL DEFAULT 'active',
+  `active` int(11) NOT NULL default '1',
   `pinned` int(11) NOT NULL default '0',
   `sticked` int(11) NOT NULL default '0',
   `promoted` int(11) NOT NULL default '0',