{"action":"created","issue":{"url":"https://api.github.com/repos/symphonycms/symphony-2/issues/2366","labels_url":"https://api.github.com/repos/symphonycms/symphony-2/issues/2366/labels{/name}","comments_url":"https://api.github.com/repos/symphonycms/symphony-2/issues/2366/comments","events_url":"https://api.github.com/repos/symphonycms/symphony-2/issues/2366/events","html_url":"https://github.com/symphonycms/symphony-2/issues/2366","id":60099383,"number":2366,"title":"Delegate tracking a delegate","user":{"login":"designermonkey","id":221344,"avatar_url":"https://avatars.githubusercontent.com/u/221344?v=3","gravatar_id":"","url":"https://api.github.com/users/designermonkey","html_url":"https://github.com/designermonkey","followers_url":"https://api.github.com/users/designermonkey/followers","following_url":"https://api.github.com/users/designermonkey/following{/other_user}","gists_url":"https://api.github.com/users/designermonkey/gists{/gist_id}","starred_url":"https://api.github.com/users/designermonkey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/designermonkey/subscriptions","organizations_url":"https://api.github.com/users/designermonkey/orgs","repos_url":"https://api.github.com/users/designermonkey/repos","events_url":"https://api.github.com/users/designermonkey/events{/privacy}","received_events_url":"https://api.github.com/users/designermonkey/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-03-06T13:05:47Z","updated_at":"2015-03-08T10:02:12Z","closed_at":null,"body":"Is there any way we can have one delegate know if another has fired? I'll explain, as that sounds weird...\r\n\r\nI want to track all the SQL statements that are run for say, a Section save event (create/edit/delete delegates). I know there is the delegate that fires for each SQL statement, but at that point there is no context as to what called it, so I can't say \"Ah, this group of SQL statements are from a Section being created!\".\r\n\r\nThe same for Entries and other perts of the system too."},"comment":{"url":"https://api.github.com/repos/symphonycms/symphony-2/issues/comments/77741683","html_url":"https://github.com/symphonycms/symphony-2/issues/2366#issuecomment-77741683","issue_url":"https://api.github.com/repos/symphonycms/symphony-2/issues/2366","id":77741683,"user":{"login":"brendo","id":69268,"avatar_url":"https://avatars.githubusercontent.com/u/69268?v=3","gravatar_id":"","url":"https://api.github.com/users/brendo","html_url":"https://github.com/brendo","followers_url":"https://api.github.com/users/brendo/followers","following_url":"https://api.github.com/users/brendo/following{/other_user}","gists_url":"https://api.github.com/users/brendo/gists{/gist_id}","starred_url":"https://api.github.com/users/brendo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendo/subscriptions","organizations_url":"https://api.github.com/users/brendo/orgs","repos_url":"https://api.github.com/users/brendo/repos","events_url":"https://api.github.com/users/brendo/events{/privacy}","received_events_url":"https://api.github.com/users/brendo/received_events","type":"User","site_admin":false},"created_at":"2015-03-08T10:02:12Z","updated_at":"2015-03-08T10:02:12Z","body":"Could it be solved by subscribing to SectionPreCreate and PostCreate delegates and then calling `Symphony::Database()->debug()` to get the list of queries that have run? We do something similar in `ExtensionManager->notifyMembers` to find out what extension ran which queries. Alternatively, you can subscribe to `PostQueryExecution` and use some sort of timestamp to figure out what has run. \r\n\r\n> Is the extension instantiated only once, or does it happen on a per delegate triggering basis?\r\n\r\nOnce. Extensions are initialised once and saved into a static cache. The `ExtensionManager` is a singleton.\r\n\r\n> Right now, I think we check the pool of listeners only when the actual delegate is called.\r\n\r\nCorrect, the subscriptions are loaded on initialisation of the `ExtensionManager`, but we only check the subscriptions for matching listeners when the delegate is fired.\r\n\r\n----\r\n\r\nGiven the delegate system was built nearly 10 years ago, it's definitely got it's flaws. Unlike modern event dispatcher's featured in Symfony2 or Laravel, the Symphony Extension Manager delegate system is immutable out of the box. Extensions register their events (delegates) when they are installed (tbl_extensions_delegates) and the Extension Manager uses these on each page load. \r\n\r\nA more modern solution would be to decouple the delegates from the Extension Manager, allowing extensions and the core to be equal citizens. A central event dispatcher would allow both extensions and the core to listen to delegates. It's crazy at the moment that sometimes extensions have more power than the core because of the delegate system!"}}