modaction.class.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Represents an action to a controller or connector.
  12. *
  13. * @property string $namespace The key of the Namespace this action belongs to.
  14. * @property int $parent The ID of the parent action of this action.
  15. * @property string $controller The name of the controller to use
  16. * @property boolean $haslayout Whether or not to load the header/footer of the action. Deprecated (use
  17. * modManagerController class properties instead).
  18. * @property string $lang_topics Any lexicon topics to load in conjunction with the specified controller. Deprecated
  19. * (use modManagerController class method instead)
  20. * @property string $assets Any action-specific assets. Not used.
  21. * @property string $help_url An absolute URL that this Action can use for displaying a Help box
  22. *
  23. * @see modManagerController
  24. * @package modx
  25. */
  26. class modAction extends modAccessibleSimpleObject {
  27. /**
  28. * Overrides xPDOObject::save to cache the actionMap.
  29. *
  30. * {@inheritdoc}
  31. */
  32. public function save($cacheFlag = null) {
  33. $saved = parent::save($cacheFlag);
  34. if ($saved && empty($this->xpdo->config[xPDO::OPT_SETUP])) {
  35. $this->rebuildCache();
  36. }
  37. return $saved;
  38. }
  39. /**
  40. * Overrides xPDOObject::save to cache the actionMap.
  41. *
  42. * {@inheritdoc}
  43. */
  44. public function remove(array $ancestors = array()) {
  45. $removed = parent::remove($ancestors);
  46. if ($removed && empty($this->xpdo->config[xPDO::OPT_SETUP])) {
  47. $this->rebuildCache();
  48. }
  49. return $removed;
  50. }
  51. /**
  52. * Rebuilds the action map cache.
  53. *
  54. * @see modCacheManager::generateActionMap
  55. *
  56. * @access public
  57. * @param array $options An array of options to pass to the cacheManager->generateActionMap method
  58. * @return boolean True if successful.
  59. */
  60. public function rebuildCache(array $options = array()) {
  61. $rebuilt = false;
  62. $cacheKey= $this->xpdo->context->get('key') . '/actions';
  63. $this->xpdo->getCacheManager();
  64. if ($this->xpdo->cacheManager->generateActionMap($cacheKey, $options)) {
  65. $rebuilt = true;
  66. }
  67. return $rebuilt;
  68. }
  69. }