celtic-project / wordpress-lti

LTI Connector for WordPress
GNU General Public License v3.0
23 stars 11 forks source link

Does Not Generate Tables on First Activation #27

Closed syntaxseed closed 3 months ago

syntaxseed commented 3 months ago

Installed the Library plugin and then this plugin.

Upon first activation the plugin does not create the needed DB tables. Instead WP says that the plugin generated a fatal error.

PHP Fatal error:  Uncaught TypeError: ceLTIc\LTI\Util::logError(): Argument #1 ($message) must be of type string, null given, called in /wp-content/plugins/lti-tool/includes/lib.php on line 214 and defined in /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/Util.php:210

Upon second attempt at activation the plugin activates but only creates the consumer table.

I believe this is an issue with stricter types in newer PHP versions.

This code:

Util::logError($wpdb->print_error());

Sends null to the logError function if error logging/display is disabled.

I worked around it by adding a ? to the string type on the message parameter on this function:

// celtic-lti/vendor/celtic/lti/src/Util.php
public static function logError(?string $message, bool $showSource = true): void

We are running:

spvickers commented 3 months ago

Sorry for this issue. I have an update to be released soon which resolves this and other type errors.

spvickers commented 3 months ago

On closer inspection, this seems to be a different issue from what I had originally thought. The wpdb::print_error method actually prints the error message itself rather than returning the message for logging. Hence the call to Util::logError is redundant. Your report also highlighted that the database check being made assumes that all is well if the platform table exists, but if an error occurs in the process of creating the tables, as occurred in your case, then subsequent checks may assume all is well. In your case, it looks like the first attempt created the platform table but failed when trying to add an index to it. Hence on the second attempt the code found the platform table and assumed the database had been initialised. It was written like that to minimise the overhead when loading the plugin, but clearly needs to be updated which I shall do. Out of interest, do you know why the index creation failed (it should have been logged to your log file)? Perhaps it was because your database user account did not have the privilege to create indices?

Thanks for reporting this.

syntaxseed commented 3 months ago

Here's the pertinent log records:

[23-May-2024 14:57:54 UTC] PHP Fatal error:  Uncaught Error: Call to a member function bind_param() on bool in /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/DataConnector/DataConnector_mysqli.php:974
Stack trace:
#0 /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/PlatformNonce.php(71): ceLTIc\LTI\DataConnector\DataConnector_mysqli->loadPlatformNonce()
#1 /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/OAuthDataStore.php(99): ceLTIc\LTI\PlatformNonce->load()
#2 /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/OAuth/OAuthServer.php(297): ceLTIc\LTI\OAuthDataStore->lookup_nonce()
#3 /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/OAuth/OAuthServer.php(252): ceLTIc\LTI\OAuth\OAuthServer->check_nonce()
#4 /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/OAuth/OAuthServer.php(132): ceLTIc\LTI\OAuth\OAuthServer->check_signature()
#5 /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/System.php(1159): ceLTIc\LTI\OAuth\OAuthServer->verify_request()
#6 /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/Tool.php(1449): ceLTIc\LTI\Tool->verifySignature()
#7 /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/Tool.php(470): ceLTIc\LTI\Tool->authenticate()
#8 /wp-content/plugins/lti-tool/lti-tool.php(225): ceLTIc\LTI\Tool->handleRequest()
#9 /wp-includes/class-wp-hook.php(324): lti_tool_parse_request()
#10 /wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#11 /wp-includes/plugin.php(565): WP_Hook->do_action()
#12 /wp-includes/class-wp.php(418): do_action_ref_array()
#13 /wp-includes/class-wp.php(813): WP->parse_request()
#14 /wp-includes/functions.php(1336): WP->main()
#15 /wp-blog-header.php(16): wp()
#16 /index.php(17): require('...')
#17 {main}
  thrown in /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/DataConnector/DataConnector_mysqli.php on line 974
[23-May-2024 15:05:20 UTC] PHP Warning:  Undefined variable $lti_tool_data_connector in /wp-content/plugins/lti-tool/uninstall.php on line 41
[23-May-2024 15:06:15 UTC] PHP Warning:  file_get_contents(/wp-content/plugins/lti-tool/lti-tool.php): Failed to open stream: No such file or directory in /wp-includes/functions.php on line 6852
[23-May-2024 15:06:15 UTC] PHP Warning:  file_get_contents(/wp-content/plugins/lti-tool/lti-tool.php): Failed to open stream: No such file or directory in /wp-includes/functions.php on line 6852
[23-May-2024 15:18:49 UTC] WordPress database error Specified key was too long; max key length is 767 bytes for query ALTER TABLE wp_lti2_consumer ADD UNIQUE INDEX wp_lti2_consumer_consumer_key_UNIQUE (consumer_key ASC) made by activate_plugin, do_action('activate_lti-tool/lti-tool.php'), WP_Hook->do_action, WP_Hook->apply_filters, lti_tool_create_db_tables, lti_tool_create_db
[23-May-2024 15:18:49 UTC] WordPress database error Specified key was too long; max key length is 767 bytes for query ALTER TABLE wp_lti2_consumer ADD UNIQUE INDEX wp_lti2_consumer_consumer_key_UNIQUE (consumer_key ASC) made by activate_plugin, do_action('activate_lti-tool/lti-tool.php'), WP_Hook->do_action, WP_Hook->apply_filters, lti_tool_create_db_tables, lti_tool_create_db
[23-May-2024 15:18:49 UTC] PHP Fatal error:  Uncaught TypeError: ceLTIc\LTI\Util::logError(): Argument #1 ($message) must be of type string, null given, called in /wp-content/plugins/lti-tool/includes/lib.php on line 214 and defined in /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/Util.php:210
Stack trace:
#0 /wp-content/plugins/lti-tool/includes/lib.php(214): ceLTIc\LTI\Util::logError()
#1 /wp-content/plugins/lti-tool/lti-tool.php(907): lti_tool_create_db()
#2 /wp-includes/class-wp-hook.php(324): lti_tool_create_db_tables()
#3 /wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#4 /wp-includes/plugin.php(517): WP_Hook->do_action()
#5 /wp-admin/includes/plugin.php(705): do_action()
#6 /wp-admin/plugins.php(60): activate_plugin()
#7 {main}
  thrown in /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/Util.php on line 210
[23-May-2024 15:28:11 UTC] WordPress database error Specified key was too long; max key length is 767 bytes for query ALTER TABLE wp_lti2_consumer ADD UNIQUE INDEX wp_lti2_consumer_consumer_key_UNIQUE (consumer_key ASC) made by activate_plugin, do_action('activate_lti-tool/lti-tool.php'), WP_Hook->do_action, WP_Hook->apply_filters, lti_tool_create_db_tables, lti_tool_create_db
[23-May-2024 15:28:11 UTC] WordPress database error Specified key was too long; max key length is 767 bytes for query ALTER TABLE wp_lti2_consumer ADD UNIQUE INDEX wp_lti2_consumer_consumer_key_UNIQUE (consumer_key ASC) made by activate_plugin, do_action('activate_lti-tool/lti-tool.php'), WP_Hook->do_action, WP_Hook->apply_filters, lti_tool_create_db_tables, lti_tool_create_db
[23-May-2024 15:28:11 UTC] PHP Fatal error:  Uncaught TypeError: ceLTIc\LTI\Util::logError(): Argument #1 ($message) must be of type string, null given, called in /wp-content/plugins/lti-tool/includes/lib.php on line 214 and defined in /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/Util.php:210
Stack trace:
#0 /wp-content/plugins/lti-tool/includes/lib.php(214): ceLTIc\LTI\Util::logError()
#1 /wp-content/plugins/lti-tool/lti-tool.php(907): lti_tool_create_db()
#2 /wp-includes/class-wp-hook.php(324): lti_tool_create_db_tables()
#3 /wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#4 /wp-includes/plugin.php(517): WP_Hook->do_action()
#5 /wp-admin/includes/plugin.php(705): do_action()
#6 /wp-admin/plugins.php(60): activate_plugin()
#7 {main}
  thrown in /wp-content/plugins/celtic-lti/vendor/celtic/lti/src/Util.php on line 210
[23-May-2024 15:31:13 UTC] WordPress database error Specified key was too long; max key length is 767 bytes for query ALTER TABLE wp_lti2_consumer ADD UNIQUE INDEX wp_lti2_consumer_consumer_key_UNIQUE (consumer_key ASC) made by activate_plugin, do_action('activate_lti-tool/lti-tool.php'), WP_Hook->do_action, WP_Hook->apply_filters, lti_tool_create_db_tables, lti_tool_create_db
[23-May-2024 15:31:13 UTC] WordPress database error Specified key was too long; max key length is 767 bytes for query ALTER TABLE wp_lti2_consumer ADD UNIQUE INDEX wp_lti2_consumer_consumer_key_UNIQUE (consumer_key ASC) made by activate_plugin, do_action('activate_lti-tool/lti-tool.php'), WP_Hook->do_action, WP_Hook->apply_filters, lti_tool_create_db_tables, lti_tool_create_db
[23-May-2024 15:31:13 UTC] WordPress database error Specified key was too long; max key length is 767 bytes for query ALTER TABLE wp_lti2_consumer ADD UNIQUE INDEX wp_lti2_consumer_platform_UNIQUE (platform_id ASC, client_id ASC, deployment_id ASC) made by activate_plugin, do_action('activate_lti-tool/lti-tool.php'), WP_Hook->do_action, WP_Hook->apply_filters, lti_tool_create_db_tables, lti_tool_create_db
[23-May-2024 15:31:13 UTC] WordPress database error Specified key was too long; max key length is 767 bytes for query ALTER TABLE wp_lti2_consumer ADD UNIQUE INDEX wp_lti2_consumer_platform_UNIQUE (platform_id ASC, client_id ASC, deployment_id ASC) made by activate_plugin, do_action('activate_lti-tool/lti-tool.php'), WP_Hook->do_action, WP_Hook->apply_filters, lti_tool_create_db_tables, lti_tool_create_db

DB Version:

5.5.68-MariaDB

spvickers commented 3 months ago

Thanks for the log entries.

spvickers commented 3 months ago

Notwithstanding the issues in this plugin with handling the errors arising when creating the database structure (for which I am preparing a fix), it looks like your database version (5.5.68-MariaDB) is not sufficient to support this plugin because the index the plugin is trying to create is being rejected as being too long. Your database version has not been supported for some time (over 4 years) and I suspect that later releases do not have this same restriction; I have certainly not experienced any issues with 10.6.18-MariaDB.

syntaxseed commented 3 months ago

Thanks for the info. Unfortunately the environment & db version is out of my hand. 😓

spvickers commented 3 months ago

If you have any control over the character set being used within the schema, then you could make sure you are using one which has a smaller number of bytes per character. For example, the error in your file states that the index key must not be longer than 767 characters. But this was generated for an index of a field defined as varchar(256) which suggests that you may be using a three- or four-byte character set. (The plugin uses the same character set as has already been defined for the WordPress schema when creating its tables.) I think the largest index key involves 3 varchar(255) fields, so a single byte character set would be needed to keep within your limit (unless this limit can be changed).

syntaxseed commented 3 months ago

Unfortunately we have multi-lingual support which I think is why the multi-byte character set in the first place.

spvickers commented 3 months ago

OK, then I don't think this plugin will work in your environment, Sorry.