dev/core#2039 Remove extraneous location queries from contact.create->Location::block...
authoreileen <emcnaughton@wikimedia.org>
Tue, 6 Oct 2020 23:56:35 +0000 (12:56 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 6 Oct 2020 23:56:35 +0000 (12:56 +1300)
Overview
----------------------------------------
Removes 10 queries from each contact  create that are otherwise dealt with elsewhere
Updated version of https://github.com/civicrm/civicrm-core/pull/18477

Before
----------------------------------------
After creating location blocks 2 queries are done for each of the 5 entities to ensure is_primary fields have not been messed up (ie contact has 1 or more phones but none are marked primary or contact has more than one primary phone).

After
----------------------------------------
Queries are removed as location entities are already created correctly

Technical Details
----------------------------------------
This PR is part of a series of PRs to make this possible - best documented at https://lab.civicrm.org/dev/core/-/issues/2039#note_47758

Comments
----------------------------------------
https://lab.civicrm.org/dev/core/-/issues/2039

CRM/Core/BAO/Location.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/JobTest.php
tests/phpunit/api/v3/SyntaxConformanceTest.php

index fd1545efe9117f8d9b0917df1050dcd2f975a745..3b97cbad4482f4c4b577919274574e4382b9858f 100644 (file)
@@ -53,14 +53,6 @@ class CRM_Core_BAO_Location extends CRM_Core_DAO {
       }
     }
 
-    // when we come from a form which displays all the location elements (like the edit form or the inline block
-    // elements, we can skip the below check. The below check adds quite a feq queries to an already overloaded
-    // form
-    if (empty($params['updateBlankLocInfo'])) {
-      // make sure contact should have only one primary block, CRM-5051
-      self::checkPrimaryBlocks(CRM_Utils_Array::value('contact_id', $params));
-    }
-
     return $location;
   }
 
index a46ecbc21eeebf05294262ac84182b8cc7388d16..429249e2bde6284fe6523863db54285e737801c6 100644 (file)
@@ -149,7 +149,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    *
    * @var bool
    */
-  protected $isLocationTypesOnPostAssert = FALSE;
+  protected $isLocationTypesOnPostAssert = TRUE;
 
   /**
    * Class used for hooks during tests.
index 5bc0ccb8fddb19c9184ffb6469378eb0eed36df4..492b324c49337c5f2c623925bb4c338cf457774f 100644 (file)
@@ -44,6 +44,15 @@ class api_v3_JobTest extends CiviUnitTestCase {
    */
   private $report_instance;
 
+  /**
+   * Should location types be checked to ensure primary addresses are correctly assigned after each test.
+   *
+   * We cannot enable this until https://github.com/civicrm/civicrm-core/pull/18555 is merged
+   *
+   * @var bool
+   */
+  protected $isLocationTypesOnPostAssert = FALSE;
+
   /**
    * Set up for tests.
    */
index 0365d2a09153dc9c8a9759ca6e8416938bd63c7e..156bf876e8a6fab9960981f088f15fce8f69d1c4 100644 (file)
@@ -38,6 +38,16 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
 
   protected $_entity;
 
+  /**
+   * Should location types be checked to ensure primary addresses are correctly assigned after each test.
+   *
+   * Turn off for this class as we use DAO methods that bypass business logic. Also, this test class
+   * takes a long time so might be good not to add another check.
+   *
+   * @var bool
+   */
+  protected $isLocationTypesOnPostAssert = FALSE;
+
   /**
    * Map custom group entities to civicrm components.
    * @var array