BxBaseModGeneralInstaller.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolStudioInstaller');
  12. bx_import('BxDolStorage');
  13. bx_import('BxDolImageTranscoder');
  14. bx_import('BxDolService');
  15. class BxBaseModGeneralInstaller extends BxDolStudioInstaller
  16. {
  17. protected $_aStorages = array (); // storage objects to automatically delete files from upon module uninstallation, don't add storage objects used in image transcoder objects
  18. protected $_aTranscoders = array (); // image transcoder objects to automatically register/unregister necessary alerts for
  19. protected $_aConnections = array (); // connections objects associated with module data, it must be defined which content is associated with the connection, the key is connection object name and value is array (possible array values: type, conn, table, field_id), if 'type' == 'profiles', then it is considered profiles connection and other possible param is 'conn' ('initiator', 'content' or 'both') when 'type' == 'custom' (or ommited), then other possible params are 'conn', 'table' and 'field_id'
  20. protected $_bUpdateTimeline = false; // set to true to automatically register handlers for timeline module
  21. function __construct($aConfig)
  22. {
  23. parent::__construct($aConfig);
  24. }
  25. function enable($aParams)
  26. {
  27. $aResult = parent::enable($aParams);
  28. if (!$aResult['result']) // proces further only in case of successful enable
  29. return $aResult;
  30. BxDolImageTranscoder::registerHandlersArray($this->_aTranscoders);
  31. if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('timeline', 'add_handlers'))
  32. BxDolService::call('timeline', 'add_handlers', array($this->_aConfig['home_uri']));
  33. return $aResult;
  34. }
  35. function disable($aParams)
  36. {
  37. if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('timeline', 'delete_handlers'))
  38. BxDolService::call('timeline', 'delete_handlers', array($this->_aConfig['home_uri']));
  39. BxDolImageTranscoder::unregisterHandlersArray($this->_aTranscoders);
  40. BxDolImageTranscoder::cleanupObjectsArray($this->_aTranscoders);
  41. $aResult = parent::disable($aParams);
  42. if (!$aResult['result']) // we need to register it back if disabling failed
  43. BxDolImageTranscoder::registerHandlersArray($this->_aTranscoders);
  44. return $aResult;
  45. }
  46. function install($aParams, $bEnable = false)
  47. {
  48. return parent::install($aParams, $bEnable);
  49. }
  50. function uninstall($aParams, $bDisable = false)
  51. {
  52. // check if module is already waiting while files are deleting
  53. bx_import('BxDolInstallerUtils');
  54. if (BxDolInstallerUtils::isModulePendingUninstall($this->_aConfig['home_uri']))
  55. return array(
  56. 'message' => _t('_adm_err_modules_pending_uninstall_already'),
  57. 'result' => false,
  58. );
  59. // queue for deletion storage files
  60. $bSetModulePendingUninstall = false;
  61. foreach ($this->_aStorages as $s) {
  62. if (($o = BxDolStorage::getObjectInstance($s)) && $o->queueFilesForDeletionFromObject())
  63. $bSetModulePendingUninstall = true;
  64. }
  65. // delete comments and queue for deletion comments attachments
  66. bx_import('BxDolCmts');
  67. $iFiles = 0;
  68. BxDolCmts::onModuleUninstall ($this->_aConfig['name'], $iFiles);
  69. if ($iFiles)
  70. $bSetModulePendingUninstall = true;
  71. // if some files were added to the queue, set module as pending uninstall
  72. if ($bSetModulePendingUninstall) {
  73. BxDolInstallerUtils::setModulePendingUninstall($this->_aConfig['home_uri']);
  74. return array(
  75. 'message' => _t('_adm_err_modules_pending_uninstall'),
  76. 'result' => false,
  77. );
  78. }
  79. // delete associated connections
  80. if ($this->_aConnections)
  81. bx_import('BxDolConnection');
  82. foreach ($this->_aConnections as $sObjectConnections => $a) {
  83. $o = BxDolConnection::getObjectInstance($sObjectConnections);
  84. if (!$o)
  85. continue;
  86. $sFuncSuffix = 'DeleteInitiatorAndContent';
  87. if (isset($a['conn']) && 'initiator' == $a['conn'])
  88. $sFuncSuffix = 'DeleteInitiator';
  89. elseif (isset($a['conn']) && 'content' == $a['conn'])
  90. $sFuncSuffix = 'DeleteContent';
  91. if (isset($a['type']) && 'profiles' == $a['type']) {
  92. $sFunc = 'onModuleProfile' . $sFuncSuffix;
  93. $o->$sFunc($this->_aConfig['name']);
  94. } else {
  95. $sFunc = 'onModule' . $sFuncSuffix;
  96. $o->$sFunc($a['table'], $a['field_id']);
  97. }
  98. }
  99. return parent::uninstall($aParams, $bDisable);
  100. }
  101. }
  102. /** @} */