|
dolibarr 25.0.0-alpha
|
Tool class for CRUD operations on Dolibarr objects TODO Remove all tools in this file. More...


Public Member Functions | |
| __construct (DoliDB $db, $user=null, $conf=null) | |
| Constructor. | |
| getDefinitions () | |
| Returns an array of tool definitions, including name, description, and input schema. | |
| getRequiredRights (string $toolName) | |
| Per-object-type rights are checked inside this class (PERM_MAP / delete map), including the two permission namespaces Dolibarr uses for the same action. | |
| writeConfirmationPreview (string $toolName, array $args) | |
| Preview of the record this call would write. | |
| getCategories () | |
| Return categories this tool belongs to. | |
| execute (string $name, array $args) | |
| Executes the requested tool function based on its name. | |
Public Member Functions inherited from McpTool | |
| __construct ($db, $user, $conf) | |
| Constructor. | |
| isSystem () | |
| Return true if this is a system/infrastructure tool that must always remain visible and executable regardless of the admin allow-list. | |
Private Member Functions | |
| addLineItem (array $args) | |
| Entry point for the 'add_line_item' tool. | |
| completeCreatedProduct (Product $newprod, CommonObject $object, array $args, $price, $vat) | |
| Complete a product just created on the fly (create_missing_products) with the information the source document carries beyond the product card: | |
| findProduct ($identifier) | |
| Find a product by various identifiers (ID, Ref, Barcode, Label). | |
| deleteObject (array $args) | |
| Delete a document object. | |
| checkPermission (string $type, string $mode='write') | |
| Check if the current user has permission for the given object type. | |
| checkAccessToObject (string $type, CommonObject $object) | |
| Check that the current user is allowed to work on an already fetched object. | |
| instantiate (string $type) | |
| Factory Helper to instantiate Dolibarr objects. | |
Additional Inherited Members | |
Public Attributes inherited from McpTool | |
| const | RIGHTS_UNDECLARED = 'undeclared' |
| Default of getRequiredRights(): the class never declared anything, deny. | |
| const | NO_WRITE = '' |
| Returned by writeConfirmationPreview() when the tool writes nothing. | |
Tool class for CRUD operations on Dolibarr objects TODO Remove all tools in this file.
Must be into the objectname.class.php to follow the same structure than APIs.
Definition at line 37 of file crud_objects.class.php.
| ToolCrudObjects::__construct | ( | DoliDB | $db, |
| $user = null, | |||
| $conf = null ) |
Constructor.
Aligned with McpHandler's instantiation contract: new $className($db, $user, $conf). Accepting $user via DI allows this tool to work in HTTP MCP context where no PHP web session exists. Some sibling tool classes (ToolThirdParty, ToolCategories, ToolProducts) already use this signature; this aligns ToolCrudObjects with them.
| DoliDB | $db | Database handler |
| User | null | $user | Service user provided by McpHandler (from AI_MCP_USER_ID) |
| Conf | null | $conf | Dolibarr config (optional) |
Definition at line 51 of file crud_objects.class.php.
|
private |
Entry point for the 'add_line_item' tool.
Adds line to an already existing object. Instantiates the document and calls the line processing helper.
| array{object_type:string,parent_id:int,product_id?:int,description?:string,quantity?:float|int,unit_price?:float|int,vat_rate?:float|int} | $args Tool arguments for adding a line item |
Definition at line 1125 of file crud_objects.class.php.
Referenced by execute().
|
private |
Check that the current user is allowed to work on an already fetched object.
fetch() selects on the rowid only and does not filter on the entity, so a bare fetch() is an IDOR: it happily returns a record of another entity or of a thirdparty the user has no access to. restrictedArea() called with $mode = 1 returns 0/1 instead of emitting an HTML error page, which is what we need in this JSON API context.
| string | $type | Object type key. |
| CommonObject | $object | Object already loaded with fetch(). |
Definition at line 1431 of file crud_objects.class.php.
References $object, dol_syslog(), restrictedArea(), and user.
|
private |
Check if the current user has permission for the given object type.
| string | $type | Object type key. |
| string | $mode | 'write' to check the create/update permission, 'delete' to check the dedicated delete permission. |
Definition at line 1400 of file crud_objects.class.php.
References user.
|
private |
Complete a product just created on the fly (create_missing_products) with the information the source document carries beyond the product card:
| Product | $newprod | Product just created |
| CommonObject | $object | Parent document the line belongs to |
| array<string,mixed> | $args Line arguments | |
| ?float | $price | Line buying price (HT), when provided |
| float | $vat | Line VAT rate |
Definition at line 1194 of file crud_objects.class.php.
References $conf, $object, dol_syslog(), getDolGlobalInt(), isModEnabled(), and user.
|
private |
Delete a document object.
| array{object_type | string, id: int|string} $args Arguments containing type and ID. |
Definition at line 1346 of file crud_objects.class.php.
References $id.
Referenced by execute().
| ToolCrudObjects::execute | ( | string | $name, |
| array | $args ) |
Executes the requested tool function based on its name.
| string | $name | The name of the tool to execute. |
| array<string,mixed> | $args The arguments for the tool (key-value pairs). |
Reimplemented from McpTool.
Definition at line 505 of file crud_objects.class.php.
References $conf, $mysoc, addLineItem(), deleteObject(), and user.
|
private |
Find a product by various identifiers (ID, Ref, Barcode, Label).
| string | int | $identifier | The search term (ID, ref, barcode, etc.). |
Definition at line 1254 of file crud_objects.class.php.
References getEntity().
| ToolCrudObjects::getCategories | ( | ) |
Return categories this tool belongs to.
Used by the intent parser to filter available tools.
Reimplemented from McpTool.
Definition at line 493 of file crud_objects.class.php.
| ToolCrudObjects::getDefinitions | ( | ) |
Returns an array of tool definitions, including name, description, and input schema.
Reimplemented from McpTool.
Definition at line 229 of file crud_objects.class.php.
| ToolCrudObjects::getRequiredRights | ( | string | $toolName | ) |
Per-object-type rights are checked inside this class (PERM_MAP / delete map), including the two permission namespaces Dolibarr uses for the same action.
| string | $toolName | Tool being executed. |
Reimplemented from McpTool.
Definition at line 412 of file crud_objects.class.php.
|
private |
Factory Helper to instantiate Dolibarr objects.
| string | $type | Object type key (e.g., 'proposal', 'invoice'). |
| Exception | If the type is unknown or class not found. |
Definition at line 1463 of file crud_objects.class.php.
| ToolCrudObjects::writeConfirmationPreview | ( | string | $toolName, |
| array | $args ) |
Preview of the record this call would write.
| string | $toolName | Tool that would run. |
| array<string,mixed> | $args Arguments it would run with. |
Reimplemented from McpTool.
Definition at line 424 of file crud_objects.class.php.
References McpTool\NO_WRITE.