BxBaseModGeneralInstaller.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. bx_import('BxDolInstallerUtils');
  52. if (BxDolInstallerUtils::isModulePendingUninstall($this->_aConfig['home_uri']))
  53. return array(
  54. 'message' => _t('_adm_err_modules_pending_uninstall_already'),
  55. 'result' => false,
  56. );
  57. $bSetModulePendingUninstall = false;
  58. foreach ($this->_aStorages as $s) {
  59. if (($o = BxDolStorage::getObjectInstance($s)) && $o->queueFilesForDeletionFromObject())
  60. $bSetModulePendingUninstall = true;
  61. }
  62. if ($bSetModulePendingUninstall) {
  63. BxDolInstallerUtils::setModulePendingUninstall($this->_aConfig['home_uri']);
  64. return array(
  65. 'message' => _t('_adm_err_modules_pending_uninstall'),
  66. 'result' => false,
  67. );
  68. }
  69. return parent::uninstall($aParams, $bDisable);
  70. }
  71. }
  72. /** @} */