Repository navigation
Open
Milestone
Description
Current state
- Dispatchers are private. Every
w2p_Core_BaseObjectcreates its ownw2p_System_Dispatcherand subscribes only itself to its own events (BaseObject::_subscribeToEvents()). No module can hear another module's events, such as "a task was deleted" or "a project was deleted". Modules that keep data tied to tasks or projects can't clean up after them. - Events carry no data.
w2p_System_Eventhas a$dataproperty but no getter, andBaseObjectnever passes data (new w2p_System_Event(get_class($this), 'postDeleteEvent'), BaseObject.class.php lines 225-527). - Events are named by concrete class. Project deletes remove their tasks through
w2p_Actions_BulkTasks(CProject::hook_postDelete()), so those deletes publish asw2p_Actions_BulkTasks, notCTask. A listener forCTaskwould miss them. - Task moves bypass events.
CTask::moveTaskBetweenProjects()moves subtasks with raw SQL (updateSubTasksProject()), and only the root task isstore()d. No event says "these tasks changed project". - Bug: in
Dispatcher::publish(), the wildcard-resource loopforeach($this->_listeners['*'] as $event => $listeners)(line 75) overwrites$eventwith a string key and passes that string to listeners whose parameter is typedw2p_System_Event. That's a TypeError on PHP 8.
Intended solution
- Shared dispatcher. Add an app-wide instance,
w2p_System_Dispatcher::shared().BaseObjectkeeps publishing to its own dispatcher for itshook_*methods, then publishes the same event to the shared one. - Event data. Add
w2p_System_Event::getData(). Shared events carry['object' => $this, 'id' => <key>, 'module' => <module>, 'original' => <row before an update, or null>].- Take the
originalsnapshot (one extra SELECT) only when the shared dispatcher has listeners for that class and event. AddhasListeners($resource, $event), so unrelated saves pay nothing.
- Take the
- Publish under the module's resource too. Publish under the base module name (
tasks,projects) as well as the concrete class, so subclasses likew2p_Actions_BulkTasksreach listeners for tasks. - A move event.
CTask::moveTaskBetweenProjects()publishespostMoveEventwith['task_id', 'old_project', 'new_project', 'moved_task_ids' => <the task and every subtask>]. - Registration. A module's main class can implement a new interface,
w2p_Interfaces_Subscriber, withstatic getSubscriptions(): array, e.g.[['tasks', 'postDeleteEvent'], ['tasks', 'postMoveEvent'], ['projects', 'postDeleteEvent']].- Bootstrap reads subscriptions from active modules once and caches them in the session, as tabs already are.
- Listener objects are only created when a matching event fires.
- Isolation. Each shared-listener call is wrapped in try/catch with
error_log(), asw2p_System_HookHandleralready does. A broken module can't break a core save or delete. - Fix the bug. Fix the
$eventoverwrite inDispatcher::publish().
First consumer
The Cards module (caseysoftware/modules-cards) needs task delete, task move and project delete to keep its cards consistent.
Other uses
- Generic tagging can drop tag links when any object is deleted.
- Files and Links could clean up after task deletes the same way.
Metadata
Metadata
Assignees
Labels
No labels
Activity