BxBaseModGeneralAlertsResponse.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. private $_oModuleHidden = null;
  15. public function __get($sName) {
  16. if ($sName === '_oModule') {
  17. return $this->_oModuleHidden ??= BxDolModule::getInstance($this->MODULE);
  18. }
  19. throw new \Exception("Unknown property: $sName");
  20. }
  21. public function __set($sName, $o) {
  22. if ($sName === '_oModule') {
  23. $this->_oModuleHidden = $o;
  24. }
  25. throw new \Exception("Unknown property: $sName");
  26. }
  27. public function response($oAlert)
  28. {
  29. $CNF = $this->_oModule->_oConfig->CNF;
  30. if('system' == $oAlert->sUnit && 'save_setting' == $oAlert->sAction && isset($CNF['PARAM_SEARCHABLE_FIELDS']) && $CNF['PARAM_SEARCHABLE_FIELDS'] == $oAlert->aExtras['option'])
  31. return $this->_oModule->_oDb->alterFulltextIndex();
  32. $sKey = 'OBJECT_VIDEOS_TRANSCODERS';
  33. if(isset($CNF[$sKey]) && !empty($CNF[$sKey]['mp4']) && strcmp($oAlert->sUnit , $CNF[$sKey]['mp4']) === 0 && $oAlert->sAction == 'transcoded')
  34. return $this->_onVideoTranscoded($oAlert->iObject, $oAlert->aExtras['ret']);
  35. }
  36. protected function _onVideoTranscoded($iGhostId, $bResult, $aParams = array())
  37. {
  38. $CNF = &$this->_oModule->_oConfig->CNF;
  39. if(!isset($CNF['FIELD_STATUS']))
  40. return;
  41. $sStorage = '';
  42. if(!empty($aParams['storage']))
  43. $sStorage = $aParams['storage'];
  44. else if(!empty($CNF['OBJECT_STORAGE_VIDEOS']))
  45. $sStorage = $CNF['OBJECT_STORAGE_VIDEOS'];
  46. else
  47. return;
  48. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  49. if(!$oStorage)
  50. return;
  51. $aGhost = $oStorage->getGhost($iGhostId);
  52. if(empty($aGhost) || !is_array($aGhost))
  53. return;
  54. $iContentId = (int)$aGhost['content_id'];
  55. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  56. if(empty($aContentInfo) || !is_array($aContentInfo))
  57. return;
  58. if(!isset($aContentInfo[$CNF['FIELD_STATUS']]) || $aContentInfo[$CNF['FIELD_STATUS']] != 'awaiting')
  59. return;
  60. $iNow = time();
  61. $bNotify = $iNow - $aContentInfo[$CNF['FIELD_ADDED']] > $this->_oModule->_oConfig->getDpnTime();
  62. $iSystemBotProfileId = (int)getParam('sys_profile_bot');
  63. if(!$bResult) {
  64. if((int)$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'failed'), array($CNF['FIELD_ID'] => $iContentId)) > 0) {
  65. $this->_oModule->onFailed($iContentId);
  66. if($bNotify)
  67. /**
  68. * @hooks
  69. * @hookdef hook-bx_base_general-publish_failed '{module_name}', 'publish_failed' - hook to notify about failed content publishing
  70. * - $unit_name - module name
  71. * - $action - equals `publish_failed`
  72. * - $object_id - content id
  73. * - $sender_id - system bot profile id
  74. * - $extra_params - array of additional params with the following array keys:
  75. * - `object_author_id` - [int] content author profile id
  76. * - `privacy_view` - [int] privacy for view action, equals to BX_DOL_PG_ALL, @see BxDolPrivacy
  77. * @hook @ref hook-bx_base_general-publish_failed
  78. */
  79. bx_alert($this->_oModule->getName(), 'publish_failed', $aContentInfo[$CNF['FIELD_ID']], $iSystemBotProfileId, array(
  80. 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  81. 'privacy_view' => BX_DOL_PG_ALL
  82. ));
  83. }
  84. return;
  85. }
  86. if(isset($CNF['FIELD_PUBLISHED']) && isset($aContentInfo[$CNF['FIELD_PUBLISHED']]) && $aContentInfo[$CNF['FIELD_PUBLISHED']] > $iNow)
  87. return;
  88. $oTranscoder = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  89. $aGhostsToCheck = $oStorage->getGhosts($aGhost['profile_id'], $iContentId);
  90. foreach($aGhostsToCheck as $aGhostToCheck) {
  91. $aGhostInfo = $oStorage->getFile((int)$aGhostToCheck['id']);
  92. if(strncmp($aGhostInfo['mime_type'], 'video/', 6) !== 0)
  93. continue;
  94. if(!$oTranscoder->isFileReady((int)$aGhostToCheck['id']))
  95. return;
  96. }
  97. if(!$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'active'), array($CNF['FIELD_ID'] => $iContentId)))
  98. return;
  99. $this->_oModule->onPublished($iContentId);
  100. if($bNotify)
  101. /**
  102. * @hooks
  103. * @hookdef hook-bx_base_general-publish_succeeded '{module_name}', 'publish_succeeded' - hook to notify about successfully published content
  104. * - $unit_name - module name
  105. * - $action - equals `publish_succeeded`
  106. * - $object_id - content id
  107. * - $sender_id - system bot profile id
  108. * - $extra_params - array of additional params with the following array keys:
  109. * - `object_author_id` - [int] content author profile id
  110. * - `privacy_view` - [int] privacy for view action, equals to BX_DOL_PG_ALL, @see BxDolPrivacy
  111. * @hook @ref hook-bx_base_general-publish_succeeded
  112. */
  113. bx_alert($this->MODULE, 'publish_succeeded', $aContentInfo[$CNF['FIELD_ID']], $iSystemBotProfileId, [
  114. 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  115. 'privacy_view' => BX_DOL_PG_ALL
  116. ]);
  117. }
  118. }
  119. /** @} */