Skip to content

Expose computed ticket priority semantics in class schemas - #10

Open
agent-qv wants to merge 1 commit into
Combodo:masterfrom
agent-qv:pr/expose-priority-matrix
Open

agent-qv wants to merge 1 commit into
Combodo:masterfrom
agent-qv:pr/expose-priority-matrix

Conversation

@agent-qv

@agent-qv agent-qv commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Closes #9

Problem

In iTop, ticket priority is recomputed from impact and urgency on each save
(ComputeValues() calls ComputePriority()). It is displayed as a normal enum field by
get-class-schema, so an MCP client can reasonably but incorrectly attempt to set it
directly. create-user-request's defaults (impact 3, urgency 4) silently map to the
lowest priority, with nothing telling the caller why.

Solution

DatamodelService now reads the impact x urgency -> priority matrix out of the
ComputePriority() source embedded in the datamodel XML, so it stays correct on an
instance that customized it. Parsing is best-effort against the shape iTop ships
($aPriorities = array(impact => array(urgency => priority))); anything else yields no
matrix, and the section is simply omitted rather than guessed at. It rides in the
existing class-schema cache entry, so cache hits pay nothing extra.

get-class-schema now flags priority as computed when a matrix is available, and
renders the full matrix alongside the field list. create-user-request's docblock now
says priority is derived, that the defaults give the lowest one, and points at
get-class-schema for the actual matrix (the part that varies per instance).

Testing

Verified the parsing against tests/phpunit/data/datamodel-production.xml (a real
production datamodel export) - the extracted matrix for UserRequest matches the raw
ComputePriority() source in that file exactly. Existing test suite passes/fails
identically before and after this change (the pre-existing failures are unrelated
fixture/environment issues, not introduced by this PR).

Note

This PR follows up on the design discussion in #9. Happy to adjust the source/API if you'd
prefer a different approach once the planned schema webservice is further along.

priority looks like a plain enum in a ticket's field list, but iTop overwrites
it on every save from impact and urgency (ComputeValues() calls
ComputePriority()). create-user-request defaults to impact 3 (one person) and
urgency 4 (low), which maps to the lowest priority - so a ticket opened
through the MCP without explicit values lands as "low", outage or not, with
nothing saying why.

DatamodelService now reads the matrix out of the ComputePriority() source
embedded in the datamodel XML, so it stays right on an instance that
customized it, and get-class-schema renders it alongside the fields. Parsing
is best-effort against the shape iTop ships; anything else yields no matrix
and the section is omitted rather than guessed at. Verified against the
matrix in tests/phpunit/data/datamodel-production.xml, which matches exactly.
It rides in the existing class-schema cache entry, so cache hits pay nothing.

The create-user-request docblock now carries what holds everywhere - priority
is derived, the defaults give the lowest one, what the impact and urgency
codes mean - and points at get-class-schema only for the matrix itself, the
part that actually varies per instance.
Copilot AI balanced review requested due to automatic review settings September 1, 2026 11:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds instance-aware ticket priority semantics to class schemas.

Changes:

  • Parses priority matrices from datamodel XML.
  • Marks and renders computed priority information.
  • Documents impact and urgency for user-request creation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Service/DatamodelService.php Extracts and caches priority matrices.
src/Tools/schema/iTopSchemaTools.php Renders computed priority details.
src/Tools/core/create/iTopCreateTools.php Documents derived priority inputs.
Suppressed comments (1)

src/Service/DatamodelService.php:150

  • This pattern scans the entire method for any numeric nested array; it is not scoped to the $aPriorities assignment. A customized method containing another lookup such as $other = [9 => [8 => 7]] will expose that lookup as a priority row (and can merge it with the real matrix). Extract the named assignment first and reject the result unless its complete initializer matches the supported shape.
        // Each 'impact => array(urgency => priority, ...)' entry of the outer array.
        if (!preg_match_all('/(\d+)\s*=>\s*(?:array\s*\(|\[)([^)\]]*)(?:\)|\])/s', $code, $matches, PREG_SET_ORDER)) {
            return null;

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +122 to +123
// A class that does not redefine ComputePriority() inherits its parent's.
$priorityMatrix = $this->getPriorityMatrixFromXml($className) ?? $inheritedPriorityMatrix;
Comment on lines +79 to +81
$computed = ($code === 'priority' && ($info['priority_matrix'] ?? null) !== null)
? ' [COMPUTED from impact and urgency, setting it directly has no effect - see below]'
: '';
@jf-cbd

jf-cbd commented Sep 9, 2026

Copy link
Copy Markdown
Member

Hello @agent-qv, thank you for your PR. We're not willing to have this in our repo, but we're working on extensibility so people willing to add such functionalities will be able to do so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pending review

Development

Successfully merging this pull request may close these issues.

Expose computed ticket priority semantics in class schemas

3 participants