Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Cleanup and restructure #67

Merged
merged 94 commits into from
Jul 8, 2017
Merged

Cleanup and restructure #67

merged 94 commits into from
Jul 8, 2017

Conversation

mickadoo
Copy link
Collaborator

@mickadoo mickadoo commented Jul 6, 2017

This PR contains changes currently under review in #66

Overview

This PR focuses on allowing automatic joins to other tables using dot notation syntax in the select query, for example Contact::get()->addSelect('emails.email')

It also does a lot of moving files about, so there are a lot of files changed.

Before

APIv4 did not allow joining on any other tables

After

A schema map builds links to tables that can be joined and automatically joins them if used in the query

Notes

  • The SchemaMap class contains a collection of all tables in the database. Each table has n links to other tables. These links are Joinable instances, which can be used by the Joiner class to join tables.
  • The SchemaMap is built using a factory service, this service uses both calls to core code (to fetch the base tables), an event system, and calls to get the custom value tables to build a picture of the schema with the links between tables
  • I've moved all folders to the top level and removed the distinction between Civi/API and Civi/Api4. I've also added a PSR-4 prefix so we can use a unique prefix name (Civi\API\V4). Because of the namespace change I've had to temporarily modify \Civi\API\Request in the core code. The new namespace should be used here: $callable = array("Civi\\API\\V4\\Entity\\$entity", $action);
  • I've moved the tests around and used a separate top-level namespace for them, Civi\Test. This separates the test namespace from production
  • All tests are running, although some are marked as skipped (these are tests that were broken from the start)

@colemanw
Copy link
Member

colemanw commented Jul 7, 2017

@mickadoo can you please rebase this to fix merge conflicts?

@mickadoo
Copy link
Collaborator Author

mickadoo commented Jul 7, 2017

@colemanw rebased onto master

Just a reminder, but if you want to run tests on this you make a change in the core code which has the API4 namespace hardcoded in \Civi\API\Request. Here's what I have:

        $callable = array("Civi\\API\\V4\\Entity\\$entity", $action);
//        $callable = array("Civi\\Api4\\$entity", $action);

Do you think I should submit a core patch for this, it's not urgent for me, but will be annoying for anyone who wants to demo APIv4. I wonder if this should be configurable, or if there's a different approach for how we'll do this.

@colemanw
Copy link
Member

colemanw commented Jul 7, 2017 via email

@colemanw
Copy link
Member

colemanw commented Jul 7, 2017

@mickadoo it looks like you're placing api4 entities in the \Civi\Entity namespace - that might not be specific enough... shouldn't it be \Civi\Api4\Entity?

@mickadoo
Copy link
Collaborator Author

mickadoo commented Jul 7, 2017

@colemanw The namespace is Civi\API\V4\Entity although the files are located the Civi directory. This is because I'm using a PSR-4 prefix (which helps to cut out the extra directories) in info.xml

<psr4 prefix="Civi\API\V4\" path="Civi" />

Which replaced

<psr4 prefix="Civi\" path="Civi" />

@colemanw colemanw merged commit 1fd6674 into civicrm:master Jul 8, 2017
@mickadoo mickadoo deleted the cleanup_and_restructure branch July 10, 2017 16:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants