Repository navigation
Description
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
- In
BaseObject, work out the project id before callingaddHistory()and pass it as the fifth argument. Most project-scoped tables already have a<prefix>_projectcolumn: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. Forprojectsitself, useproject_id. A protectedgetProjectId()on BaseObject (default: read<prefix>_projectif the property exists, else 0) would let a class likeCProjectoverride it. - On a project's History tab, select
history_project = <project_id>(plus the project's ownprojectsrows), still filtered by the existing per-module permission conditions. - 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
History: record each entry's project and list them on the project tab
Migration 072: fill history_project for existing history entries