BxDolAIToolContentUpdate.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. use NeuronAI\Tools\PropertyType;
  10. use NeuronAI\Tools\ToolProperty;
  11. use NeuronAI\Tools\ArrayProperty;
  12. use NeuronAI\Tools\ObjectProperty;
  13. class BxDolAIToolContentUpdate extends BxDolAITool
  14. {
  15. public function __construct()
  16. {
  17. parent::__construct(
  18. 'content_update',
  19. 'Use this tool to update content. Always use "content_structure" tool to get knowledge about content modules fields. Available modules: ' . $this->getContentModules() . '.',
  20. );
  21. }
  22. protected function properties(): array
  23. {
  24. return [
  25. new ToolProperty(
  26. name: 'module',
  27. type: PropertyType::STRING,
  28. description: 'The module name to perform content changes on. Use "system" for site accounts. ',
  29. required: true
  30. ),
  31. new ToolProperty(
  32. name: 'content_id',
  33. type: PropertyType::INTEGER,
  34. description: 'Content ID to update.',
  35. required: true
  36. ),
  37. new ArrayProperty(
  38. name: 'data',
  39. description: 'Key-value pairs of data fields to add, where keys match the field names. Never use fields what aren\'t defined in content structure.',
  40. required: true,
  41. items: new ObjectProperty(
  42. name: 'parameter',
  43. properties: [
  44. new ToolProperty('name', PropertyType::STRING, 'Parameter name', true),
  45. new ToolProperty('value', PropertyType::STRING, 'Parameter value', true),
  46. ]
  47. )
  48. ),
  49. new ToolProperty(
  50. name: 'profile_id',
  51. type: PropertyType::INTEGER,
  52. description: 'Author profile ID.',
  53. required: true
  54. )
  55. ];
  56. }
  57. public function __invoke(string $module, int $content_id, array $data, int $profile_id): array
  58. {
  59. if ($profile_id) {
  60. $GLOBALS['glForceCurrentProfileId'] = $profile_id;
  61. }
  62. $a = bx_srv('system', 'update', [$module, $content_id, $this->convertArrayToKeyValue($data)], 'TemplServiceContent');
  63. $GLOBALS['glForceCurrentProfileId'] = 0;
  64. return $a;
  65. }
  66. }