Repository navigation
Asset CI Link Developer Guide
How the asset ↔ CI link (#201) is built, and the rules a change must keep. The user page is Linking an asset to its configuration item; the reasoning is in the design.
In one breath: one table of periods (asset_ci_links), one service (AssetCiLinkService) behind the asset page, the CI page and REST, and one JS card (CiAssetLink) drawn on both pages. The link is an identity. It is never an edge in the CMDB graph.
🗄️ schema · 🧠 rules · ✏️ write paths that call in · 🔌 REST · 🖥️ UI · 🧪 tests
| 🎨 | File | What it does there |
|---|---|---|
| 🗄️ |
database/freeitsm.sql, includes/db_verify_schema.php, includes/db_verify_indexes.php, api/system/db_verify.php
|
asset_ci_links, its two indexes ((asset_id, unlinked_at), (cmdb_object_id, unlinked_at)) and one FK (asset_id → assets, CASCADE). No FK on cmdb_object_id, on purpose |
| 🧠 | includes/services/asset_ci_links.php |
AssetCiLinkService - every rule: access, restriction, one live link per side, link / Replace / unlink, CI delete, merge, the card's details, history values |
| ✏️ | includes/services/cmdb.php |
deleteObject() calls AssetCiLinkService::ciDeleted() and clearAssetRefFields() inside its transaction, before the deletes |
| ✏️ | includes/services/asset_merge.php |
REFERENCES has ['asset_ci_links', 'asset_id', 'ci_links'], handled by AssetCiLinkService::mergeLinks(). NOT_REFERENCES has asset_ci_links.original_asset_id
|
| ✏️ | api/assets/review_merge.php |
Passes ci_links_seen and ci_link_keep from the merge window |
| 🖥️ | api/assets/ci_link.php |
The page endpoint: both sides' reads, both pickers, the merge preview, link and unlink |
| 🖥️ |
api/assets/save_asset_type.php, api/assets/get_asset_types.php
|
Part C: asset_types.cmdb_class_id (saved only when sent; read on its own query so the list loads before Database Verification) and the active classes for the settings dropdown |
| 🖥️ | api/cmdb/asset_card_settings.php |
CMDB → Settings → Asset card (Cap::CMDB_ASSET_CARD) |
| 🖥️ |
assets/js/ci-asset-link.js, assets/css/ci-asset-link.css
|
The card. side: 'asset' on the asset page, side: 'cmdb' on the CI page. Also draws the asset side's "If this failed" line and the Create linked CI form |
| 🖥️ | asset-management/index.php |
Mounts the card in Key info section cmdb (#ciLinkSection); atlSaw('cmdb', …) feeds the "hidden by this type" notice |
| 🖥️ |
cmdb/object.js, cmdb/object.php
|
Mounts the card under Details (#cmdbAssetLink); scrolls to #o2Blast when the asset card's Show links there |
| 🖥️ | asset-management/settings/index.php |
The merge window's CI-link block (loadMergeCiLinks(), renderMergeCiLinks()) |
| 🖥️ | includes/services/asset_type_layout.php |
cmdb in SECTIONS; hidden in the Peripheral and Mobile presets |
| 🖥️ | api/assets/get_asset_history.php |
Turns cmdb_link values (ci:<id>) into names, or restricted
|
| 🔌 |
api/v1/lib/routes.php, api/v1/resources/assets.php, api/v1/resources/cmdb.php, api/v1/lib/permissions.php, api/v1/spec.json, api/v1/lib/openapi_schemas.php
|
Four routes, linked_ci / linked_asset blocks, the asset_ci_links permission, the catalogue entries and typed fields |
| 🧪 | tests/asset-ci-link.php |
66 checks: page, service and REST, restriction, Replace races, delete, merge, companies |
| 🧪 | tests/asset-merge.php |
Its guard fails if an asset column is missing from REFERENCES / NOT_REFERENCES
|
What you don't touch: includes/cmdb_impact.php. The asset is not in the graph, so the impact walk never learns about the link. The asset card simply asks the CI's own blast radius.
| Column | Rule |
|---|---|
asset_id |
Follows a merge (the kept asset sees the whole history) |
original_asset_id, asset_name
|
The asset the link was made on and its name then. Never moved, never updated |
cmdb_object_id |
No FK: a deleted CI's rows stay |
linked_at / linked_by_id / link_source |
link_source is ui, api:<key name>, or integration:<name> (reserved for #199) |
unlinked_at / unlinked_by_id / unlink_source / unlink_reason |
NULL while live. Reasons: unlinked, replaced, ci_deleted, asset_merged
|
ci_name / ci_class_name |
Written by close() when a period ends, so the history still reads after the CI is gone |
One live link per asset and per CI is enforced in the service, not the schema (MySQL has no partial unique index). Every write locks the asset row, then the CI row (FOR UPDATE), then the live link rows, in that order everywhere, including unlink() from the CI side, which re-reads under the lock.
The service never reads a session or a key. It takes an ActorContext (company scope) and an access array:
['assets_read' => bool, 'cmdb_read' => bool, 'assets_write' => bool, 'cmdb_write' => bool]| Adapter | Built by | Read | Write |
|---|---|---|---|
| Page | accessForAnalyst() |
analystCanAccessModule() |
analystCanWriteModule() - today always full for Assets and CMDB; follows a future Read only level automatically |
| REST | accessForApiKey($key, $forWrite) |
assets.read / cmdb_objects.read on the key |
The route already demanded asset_ci_links.create/delete
|
Restriction is decided by the other side's read flag: from the asset, cmdb_read; from the CI, assets_read. When it is false, everything about the other end becomes {restricted: true}: the current link, every history entry, conflict messages ("…linked to an asset you cannot open"), and REST blocks. Ids are dropped too: a restricted block never carries an id.
The asset card setting (cmdb_asset_card_fields) only filters which details assetView() returns. It is applied after the access decision, so it can never widen access.
link(asset, ci, replace, replaces[])
lock asset, lock CI, same company? -> different_company
asset's live link is this CI? -> unchanged (idempotent retry)
conflicts = live link on asset + live link on CI
conflicts and not replace -> ci_already_linked / asset_already_linked
replace and sorted(conflicts) != sorted(replaces) -> link_changed
close each conflict 'replaced', insert, history lines
replaces is exactly what the person saw. A refused link sends back conflictIds() (ids only, which say nothing about the record), the UI confirms and resends them. If anyone changed the link in between, the sets differ and nothing happens.
createLinkedCi() holds one transaction: lock the asset → already linked? return that CI (created: false, the retry case) → the type's class (mappedClass(), active only) or no_class_mapped → possible_matches unless ignore_matches → CmdbService::createInTransaction() → link() → commit → then CmdbService::announceCreated().
createObject() now begins and commits only when it owns the transaction, so it can run inside this one; createInTransaction() also holds back the cmdb.object.created workflow event, so a create that rolls back - a required property the CMDB refuses, a link that fails - never announces a CI that does not exist. CmdbService::requiredProperties() is what the form asks for.
$expectedLinkId (the card's link_id) must still be the live link, or link_changed. REST takes it as ?link_id=; leaving it out unlinks whatever is live.
CmdbService::deleteObject() → AssetCiLinkService::ciDeleted($ids) for the CI and every descendant, inside the delete's transaction and before any row goes, because close() reads the CI's name and class. Then clearAssetRefFields() deletes asset_field_values of ref fields whose config.ref_kind is cmdb_object pointing at those ids, with a field:<key> history row storing the id (as other link-field history rows do).
AssetMergeService::merge(..., $ciLinks) with $ciLinks = ['seen' => [...], 'keep_link_id' => N]:
-
seengiven and not equal to the live links of the two assets →ci_link_changed - both linked and
keep_link_idis not one of them →ci_link_choice_required(also what a caller passingnullgets) - the other link is closed
asset_merged, then every row'sasset_idmoves to the kept asset
Neither CI is touched. Both errors throw inside the merge's transaction, so nothing is merged.
asset_history rows for the link use field_name = 'cmdb_link' and values ci:<id>, never a name. historyValue() resolves them per reader: the CI's name (live, or ci_name from the link row once it is deleted) for someone who can open the CMDB, a restricted configuration item for someone who cannot, and for REST ci:<id> or restricted. If you add another place that shows asset history, run it through historyValue().
-
TRAP: the merge guard. A new column naming an asset in
asset_ci_linksmust go inREFERENCESorNOT_REFERENCES, ortests/asset-merge.phpfails. That is the point:original_asset_idmust not move. -
TRAP:
ciDeleted()before the deletes. Called after,close()finds no CI and the history row loses its name. -
TRAP: no PUT. The API router, its CORS header and the method override only know GET/POST/PATCH/DELETE (and IIS often blocks PUT), so linking is
POST /assets/{id}/ci-link. It is still safe to retry. -
TRAP: a static call resolves its class before its arguments.
AssetCiLinkService::restBlock($conn, apiAssetCiAccess($key), …)fatals if the class is loaded only insideapiAssetCiAccess(). The resource file requires the service at the top. -
Headless screenshots of the CI page stop after the fourth section: its entry animation never finishes without a compositor. Use
--force-prefers-reduced-motion.
Hyper-V discovery binds CIs to discovered objects with the same shape: periods, actor and source at both ends, restricted readers, a decision refused if the state it was made on changed. An integration that links assets calls AssetCiLinkService::link() with link_source = 'integration:<name>' and an access array saying it may write. It never links on a name alone.
FreeITSM — an open-source IT Service Management platform · github.com/edmozley/freeitsm · MIT licence
- Installation
- ⏰ Scheduled tasks (cron jobs)
-
Architecture
- ↳ 🧹 Root folder tidy (URL routing)
- ↳ 🔗 Database Integrity (FKs & constraints)
- ↳ 🛠️ Database Verification — Developer Guide
- ↳ 🧩 Service Layer (UI + API share code)
- ↳ 🪤 Code traps (the TRAP: comments)
- ↳ 📝 Commenting for the Engineering wiki
- ↳ 🛠️ Engineering wiki scanner - Developer Guide
- ↳ 📊 Service-Layer progress
- 🤝 Contributing (read before a pull request)
- 🧪 Developer tests
- AI Providers
- Internationalisation (i18n)
- Timezones & Time Handling
- 📅 Date & Time Formats
- 💱 Currencies
- 🧭 The sidebar (optional module rail)
- 🧩 Preference templates
- 🔀 Display order (modules, Watchtower cards) — Developer Guide
- Theming & Dark Mode
- 🗂️ Recent — getting back to what you were doing
- ⌨️ Command palette (⌘K)
- 🔍 Searching inside tickets
- 📄 Attached documents
-
Mobile‑Friendly
- ↳ 🎫 Mobile: Tickets
- ↳ 💻 Mobile: Assets
- ↳ 📅 Mobile: Calendar
- ↳ 📚 Mobile: Knowledge
- ↳ 🚦 Mobile: Service Status
- ↳ 🗼 Mobile: Watchtower
- ↳ 🧩 Mobile: Problem Management
- ↳ 🔁 Mobile: Change Management
- ↳ 💿 Mobile: Software
- ↳ ✅ Mobile: Tasks
- ↳ 📝 Mobile: Forms
- ↳ 📄 Mobile: Contracts
- ↳ 📄 Mobile: Domains
- ↳ 📄 Mobile: People
- ↳ 🚀 Mobile: Projects
- ↳ 🗂️ Mobile: Files
- ↳ 🎓 Mobile: LMS
- ↳ 🗺️ Mobile: CMDB
- ↳ 🗺️ Mobile: Network Mapper
- ↳ 🧭 Mobile: Process Mapper
- ↳ ⚙️ Mobile: Workflow
- ↳ 🖥️ Mobile: System
- ↳ 📊 Mobile: Reporting
- ↳ 📖 Mobile: System Wiki
- ↳ 🙋 Mobile: Self-Service Portal
- ↳ 🧰 Mobile: Techniques & Tricks
-
Security
- Layer 1 — which modules you can enter
- ↳ 🧩 Module Access Control
- ↳ 🛠️ Module Access — Developer Guide
- ↳ 🔌 Switching modules off
- ↳ 🛠️ Module availability — Developer Guide
- ↳ 📐 Module availability — design (#217)
- Layer 2 — what you can administer
- ↳ 🎭 Roles & Permissions
- ↳ 🛠️ Roles — Developer Guide
- ↳ 🔤 Why capabilities are constants
- Layer 3 — the System module
- ↳ 🔑 Admin Access Control
- Hardening
- ↳ 📄 Security review response 2026-08
- ↳ 🛡️ Security hardening 2026-08
- ↳ 🛠️ Security hardening 2026-08 — Developer Guide
- ↳ 🛡️ Round three — plain English
- ↳ 🛠️ Round three — Developer Guide
- ↳ 🛡️ CSRF protection (S4) — Developer Guide
- Single Sign-On (SSO)
- 🗂️ LDAP & Active Directory
- 📇 CardDAV contact sync
- Browser Extension
- API Reference
-
🔌 REST API — how it works
- ↳ 📋 Proposal: custom fields, inventory import and change evidence (#194)
- ↳ 🛠️ Custom fields, evidence + inventory - review (#195-#197)
- ↳ 🛠️ Long forms in a task's Work view - review (#198)
- ↳ 🎫 REST API: Tickets
- ↳ 💻 REST API: Assets
- ↳ 🔴 REST API: Problems
- ↳ 🟠 REST API: Changes
- ↳ 📚 REST API: Knowledge
- ↳ ✅ REST API: Tasks
- ↳ 🗄️ REST API: CMDB
- ↳ 📜 REST API: Contracts
- ↳ 🗓️ REST API: Calendar
- ↳ 💿 REST API: Software
- ↳ 🌐 REST API: Domains
- ↳ 🚦 REST API: Service Status
- ↳ ☀️ REST API: Morning Checks
- ↳ 📝 REST API: Forms
- ↳ ⚙️ REST API: Workflow
- ↳ 🏷️ REST API: Cost centres
- ↳ 🧑💼 REST API: Analysts
- ↳ 🗺️ REST API: Network Mapper
- ↳ 🧭 Using the API docs page
- ↳ 📐 OpenAPI specification
- ↳ ✅ OpenAPI: kept correct
- ↳ 🛠️ Maintaining the catalogue
- Watchtower
-
Tickets
- ↳ 🛠️ Inbox.js map — Developer Guide
- ↳ 🛠️ Tickets settings — Developer Guide
- ↳ 🗂️ The ticket workspace
- ↳ 📊 The ticket table
- ↳ 📋 Rota copy and paste — Developer Deep Dive
- ↳ ✅ Checklists & SOPs
- ↳ ☑️ Mandatory fields
- ↳ 🧾 Custom ticket fields
- ↳ 🏷️ Ticket categories
- ↳ 👥 Assigning tickets to a team, and escalation
- ↳ 🏢 One board across every company
- ↳ Mailbox Authentication
- ↳ 📤 Email send log
- ↳ 📎 Attachment size limits and large emails
- ↳ Basic IMAP mailboxes
- ↳ Email rendering & images
- ↳ SLA Management
- ↳ WhatsApp channel
-
↳
✈️ Telegram channel - ↳ ⭐ CSAT company scope and filters — Developer Guide
- ↳ 👥 Microsoft Teams channel
- ↳ 🗨️ Mattermost channel
- ↳ 💬 Web chat channel
- ↳ 🟣 Slack channel
- ↳ 🔗 Linking tickets
- ↳ ⓘ Record previews
- ↳ 📝 Ticket notes: internal or shared
- ↳ 🗒️ Canned responses
- ↳ ✉️ Limiting replies to particular senders
- ↳ 📨 Telling the analyst a ticket is theirs
- ↳ ✍️ Email signatures
- ↳ 🌐 The public web address
- ↳ 🔢 Ticket numbering
- ↳ 🙋 Raising a ticket for someone else
- ↳ 🔀 Merging tickets
- ↳ 🔒 Confidential tickets
- ↳ 👥 Portal managers
- ↳ 👁 Who has seen a ticket
- ↳ 📜 Reading long tickets
- ↳ ⑂ Splitting tickets
- ↳ ✅ Selecting several tickets
- ↳ 🗂️ The folder pane
- ↳ 🔽 Just my tickets, or no closed ones
- ↳ 🛠️ Snoozing tickets — Developer Guide
- ↳ 👥 Collision detection
- ↳ ⏱️ Time tracking
- ↳ 📄 Case reports - a ticket and its work as one PDF
- ↳ 📅 Scheduled work in your own calendar
- Problem Management
- Tasks
- 🚀 Projects
-
Assets
- ↳ 🏢 Moving an asset between companies
- ↳ 📍 Shared asset locations
- ↳ 🧑💼 Assigning assets to analysts
- ↳ 📆 Warranty and lease alerts
- ↳ 📄 Leases
- ↳ 🔭 Saved table views
- ↳ 🖨️ Recording anything, and importing it
- ↳ 🧩 Asset type layouts
- ↳ 🕒 Inventory freshness
- ↳ 🔗 Linked configuration item
- ↳ 🔌 Connected assets
- ↳ 🔍 Asset review
- ↳ 🏷️ QR asset labels
- ↳ 📋 Who holds what, and handover documents
- ↳ 🖥️ The inventory agent (PowerShell)
- ↳ 🗄️ Proxmox VE servers
- ↳ ☁️ VMware Cloud Director servers
- ↳ 🪟 Hyper-V and Failover Clusters
- ↳ 🔗 Linking equipment to tickets
- ↳ ☑️ Follow-up tasks on a ticket
- Knowledge
- Change Management
- Calendar
- Morning Checks
- Reporting
- Software
-
Forms
- ↳ 🎨 The form designer — Developer Guide
- ↳ 📐 Layout & the grid — Developer Guide
- ↳ 🗂️ Collections — grouping submissions
- ↳ 📄 Submissions as PDFs
- ↳ ⚡ What happens next — a form's own actions
- ↳ 🛠️ Sections & conditional logic — Developer Guide
- ↳ 🛠️ Lookup fields — Developer Guide
- ↳ 🛡️ Catalogue request approvals
- People
- Domains
- 🗂️ Files
- Contracts
- Service Status
- 🔔 Notifications
- 🚨 War Room
- Self-Service Portal
- LMS
- Process Mapper
- CMDB
- Network Mapper
- Workflows
- Issue trackers (Jira, Azure DevOps)
- 📡 Zabbix (monitoring)
- 💬 Microsoft Teams alerts
- 📞 3CX (phone system)
- System
-
Overview
- ↳ 📊 Progress tracker
- ↳ Concepts & vocabulary
- ↳ Email routing & mailboxes
- ↳ Settings: global vs per-company
- ↳ Users & self-service
- ↳ Staff cross-company access
- ↳ 🏢 One board across every company
- ↳ Worked examples
- ↳ Pitfalls & gotchas
- ↳ Scope: what it's for
- ↳ 🛠️ Developer Guide (make a module multi-company)
- ↳ 🗄️ Case study: CMDB (a linked graph)
- ↳ 🧪 Test harness (prove it's isolated)
- What this is
-
🐞 Bugs resolved
- ↳ ⚙️ #214 A "contains" condition did not match capitals
- ↳ ⚙️ #216 A workflow email from a chosen mailbox always failed
- ↳ 🐳 The Docker image was missing PHP extensions
- ↳ 🌐 A failed DNS lookup read as a missing record
- ↳ 🔒 A link could change data
- ↳ 🔒 Access outlived its removal
- ↳ 🔒 Knowledge articles could run scripts
- ↳ 🔒 Knowledge writes ignored permissions
- ↳ 🔒 Company boundaries (Oct 2026)
- ↳ 🔒 Smaller gaps (Oct 2026)
- ↳ 🔒 Escaped text could leave its attribute
- ↳ 🔒 Task descriptions were not cleaned
- ↳ 🔒 Task documents ignored company scope
- ↳ 🔒 Repeating tasks ignored company scope
- ↳ 📬 #183 Mailbox checks overlapped
- ↳ 🌐 #188 Transfer lock shown off when unknown
- ↳ ✅ #184 Subtask names and Overdue
- ↳ 🧩 #186 Teams: the buttons did nothing
- ↳ 🔒 Text in a change could run script
- ↳ 🔒 AI settings changed without the AI permission
- ↳ 🚪 #178 Deleting an analyst failed
- ↳ 🎫 A team with no departments showed 0 tickets
- ↳ 🚀 Projects: adding a phase did nothing on Save
- ↳ 🔒 Leavers could still sign in
- ↳ 🖼️ Logo and courses broke on Apache with PHP-FPM
- ↳ 🔢 Chat tickets ignored your ticket numbering
- ↳ 📅 Dates shown as a dash, or in server time
- ↳ 🔒 Assets → Users showed people from other companies
- ↳ 🔒 Restricted analysts could read other modules' data
- ↳ 🖼️ Replies with a picture in the thread failed to send
- ↳ 📎 Reply attachments never reached the customer
- ↳ 🛠️ Outbound email attachments — Developer Guide
- ↳ 🔑 A global SSO provider was missing from the portal
- ↳ 🔀 Behind a proxy, the SSO redirect said http
- ↳ ✏️ The portal tagline moved when you saved it
- ↳ 🎨 The portal settings screen forgot what you saved
- ↳ 🛡️ The approvals inbox said "Error" and nothing else
- ↳ 📄 A table's answers were missing from the PDF
- ↳ ◉ A single-select column let you tick every option
- ↳ 📐 The portal ignored a form's field widths
- ↳ 📋 The tasks board stopped taking clicks
- ↳ 🗂️ #121 The index list is out of date after upgrading
- ↳ 📅 #133 The calendar subscription was empty
- ↳ 📋 #131 Tasks always reopened on the board
- ↳ 💥 #129 Every page returned HTTP 500 after upgrading
- ↳ 🐳 #127 A PHP warning above the System page
- ↳ 🕐 #126 Notes stamped with the server's clock
- ↳ 🌍 Storing every date in UTC
- ↳ 🚪 The portal was down for everyone signed in
- ↳ ⚙️ #120 Workflow notes could never be written
- ↳ ⚙️ #123 Three errors when running Database Verification
- ↳ 📝 #122 The description box was a stub in the corner
- ↳ 💣 Demo data deleted real accounts
- ↳ 🔐 #117 Sign-in redirected to the wrong address
- ↳ 🎨 #108 The priority dot was invisible
- ↳ ⏱️ #116 Time logged from the right-click menu
- ↳ 🔑 #114 API keys refused by our own guard
- ↳ 🗂️ #110 Assigning a task told nobody
- ↳ 🚪 #107 Signed out while still working
- ↳ 📎 #103 "Share with Requester" reached nobody
- ↳ 🔍 #102 Search found nothing for hyphens
- ↳ 🪟 #101 Source code editor opened behind
- ↳ ☑️ #88 Subtasks could not be ticked off
- ↳ 💻 #84 Asset deep link selected nothing
- ↳ 🎫 #79 A new ticket arrived with no status
- ↳ 📧 #79 A ticket from email did not say so
- ↳ 🔔 #78 Bell opened to nothing
- ↳ 📬 #77 Mail only collected from Inbox
- ↳ 🔐 #74 The default password could not be changed
- ↳ 🚦 #70 Renaming an impact level
- ↳ 📤 #67 App-only mailboxes could not send
- ↳ 📭 #45 Verify only ever worked for Microsoft
- ↳ 📭 #45 IMAP reported as not authenticated
- ↳ ✉️ An email template stopped escaping itself
- ↳ 🕐 The portal dashboard showed the wrong time
- ↳ 🔢 The folder said 99 and the list showed 96