1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-18 20:41:16 +02:00

Attempt to fix issue processwire/processwire-issues#242 for FieldtypeComments + utf8mb4 charset combo

This commit is contained in:
Ryan Cramer
2017-04-13 06:06:46 -04:00
parent 81c8d4eb2f
commit ae50a0563b

View File

@@ -26,6 +26,11 @@ require_once($dirname . "/CommentForm.php");
* ProcessWire Comments Fieldtype * ProcessWire Comments Fieldtype
* *
* A field that stores user posted comments for a single Page. * A field that stores user posted comments for a single Page.
*
* @method mixed updateComment(Page $page, $field, Comment $comment, array $properties)
* @method commentDeleted(Page $page, Field $field, Comment $comment, $notes = '') #pw-hooker
* @method commentApproved(Page $page, Field $field, Comment $comment, $notes = '') #pw-hooker
* @method commentUnapproved(Page $page, Field $field, Comment $comment, $notes = '') #pw-hooker
* *
*/ */
class FieldtypeComments extends FieldtypeMulti { class FieldtypeComments extends FieldtypeMulti {
@@ -104,11 +109,19 @@ class FieldtypeComments extends FieldtypeMulti {
/** /**
* Update a query to match the text with a fulltext index * Update a query to match the text with a fulltext index
*
* @param DatabaseQuerySelect $query
* @param string $table
* @param string $subfield
* @param string $operator
* @param mixed $value
* @return DatabaseQuerySelect
* *
*/ */
public function getMatchQuery($query, $table, $subfield, $operator, $value) { public function getMatchQuery($query, $table, $subfield, $operator, $value) {
if($subfield == 'text') $subfield = 'data'; if($subfield == 'text') $subfield = 'data';
if(empty($subfield) || $subfield === 'data') { if(empty($subfield) || $subfield === 'data') {
/** @var DatabaseQuerySelectFulltext $ft */
$ft = $this->wire(new DatabaseQuerySelectFulltext($query)); $ft = $this->wire(new DatabaseQuerySelectFulltext($query));
$ft->match($table, $subfield, $operator, $value); $ft->match($table, $subfield, $operator, $value);
return $query; return $query;
@@ -252,7 +265,8 @@ class FieldtypeComments extends FieldtypeMulti {
$this->commentUnapproved($page, $field, $comment); $this->commentUnapproved($page, $field, $comment);
} }
if($field->useAkismet && $comment->ip && $comment->user_agent && ($submitHam || $submitSpam)) { if($field->get('useAkismet') && $comment->ip && $comment->user_agent && ($submitHam || $submitSpam)) {
/** @var CommentFilterAkismet $akismet */
$akismet = $this->modules->get("CommentFilterAkismet"); $akismet = $this->modules->get("CommentFilterAkismet");
$akismet->setComment($comment); $akismet->setComment($comment);
if($submitHam) $akismet->submitHam(); if($submitHam) $akismet->submitHam();
@@ -302,7 +316,8 @@ class FieldtypeComments extends FieldtypeMulti {
$this->checkCommentCodes($comment); $this->checkCommentCodes($comment);
if($field->useAkismet) { if($field->get('useAkismet')) {
/** @var CommentFilterAkismet $akismet */
$akismet = $this->modules->get('CommentFilterAkismet'); $akismet = $this->modules->get('CommentFilterAkismet');
$akismet->setComment($comment); $akismet->setComment($comment);
$akismet->checkSpam(); // automatically sets status if spam $akismet->checkSpam(); // automatically sets status if spam
@@ -371,11 +386,15 @@ class FieldtypeComments extends FieldtypeMulti {
/** /**
* Schema for the Comments Fieldtype * Schema for the Comments Fieldtype
*
* @param Field $field
* @return array
* *
*/ */
public function getDatabaseSchema(Field $field) { public function getDatabaseSchema(Field $field) {
$websiteSchema = "varchar(250) NOT NULL default ''"; $maxIndexLength = $this->wire('database')->getMaxIndexLength();
$websiteSchema = "varchar($maxIndexLength) NOT NULL default ''";
$parentSchema = "int unsigned NOT NULL default 0"; $parentSchema = "int unsigned NOT NULL default 0";
$flagSchema = "int unsigned NOT NULL default 0"; $flagSchema = "int unsigned NOT NULL default 0";
$codeSchema = "varchar(128) default NULL"; $codeSchema = "varchar(128) default NULL";
@@ -386,7 +405,7 @@ class FieldtypeComments extends FieldtypeMulti {
$downvoteSchema = "int unsigned NOT NULL default 0"; $downvoteSchema = "int unsigned NOT NULL default 0";
$starsSchema = "tinyint unsigned default NULL"; $starsSchema = "tinyint unsigned default NULL";
$schemaVersion = (int) $field->schemaVersion; $schemaVersion = (int) $field->get('schemaVersion');
$updateSchema = true; $updateSchema = true;
if(!$schemaVersion) { if(!$schemaVersion) {
@@ -490,7 +509,7 @@ class FieldtypeComments extends FieldtypeMulti {
// column already exists // column already exists
$schemaVersion = 6; $schemaVersion = 6;
} else { } else {
$updateSchema = false; // $updateSchema = false;
} }
} }
} }
@@ -506,13 +525,13 @@ class FieldtypeComments extends FieldtypeMulti {
$schema['id'] = "int unsigned NOT NULL auto_increment"; $schema['id'] = "int unsigned NOT NULL auto_increment";
$schema['status'] = "tinyint(3) NOT NULL default '0'"; $schema['status'] = "tinyint(3) NOT NULL default '0'";
$schema['cite'] = "varchar(128) NOT NULL default ''"; $schema['cite'] = "varchar(128) NOT NULL default ''";
$schema['email'] = "varchar(250) NOT NULL default ''"; $schema['email'] = "varchar(128) NOT NULL default ''";
$schema['data'] = "text NOT NULL"; $schema['data'] = "text NOT NULL";
$schema['sort'] = "int unsigned NOT NULL"; $schema['sort'] = "int unsigned NOT NULL";
$schema['created'] = "int unsigned NOT NULL"; $schema['created'] = "int unsigned NOT NULL";
$schema['created_users_id'] = "int unsigned NOT NULL"; $schema['created_users_id'] = "int unsigned NOT NULL";
$schema['ip'] = "varchar(15) NOT NULL default ''"; $schema['ip'] = "varchar(15) NOT NULL default ''";
$schema['user_agent'] = "varchar(250) NOT NULL default ''"; $schema['user_agent'] = "varchar($maxIndexLength) NOT NULL default ''";
$schemaVersion = $field->schemaVersion; $schemaVersion = $field->schemaVersion;
if($schemaVersion > 0) $schema['website'] = $websiteSchema; if($schemaVersion > 0) $schema['website'] = $websiteSchema;
@@ -559,6 +578,7 @@ class FieldtypeComments extends FieldtypeMulti {
if(!$page->id || !$field->id) return false; if(!$page->id || !$field->id) return false;
/** @var CommentArray $allItems */
$allItems = $page->get($field->name); $allItems = $page->get($field->name);
$database = $this->wire('database'); $database = $this->wire('database');
$table = $database->escapeTable($field->table); $table = $database->escapeTable($field->table);
@@ -566,6 +586,7 @@ class FieldtypeComments extends FieldtypeMulti {
if(!$allItems) return false; if(!$allItems) return false;
if(!$allItems->isChanged() && !$page->isChanged($field->name)) return true; if(!$allItems->isChanged() && !$page->isChanged($field->name)) return true;
/** @var CommentArray $itemsRemoved */
$itemsRemoved = $allItems->getItemsRemoved(); $itemsRemoved = $allItems->getItemsRemoved();
if(count($itemsRemoved)) { if(count($itemsRemoved)) {
foreach($itemsRemoved as $item) { foreach($itemsRemoved as $item) {
@@ -649,6 +670,9 @@ class FieldtypeComments extends FieldtypeMulti {
/** /**
* Configuration that appears with each Comments fieldtype * Configuration that appears with each Comments fieldtype
*
* @param Field $field
* @return InputfieldWrapper
* *
*/ */
public function ___getConfigInputfields(Field $field) { public function ___getConfigInputfields(Field $field) {
@@ -937,6 +961,10 @@ class FieldtypeComments extends FieldtypeMulti {
/** /**
* For FieldtypeMulti interface, return NULL to indicate that the field is not auto-joinable * For FieldtypeMulti interface, return NULL to indicate that the field is not auto-joinable
*
* @param Field $field
* @param DatabaseQuerySelect $query
* @return null
* *
*/ */
public function getLoadQueryAutojoin(Field $field, DatabaseQuerySelect $query) { public function getLoadQueryAutojoin(Field $field, DatabaseQuerySelect $query) {
@@ -1200,6 +1228,7 @@ class FieldtypeComments extends FieldtypeMulti {
* @param Page $page * @param Page $page
* @param Field $field * @param Field $field
* @param Comment $comment * @param Comment $comment
* @param string $notes
* @return mixed * @return mixed
* *
*/ */
@@ -1235,6 +1264,8 @@ class FieldtypeComments extends FieldtypeMulti {
/** /**
* Hook called after comment has been deleted * Hook called after comment has been deleted
*
* #pw-hooker
* *
* @param Page $page * @param Page $page
* @param Field $field * @param Field $field
@@ -1248,6 +1279,8 @@ class FieldtypeComments extends FieldtypeMulti {
/** /**
* Hook called when a comment goes from un-approved to approved * Hook called when a comment goes from un-approved to approved
* *
* #pw-hooker
*
* @param Page $page * @param Page $page
* @param Field $field * @param Field $field
* @param Comment $comment * @param Comment $comment
@@ -1297,6 +1330,8 @@ class FieldtypeComments extends FieldtypeMulti {
/** /**
* Hook called when a comment goes from approved to pending or spam * Hook called when a comment goes from approved to pending or spam
*
* #pw-hooker
* *
* @param Page $page * @param Page $page
* @param Field $field * @param Field $field