BxBaseModGeneralInstaller.php 5.4 KB

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