Skip to content

Commit c8aeb4b

Browse files
authored
Merge pull request #65 from Gaya/hotfix/max-length
Hotfix: max length of VARCHAR based on charset
2 parents 78be764 + a99e6a4 commit c8aeb4b

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

README.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Donate link: https://abtestingforwp.com/
55
Requires at least: 5.0
66
Tested up to: 5.4
77
Requires PHP: 5.6
8-
Stable tag: 1.18.1
8+
Stable tag: 1.18.2
99
License: GPLv3
1010
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1111

@@ -95,6 +95,9 @@ You can find the [source and repository over at GitHub](https://github.com/Gaya/
9595
5. Integration with HTML Forms
9696

9797
== Changelog ==
98+
= 1.18.2 =
99+
* Added max length for varchar fields in utf8mb4 enabled databases
100+
98101
= 1.18.1 =
99102
* Added database repair tool
100103

ab-testing-for-wp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22
/**
33
* @package ABTestingForWP
4-
* @version 1.18.1
4+
* @version 1.18.2
55
*/
66
/*
77
Plugin Name: A/B Testing for WordPress
88
Plugin URI: https://abtestingforwp.com
99
Description: Easiest way to create split tests on your WordPress sites, right from the content editor!
10-
Version: 1.18.1
10+
Version: 1.18.2
1111
Author: CleverNode
1212
Author URI: https://theclevernode.com
1313
Text Domain: ab-testing-for-wp

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ab-test-wordpress",
3-
"version": "1.18.1",
3+
"version": "1.18.2",
44
"description": "A/B Test right from your WordPress posts.",
55
"main": "index.js",
66
"scripts": {

src/php/data/installer.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private function fillInTitle($tablePrefix) {
123123
return "UPDATE `{$tablePrefix}ab_testing_for_wp_ab_test` AS t
124124
INNER JOIN `{$tablePrefix}posts` AS p on t.postId = p.ID
125125
SET t.title = CONCAT('Test \"', p.post_title, '\"')
126-
WHERE t.name IS NULL";
126+
WHERE t.title IS NULL";
127127
}
128128

129129
private function postGoalToVarchar($tablePrefix) {
@@ -132,11 +132,12 @@ private function postGoalToVarchar($tablePrefix) {
132132

133133
private function addVariantConditions($tablePrefix) {
134134
$collate = $this->getDBCollate();
135+
$maxLength = $this->getMaxVarcharLength();
135136

136137
return "CREATE TABLE IF NOT EXISTS `{$tablePrefix}ab_testing_for_wp_variant_condition` (
137138
`variantId` varchar(32) NOT NULL DEFAULT '',
138-
`key` varchar(255) NOT NULL DEFAULT '',
139-
`value` varchar(255) NOT NULL DEFAULT '',
139+
`key` varchar({$maxLength}) NOT NULL DEFAULT '',
140+
`value` varchar({$maxLength}) NOT NULL DEFAULT '',
140141
PRIMARY KEY (`variantId`, `key`, `value`)
141142
) ENGINE = InnoDB {$collate};";
142143
}
@@ -158,6 +159,19 @@ private function getDBCollate() {
158159
return $collate;
159160
}
160161

162+
private function getMaxVarcharLength() {
163+
global $wpdb;
164+
$collate = '';
165+
166+
if ($wpdb->has_cap('collation')) {
167+
if ($wpdb->charset === 'utf8mb4') {
168+
return 191;
169+
}
170+
}
171+
172+
return 255;
173+
}
174+
161175
private function removeTables() {
162176
global $wpdb;
163177

@@ -183,6 +197,7 @@ private function createTables() {
183197
$wpdb->show_errors();
184198

185199
$collate = $this->getDBCollate();
200+
$maxLength = $this->getMaxVarcharLength();
186201

187202
$tablePrefix = $wpdb->prefix;
188203

@@ -206,7 +221,7 @@ private function createTables() {
206221
CREATE TABLE IF NOT EXISTS `{$tablePrefix}ab_testing_for_wp_variant` (
207222
`id` varchar(32) NOT NULL DEFAULT '',
208223
`testId` varchar(32) DEFAULT NULL,
209-
`name` varchar(255) DEFAULT NULL,
224+
`name` varchar({$maxLength}) DEFAULT NULL,
210225
`participants` int(11) DEFAULT 0,
211226
`conversions` int(11) DEFAULT 0,
212227
PRIMARY KEY (`id`)

0 commit comments

Comments
 (0)