Skip to content

History: history_project is never set, so history can't be filtered by project #525

Closed

Description

@caseysoftware

Branches: dev-5.0.0 and dev-6.0.0

What happens
history.history_project is always 0. Nothing in the application ever writes a project id into it, so history entries cannot be grouped or filtered by project. A project's History tab only shows edits to the project record itself, not changes to its tasks, task logs, files, links, events or forums.

Cause
addHistory($table, $id, $action = 'modify', $description = '', $project_id = 0) (includes/cleanup_functions.php ~L2630) is the only code that inserts into history, and it does write history_project = (int) $project_id. But none of its callers pass the fifth argument:

  • w2p_Core_BaseObject::store() hook, ~L807: addHistory($this->_tbl, $id, $this->_event, $name)
  • w2p_Core_BaseObject::delete(), ~L845: addHistory($this->_tbl, $id, 'delete')
  • index.php L69 / L123 and users/vw_usr_sessions.php L78 (login/logout)

The function's own TODO comment already notes this: "project_id and module_id should be provided in order to filter history entries".

Nothing reads the column either: modules/history/index_table.php filters the project tab with history_table = 'projects' AND history_item = <project_id> (L25–29), which is why only the project's own record shows up.

Evidence
On a test database after the unit tests and a page crawl: 70 history rows across billingcode, budgets, companies, contacts, departments, files, file_folders, links, projects, task_log and users, and history_project <> 0 on none of them, including the files, links and task logs that belong to a project.

Fix

  1. In BaseObject, work out the project id before calling addHistory() and pass it as the fifth argument. Most project-scoped tables already have a <prefix>_project column: tasks.task_project, task_log.task_log_project, files.file_project, links.link_project, events.event_project, forums.forum_project, contacts.contact_project, budgets_assigned.budget_project. For projects itself, use project_id. A protected getProjectId() on BaseObject (default: read <prefix>_project if the property exists, else 0) would let a class like CProject override it.
  2. On a project's History tab, select history_project = <project_id> (plus the project's own projects rows), still filtered by the existing per-module permission conditions.
  3. Optional migration to backfill existing rows from the item tables, e.g. UPDATE history h JOIN tasks t ON h.history_table = 'tasks' AND h.history_item = t.task_id SET h.history_project = t.task_project, and the same for the other tables. Deleted items can't be backfilled.

Effort: small-to-medium (one BaseObject change + the tab query; the migration is optional).

Activity

  1. added 2 commits that reference this issue on Oct 31, 2026
    5abf4e4
    4fb818a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions