BxBaseModGeneralAlertsResponse.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGeneralAlertsResponse extends BxDolAlertsResponse
  12. {
  13. protected $MODULE;
  14. protected $_oModule;
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  19. }
  20. public function response($oAlert)
  21. {
  22. $CNF = $this->_oModule->_oConfig->CNF;
  23. if('system' == $oAlert->sUnit && 'save_setting' == $oAlert->sAction && isset($CNF['PARAM_SEARCHABLE_FIELDS']) && $CNF['PARAM_SEARCHABLE_FIELDS'] == $oAlert->aExtras['option'])
  24. return $this->_oModule->_oDb->alterFulltextIndex();
  25. $sKey = 'OBJECT_VIDEOS_TRANSCODERS';
  26. if(isset($CNF[$sKey]) && !empty($CNF[$sKey]['mp4']) && strcmp($oAlert->sUnit , $CNF[$sKey]['mp4']) === 0 && $oAlert->sAction == 'transcoded')
  27. return $this->_onVideoTranscoded($oAlert->iObject, $oAlert->aExtras['ret']);
  28. }
  29. protected function _onVideoTranscoded($iGhostId, $bResult, $aParams = array())
  30. {
  31. $CNF = &$this->_oModule->_oConfig->CNF;
  32. if(!isset($CNF['FIELD_STATUS']))
  33. return;
  34. $sStorage = '';
  35. if(!empty($aParams['storage']))
  36. $sStorage = $aParams['storage'];
  37. else if(!empty($CNF['OBJECT_STORAGE_VIDEOS']))
  38. $sStorage = $CNF['OBJECT_STORAGE_VIDEOS'];
  39. else
  40. return;
  41. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  42. if(!$oStorage)
  43. return;
  44. $aGhost = $oStorage->getGhost($iGhostId);
  45. if(empty($aGhost) || !is_array($aGhost))
  46. return;
  47. $iContentId = (int)$aGhost['content_id'];
  48. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  49. if(empty($aContentInfo) || !is_array($aContentInfo))
  50. return;
  51. if(!isset($aContentInfo[$CNF['FIELD_STATUS']]) || $aContentInfo[$CNF['FIELD_STATUS']] != 'awaiting')
  52. return;
  53. $iNow = time();
  54. $bNotify = $iNow - $aContentInfo[$CNF['FIELD_ADDED']] > $this->_oModule->_oConfig->getDpnTime();
  55. $iSystemBotProfileId = (int)getParam('sys_profile_bot');
  56. if(!$bResult) {
  57. if((int)$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'failed'), array($CNF['FIELD_ID'] => $iContentId)) > 0) {
  58. $this->_oModule->onFailed($iContentId);
  59. if($bNotify)
  60. /**
  61. * @hooks
  62. * @hookdef hook-bx_base_general-publish_failed '{module_name}', 'publish_failed' - hook to notify about failed content publishing
  63. * - $unit_name - module name
  64. * - $action - equals `publish_failed`
  65. * - $object_id - content id
  66. * - $sender_id - system bot profile id
  67. * - $extra_params - array of additional params with the following array keys:
  68. * - `object_author_id` - [int] content author profile id
  69. * - `privacy_view` - [int] privacy for view action, equals to BX_DOL_PG_ALL, @see BxDolPrivacy
  70. * @hook @ref hook-bx_base_general-publish_failed
  71. */
  72. bx_alert($this->_oModule->getName(), 'publish_failed', $aContentInfo[$CNF['FIELD_ID']], $iSystemBotProfileId, array(
  73. 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  74. 'privacy_view' => BX_DOL_PG_ALL
  75. ));
  76. }
  77. return;
  78. }
  79. if(isset($CNF['FIELD_PUBLISHED']) && isset($aContentInfo[$CNF['FIELD_PUBLISHED']]) && $aContentInfo[$CNF['FIELD_PUBLISHED']] > $iNow)
  80. return;
  81. $oTranscoder = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  82. $aGhostsToCheck = $oStorage->getGhosts($aGhost['profile_id'], $iContentId);
  83. foreach($aGhostsToCheck as $aGhostToCheck) {
  84. $aGhostInfo = $oStorage->getFile((int)$aGhostToCheck['id']);
  85. if(strncmp($aGhostInfo['mime_type'], 'video/', 6) !== 0)
  86. continue;
  87. if(!$oTranscoder->isFileReady((int)$aGhostToCheck['id']))
  88. return;
  89. }
  90. if(!$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'active'), array($CNF['FIELD_ID'] => $iContentId)))
  91. return;
  92. $this->_oModule->onPublished($iContentId);
  93. if($bNotify)
  94. /**
  95. * @hooks
  96. * @hookdef hook-bx_base_general-publish_succeeded '{module_name}', 'publish_succeeded' - hook to notify about successfully published content
  97. * - $unit_name - module name
  98. * - $action - equals `publish_succeeded`
  99. * - $object_id - content id
  100. * - $sender_id - system bot profile id
  101. * - $extra_params - array of additional params with the following array keys:
  102. * - `object_author_id` - [int] content author profile id
  103. * - `privacy_view` - [int] privacy for view action, equals to BX_DOL_PG_ALL, @see BxDolPrivacy
  104. * @hook @ref hook-bx_base_general-publish_succeeded
  105. */
  106. bx_alert($this->MODULE, 'publish_succeeded', $aContentInfo[$CNF['FIELD_ID']], $iSystemBotProfileId, [
  107. 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  108. 'privacy_view' => BX_DOL_PG_ALL
  109. ]);
  110. }
  111. }
  112. /** @} */