Skip to content

Auto Folder Creation (Document Library)

Module: DMS Reference, Auto Folder Creation. It drives where Document Routing auto-publish files the reviewed copy. Off by default.

How this page was verified

Traced on Medco in June 2026. On 2026-09-06 the admin screen, the reference-type list, the gating flags and the publish-time function were re-checked on master and the big five.

Overview

Auto Folder Creation lets an admin define, per project, the nested Document Library subfolder structure that reviewed documents are auto-filed into when they are published at approver sign-off. The admin picks an ordered list of document-metadata reference types (Area, Discipline, Document Type, and so on). Those become the folder levels, and each published document self-files into the branch that matches its own metadata.

It replaces the old hard-coded approach, where the folder hierarchy was one of three fixed shapes driven by a single integer, ts_projects.project_east_java (Ophir / East Java / Medco), applied at upload time by getLibCodeAutoGenerateFromDocMaster(). The structure is now data-driven and editable per project, and the filing moved to routing auto-publish. See Upload, library folder and Sign Off.

Only master, Jadestone and Medco have it

JOTRE and Timas have neither the admin screen, nor the autopublish_auto_folder_creation key, nor getProjectAutoFolderSettings(). They still have the generic custom-subfolder flags, so the default tree from subfolder_custom_default is all they can build.

What an admin configures

In DMS Reference, Auto Folder Creation (autopublish_auto_folder_creation.php), per project, the admin selects and orders any subset of the reference types in $referencesCode. The list differs per fork:

Code storedLabelMasterJadestoneMedco
areanumberArea Codeyesyesyes
disciplineDiscipline Codeyesyesyes
doctypeDocument Type Codeyesyesyes
doccatDocument Category Codeyesyesyes
function_codeFunction Codeyesyesyes
doc_classificationClassification Codeyesyesyes
field_code, group_code, contract_noJadestone's own referencesyes
business_unit, region, location, system_code, vendor_package, code_package_identifier, sdrl_code, drawing_category, originatorMedco's extended setyes

The chosen list, in order, is the folder tree. For example ["areanumber", "discipline", "doctype"] files a document into .../<Area>/<Discipline>/<Doc Type>/.

Screen actions:

  • Load a project's current settings (cmd=get_settings).
  • Save the selected reference list (act=save_settings writes ts_auto_creation_folder_settings.settings_data as a JSON array).
  • Copy from another project (act=copyAutoFolderSetting).
  • A project with no row gets the default ['discipline'].

Storage and seeding

  • Table ts_auto_creation_folder_settings, one row per project: project_id, settings_data (JSON array of reference-type codes).

  • Medco only: a one-off script, migrations/scripts/MIG-013_ts_auto_creation_folder_settings.php, back-fills each project from its legacy project_east_java value so nothing changes until an admin edits it:

    legacy project_east_javaseeded settings_data
    0 (Ophir)areanumber, originator, discipline, doctype, system_code, drawing_category
    1 (East Java)areanumber, discipline
    2 (Medco)business_unit, region, areanumber, discipline, doctype, location, system_code, vendor_package, code_package_identifier, sdrl_code

    Idempotent (TRUNCATE plus insert); projects with project_east_java NULL or out of range are skipped for the admin to set by hand. Master and Jadestone have no such seed; their projects start from the ['discipline'] default.

How it runs, at auto-publish

The structure is applied when an approver's sign-off publishes the reviewed copy, not at upload, inside autoPublishDocumentToCustomSubfoler() in routing.inc.php. The function exists in all five forks. In master the order of checks is:

  1. File the document into the project's Deliverables root folder (getLibCodeDeliverablesByProjectCode()).
  2. Only if enable_autocreation_subfolder_custom = '1' does it build a nested subfolder. It starts from the default tree, DOCLIB_SUBFOLDER[subfolder_custom_default].tree, and, if autopublish_auto_folder_creation = '1', overrides it with the per-project tree from getProjectAutoFolderSettings($projectId, true)["tree"].
  3. For each reference type in the tree, it resolves the document's value (label_combined_code_desc) and finds or creates that subfolder. A level whose DMS reference flag (enable_*) is off is skipped. originator has no enable_* flag and is always included where it is in the list.
  4. If any required level's value is empty, it aborts the subfolder placement (validToSetInSubFolder = false) and the document stays at the Deliverables root.
  5. If library_folder_access_default = '1', it also assigns folder access to the project's resource groups.

Config flags it depends on

FlagRoleIn the seed of
autopublish_auto_folder_creationMaster switch for this feature: use the per-project tree, else fall back to the default tree. Default 0.master, Jadestone, Medco
enable_autocreation_subfolder_customMust be 1 for any custom subfolder to be built at all. Default 0.all five
subfolder_custom_defaultNames the fallback tree used when the per-project feature is off.all five
library_folder_access_defaultAuto-assign folder access to resource groups.all five
DMS enable_* (for example enable_discipline)A tree level is skipped if its reference flag is off.per fork, see inweb_config

Both switches must be on

autopublish_auto_folder_creation alone does nothing unless enable_autocreation_subfolder_custom is also 1. The per-project tree is only consulted inside the custom-subfolder branch. Both default to 0, so the feature is off out of the box.

Database tables affected

TableOperationNotes
ts_auto_creation_folder_settingsinsert / update / deleteper-project tree (admin screen)
ts_doc_libraryinsert / selectfind or create each subfolder at publish
ts_map_documents_libraryinsertmap the published document to its leaf folder
ts_projectsselectproject_east_java, Medco's seed only

Gotchas and known issues

  • Off by default and double-gated. Easy to think it is broken when it is just not enabled.
  • Medco keeps the legacy path too. getLibCodeAutoGenerateFromDocMaster() (project_east_java) is still present and called in Medco's actMultipleProcessNew(). The other forks no longer have that function. Confirm which governs filing on a Medco build.
  • Silent fallback to the Deliverables root when any tree level's value is missing on the document. No error; the document just is not nested.
  • Applies at publish, not upload. A freshly uploaded, not-yet-approved document sits in the Deliverables folder until its reviewed _R copy is published.

Instance differences

Checked on 2026-09-06.

InstanceDifference
JadestoneReference list adds field_code, group_code and contract_no.
MedcoReference list has 15 entries. Legacy project_east_java seed script and the legacy filing function are both present.
JOTRENo admin screen, no autopublish_auto_folder_creation key, no getProjectAutoFolderSettings(). Only the default tree.
TimasSame as JOTRE.
  • Upload files into the Deliverables folder only.
  • Sign Off is the auto-publish step that triggers folder creation.
  • inweb_config lists the flags above.