Commit 5e6cc3c8 authored by Dries's avatar Dries

- Patch #1410096 by fastangel, Gábor Hojtsy, kalman.hosszu: convert comment...

- Patch #1410096 by fastangel, Gábor Hojtsy, kalman.hosszu: convert comment language code schema to langcode.
parent cc9cd994
......@@ -25,11 +25,11 @@ class Comment extends Entity {
public $pid;
/**
* The comment language.
* The comment language code.
*
* @var string
*/
public $language = LANGUAGE_NONE;
public $langcode = LANGUAGE_NONE;
/**
* The comment title.
......
......@@ -167,7 +167,7 @@ function comment_schema() {
'not null' => FALSE,
'description' => "The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on.",
),
'language' => array(
'langcode' => array(
'description' => 'The {language}.langcode of this comment.',
'type' => 'varchar',
'length' => 12,
......@@ -179,7 +179,7 @@ function comment_schema() {
'comment_status_pid' => array('pid', 'status'),
'comment_num_new' => array('nid', 'status', 'created', 'cid', 'thread'),
'comment_uid' => array('uid'),
'comment_nid_language' => array('nid', 'language'),
'comment_nid_langcode' => array('nid', 'langcode'),
'comment_created' => array('created'),
),
'primary key' => array('cid'),
......@@ -259,3 +259,29 @@ function comment_schema() {
return $schema;
}
/**
* @addtogroup updates-7.x-to-8.x
* @{
*/
/**
* Renames {comment}.language to {comment}.langcode.
*/
function comment_update_8000() {
db_drop_index('comment', 'comment_nid_langcode');
$langcode_spec = array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
'description' => "Language code, e.g. 'de' or 'en-US'.",
);
db_change_field('comment', 'language', 'langcode', $langcode_spec);
db_add_index('comment', 'comment_nid_langcode', array('nid', 'langcode'));
}
/**
* @} End of "addtogroup updates-7.x-to-8.x"
* The next series of updates should start at 9000.
*/
......@@ -1844,11 +1844,11 @@ function comment_form($form, &$form_state, $comment) {
// If a content type has multilingual support we set the comment to inherit the
// content language. Otherwise mark the comment as language neutral.
$comment_langcode = $comment->language;
$comment_langcode = $comment->langcode;
if (($comment_langcode == LANGUAGE_NONE) && variable_get('node_type_language_' . $node->type, 0)) {
$comment_langcode = $language_content->langcode;
}
$form['language'] = array(
$form['langcode'] = array(
'#type' => 'value',
'#value' => $comment_langcode,
);
......
......@@ -451,7 +451,7 @@ class CommentInterfaceTest extends CommentHelperCase {
'status' => COMMENT_PUBLISHED,
'subject' => $this->randomName(),
'hostname' => ip_address(),
'language' => LANGUAGE_NONE,
'langcode' => LANGUAGE_NONE,
'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
));
comment_save($comment);
......@@ -778,7 +778,7 @@ class CommentInterfaceTest extends CommentHelperCase {
'status' => COMMENT_PUBLISHED,
'subject' => $this->randomName(),
'hostname' => ip_address(),
'language' => LANGUAGE_NONE,
'langcode' => LANGUAGE_NONE,
'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
));
comment_save($comment);
......
......@@ -106,10 +106,10 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
$url_options = array('absolute' => TRUE);
if (isset($options['language'])) {
$url_options['language'] = $options['language'];
$language_code = $options['language']->langcode;
$langcode = $options['language']->langcode;
}
else {
$language_code = NULL;
$langcode = NULL;
}
$sanitize = !empty($options['sanitize']);
......@@ -155,9 +155,9 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
break;
case 'body':
if ($items = field_get_items('comment', $comment, 'comment_body', $language_code)) {
if ($items = field_get_items('comment', $comment, 'comment_body', $langcode)) {
$instance = field_info_instance('comment', 'body', 'comment_body');
$field_langcode = field_language('comment', $comment, 'comment_body', $language_code);
$field_langcode = field_language('comment', $comment, 'comment_body', $langcode);
$replacements[$original] = $sanitize ? _text_sanitize($instance, $field_langcode, $items[0], 'value') : $items[0]['value'];
}
break;
......@@ -186,11 +186,11 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
break;
case 'created':
$replacements[$original] = format_date($comment->created, 'medium', '', NULL, $language_code);
$replacements[$original] = format_date($comment->created, 'medium', '', NULL, $langcode);
break;
case 'changed':
$replacements[$original] = format_date($comment->changed, 'medium', '', NULL, $language_code);
$replacements[$original] = format_date($comment->changed, 'medium', '', NULL, $langcode);
break;
case 'node':
......
......@@ -2725,8 +2725,8 @@ class LocaleCommentLanguageFunctionalTest extends DrupalWebTestCase {
->orderBy('cid', 'DESC')
->execute()
->fetchObject();
$args = array('%node_language' => $node_langcode, '%comment_language' => $comment->language, '%langcode' => $langcode);
$this->assertEqual($comment->language, $langcode, t('The comment posted with content language %langcode and belonging to the node with language %node_language has language %comment_language', $args));
$args = array('%node_language' => $node_langcode, '%comment_language' => $comment->langcode, '%langcode' => $langcode);
$this->assertEqual($comment->langcode, $langcode, t('The comment posted with content language %langcode and belonging to the node with language %node_language has language %comment_language', $args));
}
}
}
......
......@@ -524,3 +524,261 @@
->condition('type', 'module')
->condition('name', 'locale')
->execute();
// Add a sample node to test comments on.
db_insert('node')->fields(array(
'nid',
'vid',
'type',
'language',
'title',
'uid',
'status',
'created',
'changed',
'comment',
'promote',
'sticky',
'tnid',
'translate',
))
->values(array(
'nid' => '38',
'vid' => '50',
'type' => 'article',
'language' => 'und',
'title' => 'Node title 38',
'uid' => '6',
'status' => '1',
'created' => '1263769200',
'changed' => '1314997642',
'comment' => '2',
'promote' => '0',
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
))
->execute();
// Add its node comment statistics.
db_insert('node_comment_statistics')->fields(array(
'nid',
'cid',
'last_comment_timestamp',
'last_comment_name',
'last_comment_uid',
'comment_count',
))
->values(array(
'nid' => '38',
'cid' => '0',
'last_comment_timestamp' => '1314997642',
'last_comment_name' => NULL,
'last_comment_uid' => '6',
'comment_count' => '1',
))
->execute();
// Add node revision information.
db_insert('node_revision')->fields(array(
'nid',
'vid',
'uid',
'title',
'log',
'timestamp',
'status',
'comment',
'promote',
'sticky',
))
->values(array(
'nid' => '38',
'vid' => '50',
'uid' => '6',
'title' => 'Node title 38',
'log' => 'added a node to comment on',
'timestamp' => '1314997642',
'status' => '1',
'comment' => '2',
'promote' => '0',
'sticky' => '0',
))
->execute();
// Add the body field value.
db_insert('field_data_body')->fields(array(
'entity_type',
'bundle',
'deleted',
'entity_id',
'revision_id',
'language',
'delta',
'body_value',
'body_summary',
'body_format',
))
->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '38',
'revision_id' => '50',
'language' => 'und',
'delta' => '0',
'body_value' => 'Node body',
'body_summary' => 'Node body',
'body_format' => 'filtered_html',
))
->execute();
// Add revision information for the body field value.
db_insert('field_revision_body')->fields(array(
'entity_type',
'bundle',
'deleted',
'entity_id',
'revision_id',
'language',
'delta',
'body_value',
'body_summary',
'body_format',
))
->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '38',
'revision_id' => '50',
'language' => 'und',
'delta' => '0',
'body_value' => 'Node body',
'body_summary' => 'Node body',
'body_format' => 'filtered_html',
))
->execute();
// Add two comments to this node in a thread.
db_insert('comment')->fields(array(
'cid',
'pid',
'nid',
'uid',
'subject',
'hostname',
'created',
'changed',
'status',
'thread',
'name',
'mail',
'homepage',
'language',
))
->values(array(
'cid' => '1',
'pid' => '0',
'nid' => '38',
'uid' => '6',
'subject' => 'First test comment',
'hostname' => '127.0.0.1',
'created' => '1314997642',
'changed' => '1314997642',
'status' => '1',
'thread' => '01/',
'name' => 'test user 4',
'mail' => '',
'homepage' => '',
'language' => 'und',
))
->values(array(
'cid' => '2',
'pid' => '0',
'nid' => '38',
'uid' => '6',
'subject' => 'Reply to first test comment',
'hostname' => '127.0.0.1',
'created' => '1314997642',
'changed' => '1314997642',
'status' => '1',
'thread' => '01.00/',
'name' => 'test user 4',
'mail' => '',
'homepage' => '',
'language' => 'und',
))
->execute();
// Add both comment bodies.
db_insert('field_data_comment_body')->fields(array(
'entity_type',
'bundle',
'deleted',
'entity_id',
'revision_id',
'language',
'delta',
'comment_body_value',
'comment_body_format',
))
->values(array(
'entity_type' => 'comment',
'bundle' => 'comment_node_article',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'und',
'delta' => '0',
'comment_body_value' => 'Comment body',
'comment_body_format' => 'filtered_html',
))
->values(array(
'entity_type' => 'comment',
'bundle' => 'comment_node_article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '0',
'comment_body_value' => 'Second comment body',
'comment_body_format' => 'filtered_html',
))
->execute();
// Add revisions for comment bodies.
db_insert('field_revision_comment_body')->fields(array(
'entity_type',
'bundle',
'deleted',
'entity_id',
'revision_id',
'language',
'delta',
'comment_body_value',
'comment_body_format',
))
->values(array(
'entity_type' => 'comment',
'bundle' => 'comment_node_article',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'und',
'delta' => '0',
'comment_body_value' => 'Comment body',
'comment_body_format' => 'filtered_html',
))
->values(array(
'entity_type' => 'comment',
'bundle' => 'comment_node_article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'language' => 'und',
'delta' => '0',
'comment_body_value' => 'Second comment body',
'comment_body_format' => 'filtered_html',
))
->execute();
......@@ -41,6 +41,16 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase {
$this->assertTrue($language->default == ($language->langcode == 'ca'), t('@language default property properly set', array('@language' => $language->name)));
}
// Check that both comments display on the node.
$this->drupalGet('node/38');
$this->assertText('Node title 38', t('Node 38 displayed after update.'));
$this->assertText('First test comment', t('Comment 1 displayed after update.'));
$this->assertText('Reply to first test comment', t('Comment 2 displayed after update.'));
// Directly check the comment language property on the first comment.
$comment = db_query('SELECT * FROM {comment} WHERE cid = :cid', array(':cid' => 1))->fetchObject();
$this->assertTrue($comment->langcode == 'und', t('Comment 1 language code found.'));
// Check for node content type settings upgrade.
$this->drupalGet('node/add/article');
$this->assertFieldByName('language');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment