Repository navigation
🎉 Add WordPress Multisite support and modularize database management - #3267
harunollyo wants to merge 39 commits into
Conversation
…d multisite classes
…ager and Tutor classes
shewa12
left a comment
There was a problem hiding this comment.
Nice direction: one Table class per schema, a central TableManager, and per-blog FK names via fk_name() (needed because FK constraint names must be unique across the whole database, which made the old fixed names collide on multisite). I regenerated all 17 schemas from the new classes and diffed them against the previous CREATE TABLE SQL. They match, apart from these intentional or harmless differences:
answer_explanationisDEFAULT NULLinstead of'', which also avoids the strict-mode "TEXT can't have a default" error.item_details/item_typeare now part of the basetutor_cart_itemsschema.- The column COMMENTs on
tutor_ordersare dropped (nit inline).
CI: PHPUnit, E2E and PHP compat pass. WPCS fails on new files.
Requesting changes, mainly for backward compatibility with Tutor Pro and the multisite lifecycle:
- 🔴 Free still reads
$wpdb->tutor_gradebooksand$wpdb->tutor_email_queue, but no longer registers them, and the gradebook/email-queue installers were removed. Without a matching Pro release this breaks the Gradebook and email queue. - 🔴
wp_initialize_siteprovisions Tutor (tables, options, roles and pages) on every new subsite, even when Tutor isn't network-activated. - 🟠 Network or new-site provisioning skips the per-site activation steps (daily cron, permalink flush, first-activation time).
- 🟠 Uninstall on multisite only cleans the current site, and now also drops the e-commerce tables.
- 🟠
Upgraderstill createstutor_order_itemmetawith the old fixed FK name, so it collides on the second subsite.
Details are inline.
shewa12
left a comment
There was a problem hiding this comment.
Follow-up after a deeper pass over all 17 table classes and the code paths that create them. This adds new findings on top of my earlier review.
How I verified this:
- I extracted WordPress core's real
dbDelta()(current trunk) and ran each newget_schema()through it against two states: a fresh install (no tables), and an existing site whose tables were built from the previousTutor::create_database()/UpgraderSQL. I then diffed the queriesdbDelta()issues for the old schema vs the new one. - I diffed every new class column by column against the old SQL. All columns, types, defaults, keys and table-creation/FK ordering match, apart from the intentional changes noted earlier.
- I resolved
Table::get_name()under different$table_prefixvalues. - I checked tutor-pro (local 4.2.3, plus the
origin/4.3.0andorigin/multisitebranches) for the$wpdbtable properties this PR stops registering.
Fresh installs are fine: dbDelta() issues exactly one valid CREATE TABLE per table, in a valid FK order.
Existing sites and some prefixes are not:
- 🔴 Putting the
CONSTRAINTon the same line as the lastKEYbreaksdbDelta()'s index parser for 5 tables. Every reactivation of an existing site raises 20 PHP warnings ("Undefined array key index_type/index_name/index_columns/column_name") and runs 5 invalidALTER TABLE … ADD `` (``)queries. Warnings during activation also cause the "plugin generated unexpected output" notice. - 🔴
Table::get_name()goes through the new prefix-strippingprepare_table_name(). On sites whose$table_prefixis a leading part oftutor_(t,tu,tut,tutor,tutor_…), every Tutor table resolves to the wrong name (tutor_ordersinstead oftutor_tutor_orders). Existing data "disappears" and empty tables get created. - 🔴 Confirmed backward-compatibility break with Pro: no Pro branch I checked registers
$wpdb->tutor_gradebooks,tutor_gradebooks_results,tutor_email_queueor thetutor_subscription*properties, or creates the gradebook/email-queue tables. Pro uses$wpdb->tutor_gradebooks*68 times. With this PR and the current Pro, Gradebook and the email queue break. Please link the companion Pro PR, or keep the fallbacks (see the earlier comment onTutor.php:468). - 🟠
Upgradernow usesDB::has_table()/has_column(), which reject table names starting with a digit.QueryHelper::table_exists()didn't, so on prefixes like2fa_every column migration is silently skipped. - 🟡
JSONin the basetutor_cart_itemsschema makes the wholeCREATE TABLEfail on MySQL < 5.7.8 / MariaDB < 10.2.7.CREATE TABLE IF NOT EXISTSon earnings/withdraws stopsdbDelta()from ever updating those tables.
Details are inline.
|
Correction to point 3 of my review above. I analysed
Everything else in the review (points 1, 2, 4 and 5, and all 6 inline comments) still applies to |
ClickUp: https://app.clickup.com/t/9018365849/z8zyy1rk1c
Summary
Adds WordPress Multisite support and modernizes Tutor LMS database management with a modular, extensible architecture.
Key Improvements
Design Patterns & Approaches
Backward Compatibility
Single-site behavior and public entry points are preserved, but some legacy database methods were replaced. Tutor Pro and third-party addons may need to adopt the new table registration approach.
Testing
Use of AI Tool
Used: Yes
Used for: Analyzing dependencies, ensuring backward compatibility, and implementing code according to a planned architecture.