1
0

BxBaseModGeneralAlertsResponse.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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(!empty($CNF[$sKey]) && is_array($CNF[$sKey]) && in_array($oAlert->sUnit, $CNF[$sKey]) && $oAlert->sAction == 'transcoded')
  27. return $this->_onVideoTranscoded($oAlert->iObject);
  28. }
  29. protected function _onVideoTranscoded($iGhostId, $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. if(isset($CNF['FIELD_PUBLISHED']) && isset($aContentInfo[$CNF['FIELD_PUBLISHED']]) && $aContentInfo[$CNF['FIELD_PUBLISHED']] > $iNow)
  55. return;
  56. $aTranscoders = array();
  57. foreach($CNF['OBJECT_VIDEOS_TRANSCODERS'] as $sKey => $sTranscoder)
  58. if(in_array($sKey, array('mp4', 'mp4_hd')))
  59. $aTranscoders[$sTranscoder] = BxDolTranscoder::getObjectInstance($sTranscoder);
  60. $aGhostsToCheck = $oStorage->getGhosts($aGhost['profile_id'], $iContentId);
  61. foreach($aGhostsToCheck as $aGhostToCheck)
  62. foreach($aTranscoders as $sTranscoder => $oTranscoder)
  63. if(!$oTranscoder->isFileReady($aGhostToCheck['id']))
  64. return;
  65. if((int)$this->_oModule->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS'] => 'active'), array($CNF['FIELD_ID'] => $iContentId)) > 0)
  66. $this->_oModule->onPublished($iContentId);
  67. }
  68. }
  69. /** @} */