From b07c8672310da30f3480b663ad1693060d18a69f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 24 Jul 2019 18:02:15 -0700 Subject: [PATCH] CRM-20455 - Add specialized event for queries Overview -------- The recently merged PR for CRM-20455, https://github.com/civicrm/civicrm-packages/pull/180, uses the GenericHookEvent for modifying all SQL queries. GHE is flexible, but it comes with a slight performance penalty (juggling a few internal arrays). The penalty is usually too small to care if you're firing one hook. However, with CRM-20455, we can foresee the event firing hundreds or even thousands of times within a given page-view. This PR adds a smaller/simpler class for use with `modifyQuery`. There will be a different PR to use it. Before ------ * Don't have `QueryEvent` After ----- * Do have `QueryEvent` --- Civi/Core/Event/QueryEvent.php | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Civi/Core/Event/QueryEvent.php diff --git a/Civi/Core/Event/QueryEvent.php b/Civi/Core/Event/QueryEvent.php new file mode 100644 index 0000000000..d670bf2395 --- /dev/null +++ b/Civi/Core/Event/QueryEvent.php @@ -0,0 +1,70 @@ +query = $query; + } + + /** + * @return string|FALSE + * Ex: 'SELECT', 'INSERT', 'CREATE', 'ALTER' + * A FALSE value indicates that a singular verb could not be identified. + */ + public function getVerb() { + if ($this->verb === NULL) { + if (preg_match(';(/\*.*/\*\s*)?([a-zA-Z]+) ;', $this->query, $m)) { + $this->verb = strtolower($m[2]); + } + else { + $this->verb = FALSE; + } + } + return $this->verb; + } + +} -- 2.25.1