BxBaseModGeneralInstaller.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. protected $_aMenuTriggers = array(); // list of menu triggers, it must be specified in the module which adds menu item and in modules where menu items are added, @see BxDolMenu::processMenuTrigger
  22. function __construct($aConfig)
  23. {
  24. parent::__construct($aConfig);
  25. }
  26. function enable($aParams)
  27. {
  28. $aResult = parent::enable($aParams);
  29. if (!$aResult['result']) // proces further only in case of successful enable
  30. return $aResult;
  31. BxDolImageTranscoder::registerHandlersArray($this->_aTranscoders);
  32. if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('timeline', 'add_handlers'))
  33. BxDolService::call('timeline', 'add_handlers', array($this->_aConfig['home_uri']));
  34. if ($this->_aMenuTriggers) {
  35. bx_import('BxDolMenu');
  36. foreach ($this->_aMenuTriggers as $sMenuTriggerName)
  37. BxDolMenu::processMenuTrigger($sMenuTriggerName);
  38. }
  39. return $aResult;
  40. }
  41. function disable($aParams)
  42. {
  43. if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('timeline', 'delete_handlers'))
  44. BxDolService::call('timeline', 'delete_handlers', array($this->_aConfig['home_uri']));
  45. BxDolImageTranscoder::unregisterHandlersArray($this->_aTranscoders);
  46. BxDolImageTranscoder::cleanupObjectsArray($this->_aTranscoders);
  47. $aResult = parent::disable($aParams);
  48. if (!$aResult['result']) // we need to register it back if disabling failed
  49. BxDolImageTranscoder::registerHandlersArray($this->_aTranscoders);
  50. return $aResult;
  51. }
  52. function install($aParams, $bEnable = false)
  53. {
  54. return parent::install($aParams, $bEnable);
  55. }
  56. function uninstall($aParams, $bDisable = false)
  57. {
  58. // check if module is already waiting while files are deleting
  59. bx_import('BxDolInstallerUtils');
  60. if (BxDolInstallerUtils::isModulePendingUninstall($this->_aConfig['home_uri']))
  61. return array(
  62. 'message' => _t('_adm_err_modules_pending_uninstall_already'),
  63. 'result' => false,
  64. );
  65. // queue for deletion storage files
  66. $bSetModulePendingUninstall = false;
  67. foreach ($this->_aStorages as $s) {
  68. if (($o = BxDolStorage::getObjectInstance($s)) && $o->queueFilesForDeletionFromObject())
  69. $bSetModulePendingUninstall = true;
  70. }
  71. // delete comments and queue for deletion comments attachments
  72. bx_import('BxDolCmts');
  73. $iFiles = 0;
  74. BxDolCmts::onModuleUninstall ($this->_aConfig['name'], $iFiles);
  75. if ($iFiles)
  76. $bSetModulePendingUninstall = true;
  77. // if some files were added to the queue, set module as pending uninstall
  78. if ($bSetModulePendingUninstall) {
  79. BxDolInstallerUtils::setModulePendingUninstall($this->_aConfig['home_uri']);
  80. return array(
  81. 'message' => _t('_adm_err_modules_pending_uninstall'),
  82. 'result' => false,
  83. );
  84. }
  85. // delete associated connections
  86. if ($this->_aConnections) {
  87. bx_import('BxDolConnection');
  88. foreach ($this->_aConnections as $sObjectConnections => $a) {
  89. $o = BxDolConnection::getObjectInstance($sObjectConnections);
  90. if (!$o)
  91. continue;
  92. $sFuncSuffix = 'DeleteInitiatorAndContent';
  93. if (isset($a['conn']) && 'initiator' == $a['conn'])
  94. $sFuncSuffix = 'DeleteInitiator';
  95. elseif (isset($a['conn']) && 'content' == $a['conn'])
  96. $sFuncSuffix = 'DeleteContent';
  97. if (isset($a['type']) && 'profiles' == $a['type']) {
  98. $sFunc = 'onModuleProfile' . $sFuncSuffix;
  99. $o->$sFunc($this->_aConfig['name']);
  100. } else {
  101. $sFunc = 'onModule' . $sFuncSuffix;
  102. $o->$sFunc($a['table'], $a['field_id']);
  103. }
  104. }
  105. }
  106. //request Timeline cleaning
  107. if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('timeline', 'delete_module_events'))
  108. BxDolService::call('timeline', 'delete_module_events', array($this->_aConfig['home_uri']));
  109. return parent::uninstall($aParams, $bDisable);
  110. }
  111. }
  112. /** @} */