BxBaseModGeneralAlertsResponse.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. if(!$bResult) {
  54. if((int)$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'failed'), array($CNF['FIELD_ID'] => $iContentId)) > 0)
  55. $this->_oModule->onFailed($iContentId);
  56. return;
  57. }
  58. $iNow = time();
  59. if(isset($CNF['FIELD_PUBLISHED']) && isset($aContentInfo[$CNF['FIELD_PUBLISHED']]) && $aContentInfo[$CNF['FIELD_PUBLISHED']] > $iNow)
  60. return;
  61. $oTranscoder = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  62. $aGhostsToCheck = $oStorage->getGhosts($aGhost['profile_id'], $iContentId);
  63. foreach($aGhostsToCheck as $aGhostToCheck) {
  64. $aGhostInfo = $oStorage->getFile((int)$aGhostToCheck['id']);
  65. if(strncmp($aGhostInfo['mime_type'], 'video/', 6) !== 0)
  66. continue;
  67. if(!$oTranscoder->isFileReady((int)$aGhostToCheck['id']))
  68. return;
  69. }
  70. if(!$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'active'), array($CNF['FIELD_ID'] => $iContentId)))
  71. return;
  72. $this->_oModule->onPublished($iContentId);
  73. /*
  74. * Process metas.
  75. * Note. It's essential to process metas a the very end,
  76. * because all data related to an entry should be already
  77. * processed and are ready to be passed to alert.
  78. */
  79. $this->_oModule->processMetasAdd($iContentId);
  80. }
  81. }
  82. /** @} */