BxBaseModGeneralInstaller.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 $_bUpdateTimeline = false; // set to true to automatically register handlers for timeline module
  20. function __construct($aConfig)
  21. {
  22. parent::__construct($aConfig);
  23. }
  24. function enable($aParams)
  25. {
  26. $aResult = parent::enable($aParams);
  27. if (!$aResult['result']) // proces further only in case of successful enable
  28. return $aResult;
  29. BxDolImageTranscoder::registerHandlersArray($this->_aTranscoders);
  30. if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('timeline', 'add_handlers'))
  31. BxDolService::call('timeline', 'add_handlers', array($this->_aConfig['home_uri']));
  32. return $aResult;
  33. }
  34. function disable($aParams)
  35. {
  36. if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('timeline', 'delete_handlers'))
  37. BxDolService::call('timeline', 'delete_handlers', array($this->_aConfig['home_uri']));
  38. BxDolImageTranscoder::unregisterHandlersArray($this->_aTranscoders);
  39. BxDolImageTranscoder::cleanupObjectsArray($this->_aTranscoders);
  40. $aResult = parent::disable($aParams);
  41. if (!$aResult['result']) // we need to register it back if disabling failed
  42. BxDolImageTranscoder::registerHandlersArray($this->_aTranscoders);
  43. return $aResult;
  44. }
  45. function install($aParams, $bEnable = false)
  46. {
  47. return parent::install($aParams, $bEnable);
  48. }
  49. function uninstall($aParams, $bDisable = false)
  50. {
  51. // check if module is already waiting while files are deleting
  52. bx_import('BxDolInstallerUtils');
  53. if (BxDolInstallerUtils::isModulePendingUninstall($this->_aConfig['home_uri']))
  54. return array(
  55. 'message' => _t('_adm_err_modules_pending_uninstall_already'),
  56. 'result' => false,
  57. );
  58. // queue for deletion storage files
  59. $bSetModulePendingUninstall = false;
  60. foreach ($this->_aStorages as $s) {
  61. if (($o = BxDolStorage::getObjectInstance($s)) && $o->queueFilesForDeletionFromObject())
  62. $bSetModulePendingUninstall = true;
  63. }
  64. // delete comments and queue for deletion comments attachments
  65. bx_import('BxDolCmts');
  66. $iFiles = 0;
  67. BxDolCmts::onModuleUninstall ($this->_aConfig['name'], $iFiles);
  68. if ($iFiles)
  69. $bSetModulePendingUninstall = true;
  70. // if some files were added to the queue, set module as pending uninstall
  71. if ($bSetModulePendingUninstall) {
  72. BxDolInstallerUtils::setModulePendingUninstall($this->_aConfig['home_uri']);
  73. return array(
  74. 'message' => _t('_adm_err_modules_pending_uninstall'),
  75. 'result' => false,
  76. );
  77. }
  78. return parent::uninstall($aParams, $bDisable);
  79. }
  80. }
  81. /** @} */