Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an Object Relationships Database Table #1429

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from

Conversation

KTS915
Copy link
Member

@KTS915 KTS915 commented May 7, 2024

This is the start of an attempt to address Issue #1155.

One of my production sites depends on an object relationships table (and associated meta table), for which I created a plugin. This PR is an attempt to translate the code from that plugin into something that can be used for core.

The main table works by storing in the same row both an ID and an object type (such as user, comment, or a specific custom taxonomy) for two objects. The table can then be checked to see if such a relationship exists, or a user can add or delete such a relationship, or they can get the ID of the second object if the details of the first and object type of the second are known.

The meta table enables the creation, updating, getting, and deleting of metadata about the relationship. (CP automatically recognizes such functions if the tables follow the specific naming conventions used here.)

One obvious omission here is any attempt to include the information retrieved into CP's object cache. I'm hoping someone will add that.

Secondly (and more immediately), I cannot get the code to create the new databases to work. It works fine in my plugin, but not when added to ~wp-admin/includes/schema.php. Instead, CP instantiates the database without these tables, and I receive the following message:

ClassicPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( relationship_id bigint(20) NOT NULL auto_increment, left_object_id bigint...' at line 1]
CREATE TABLE ( relationship_id bigint(20) NOT NULL auto_increment, left_object_id bigint(20) NOT NULL, left_object_type varchar(255) NOT NULL, right_object_type varchar(255) NOT NULL, right_object_id bigint(20) NOT NULL, PRIMARY KEY (relationship_id) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci

Again, I'm hoping that someone can identify the problem here and fix it.

@mattyrob mattyrob added the task: documentation Something that needs to be documented label May 7, 2024
@mattyrob mattyrob added this to the 2.2 milestone May 7, 2024
@KTS915
Copy link
Member Author

KTS915 commented May 7, 2024

@mattyrob Thanks for getting that all working!

This will now work for brand new sites. Will there need to be some extra code to ensure that these tables are created for sites that already exist?

@xxsimoxx
Copy link
Member

xxsimoxx commented May 8, 2024

Seems that extra code will be needed to create the table.
But on my first test the tables were created because of a database update triggered by switching from #1436 (that contains a database update) to develop and then to #1429.
So when upgrading to 2.2.0 users will get the table in place.

Edit: Maybe merging on the same day #1436 will make nightlies have the tables.

@KTS915
Copy link
Member Author

KTS915 commented May 13, 2024

Hmm, it looks like the Coding Standards / Pre-commit checks (pull_request) doesn't like the spread operator. I could change it to array_merge, but the spread operator is faster (and the other differences between the two methods are immaterial here).

EDIT: now made the change anyway just to stop the failure!

@KTS915 KTS915 removed the task: documentation Something that needs to be documented label May 14, 2024
src/wp-admin/includes/schema.php Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants