From 61fbf33286db5e4b6f10b9c66796126a0b65acb0 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 3 Jul 2021 22:05:12 -0400 Subject: [PATCH] APIv4 - Remove unused backreferences from SchemaMap --- Civi/Api4/Service/Schema/SchemaMapBuilder.php | 45 ------------------- .../Service/Schema/SchemaMapRealTableTest.php | 40 ----------------- 2 files changed, 85 deletions(-) delete mode 100644 tests/phpunit/api/v4/Service/Schema/SchemaMapRealTableTest.php diff --git a/Civi/Api4/Service/Schema/SchemaMapBuilder.php b/Civi/Api4/Service/Schema/SchemaMapBuilder.php index e89b7c359a..7db2ac0d5b 100644 --- a/Civi/Api4/Service/Schema/SchemaMapBuilder.php +++ b/Civi/Api4/Service/Schema/SchemaMapBuilder.php @@ -68,8 +68,6 @@ class SchemaMapBuilder { $this->addCustomFields($map, $table, $data['name']); } } - - $this->addBackReferences($map); } /** @@ -98,49 +96,6 @@ class SchemaMapBuilder { } } - /** - * Loop through existing links and provide link from the other side - * - * @param SchemaMap $map - */ - private function addBackReferences(SchemaMap $map) { - foreach ($map->getTables() as $table) { - foreach ($table->getTableLinks() as $link) { - $target = $map->getTableByName($link->getTargetTable()); - $tableName = $link->getBaseTable(); - // Exclude custom field tables - if (strpos($link->getTargetTable(), 'civicrm_value_') !== 0 && strpos($link->getBaseTable(), 'civicrm_value_') !== 0) { - $plural = str_replace('civicrm_', '', $this->getPlural($tableName)); - $joinable = new Joinable($tableName, $link->getBaseColumn(), $plural); - $joinable->setJoinType($joinable::JOIN_TYPE_ONE_TO_MANY); - $target->addTableLink($link->getTargetColumn(), $joinable); - } - } - } - } - - /** - * Simple implementation of pluralization. - * Could be replaced with symfony/inflector - * - * @param string $singular - * - * @return string - */ - private function getPlural($singular) { - $last_letter = substr($singular, -1); - switch ($last_letter) { - case 'y': - return substr($singular, 0, -1) . 'ies'; - - case 's': - return $singular . 'es'; - - default: - return $singular . 's'; - } - } - /** * @param \Civi\Api4\Service\Schema\SchemaMap $map * @param \Civi\Api4\Service\Schema\Table $baseTable diff --git a/tests/phpunit/api/v4/Service/Schema/SchemaMapRealTableTest.php b/tests/phpunit/api/v4/Service/Schema/SchemaMapRealTableTest.php deleted file mode 100644 index 6a7b2598da..0000000000 --- a/tests/phpunit/api/v4/Service/Schema/SchemaMapRealTableTest.php +++ /dev/null @@ -1,40 +0,0 @@ -get('schema_map'); - $this->assertNotEmpty($map->getTables()); - } - - public function testSimplePathWillExist() { - $map = \Civi::container()->get('schema_map'); - $path = $map->getPath('civicrm_contact', 'emails'); - $this->assertCount(1, $path); - } - -} -- 2.25.1