TrioCMS Developers
← Docs

Writing an import/scan stepInternals

The AI import is a scanner: every file in /home/www.triocms.net/ai_import/*.php runs in filename order. Each step is a closure that returns an exit code + message.

<?php
// ai_import/NN_name.php
return function (TcmsImportContext $ctx): array {
    // ... do work, reading $ctx->html / $ctx->dom() ...
    return ['code' => 0, 'msg' => 'what happened'];  // code 0 = ok/green, non-zero = red
};

The runner records {name, code, ms, msg} per step into a results array and writes live progress to tmp/<domain>.progress.json after each step:

{ "step":3, "total":9, "name":"30_meta_tags", "status":"ok",
  "done":false, "results":[ {"name":"10_fetch_index","code":0,"ms":11,"msg":"..."} ] }

The dashboard polls that file and renders a green/red report card. A step may also return a plain string (treated as exit 0). The same exit-code + report-card contract is used by the Domain Control Panel scans.

Context (TcmsImportContext): url, domain, html, dir, siteDir, data[], site[], model + helpers fetch(), dom(), absUrl(), saveAsset(), put().