diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php index f5e493d9623..2961aebffc3 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -140,8 +140,13 @@ class Schema extends DatabaseSchema { protected function createFieldSql($name, $spec) { $sql = "`" . $name . "` " . $spec['mysql_type']; - if (in_array($spec['mysql_type'], array('VARCHAR', 'CHAR', 'TINYTEXT', 'MEDIUMTEXT', 'LONGTEXT', 'TEXT')) && isset($spec['length'])) { - $sql .= '(' . $spec['length'] . ')'; + if (in_array($spec['mysql_type'], array('VARCHAR', 'CHAR', 'TINYTEXT', 'MEDIUMTEXT', 'LONGTEXT', 'TEXT'))) { + if (isset($spec['length'])) { + $sql .= '(' . $spec['length'] . ')'; + } + if (!empty($spec['binary'])) { + $sql .= ' BINARY'; + } } elseif (isset($spec['precision']) && isset($spec['scale'])) { $sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')'; diff --git a/core/lib/Drupal/Core/Database/Schema.php b/core/lib/Drupal/Core/Database/Schema.php index 9e2f22e3883..62e132761d6 100644 --- a/core/lib/Drupal/Core/Database/Schema.php +++ b/core/lib/Drupal/Core/Database/Schema.php @@ -80,6 +80,10 @@ use Drupal\Core\Database\Query\PlaceholderInterface; * the precision (total number of significant digits) and scale * (decimal digits right of the decimal point). Both values are * mandatory. Ignored for other field types. + * - 'binary': A boolean indicating that MySQL should force 'char', + * 'varchar' or 'text' fields to use case-sensitive binary collation. + * This has no effect on other database types for which case sensitivity + * is already the default behavior. * All parameters apart from 'type' are optional except that type * 'numeric' columns must specify 'precision' and 'scale', and type * 'varchar' must specify the 'length' parameter. diff --git a/core/lib/Drupal/Core/Database/StatementEmpty.php b/core/lib/Drupal/Core/Database/StatementEmpty.php index 84ccb6a2ab5..4336fa11f4b 100644 --- a/core/lib/Drupal/Core/Database/StatementEmpty.php +++ b/core/lib/Drupal/Core/Database/StatementEmpty.php @@ -18,7 +18,7 @@ use Iterator; * database. Calling code can then treat it the same as if it were an actual * result set that happens to contain no records. * - * @see SearchQuery + * @see Drupal\search\SearchQuery */ class StatementEmpty implements Iterator, StatementInterface { diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index fec4f0be0ff..9a266baf579 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -396,6 +396,7 @@ function aggregator_block_view($delta = '') { if (user_access('access news feeds')) { $block = array(); list($type, $id) = explode('-', $delta); + $result = FALSE; switch ($type) { case 'feed': if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) { @@ -413,9 +414,12 @@ function aggregator_block_view($delta = '') { } break; } + $items = array(); - foreach ($result as $item) { - $items[] = theme('aggregator_block_item', array('item' => $item)); + if (!empty($result)) { + foreach ($result as $item) { + $items[] = theme('aggregator_block_item', array('item' => $item)); + } } // Only display the block if there are items to show. diff --git a/core/modules/aggregator/aggregator.test b/core/modules/aggregator/aggregator.test index 2149bed535e..61ad16b2d81 100644 --- a/core/modules/aggregator/aggregator.test +++ b/core/modules/aggregator/aggregator.test @@ -887,6 +887,16 @@ class AggregatorRenderingTestCase extends AggregatorTestCase { $this->drupalGet($href); $correct_titles = $this->xpath('//h1[normalize-space(text())=:title]', array(':title' => $feed->title)); $this->assertFalse(empty($correct_titles), t('Aggregator feed page is available and has the correct title.')); + + // Set the number of news items to 0 to test that the block does not show + // up. + $feed->block = 0; + aggregator_save_feed((array) $feed); + // It is nescessary to flush the cache after saving the number of items. + drupal_flush_all_caches(); + // Check that the block is no longer displayed. + $this->drupalGet('node'); + $this->assertNoText(t($block['title']), 'Feed block is not displayed on the page when number of items is set to 0.'); } /** diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index c0f92d98cee..d84b785c278 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -264,7 +264,7 @@ function comment_confirm_delete_page($cid) { /** * Form constructor for the confirmation form for comment deletion. * - * @param $comment + * @param Comment $comment * The comment that is about to be deleted. * * @ingroup forms @@ -272,7 +272,7 @@ function comment_confirm_delete_page($cid) { * @see comment_confirm_delete_submit() * @see confirm_form() */ -function comment_confirm_delete($form, &$form_state, $comment) { +function comment_confirm_delete($form, &$form_state, Comment $comment) { $form['#comment'] = $comment; // Always provide entity id in the same form key as in the entity edit form. $form['cid'] = array('#type' => 'value', '#value' => $comment->cid); diff --git a/core/modules/comment/comment.api.php b/core/modules/comment/comment.api.php index f270aadade1..eb9f34d4acf 100644 --- a/core/modules/comment/comment.api.php +++ b/core/modules/comment/comment.api.php @@ -16,10 +16,10 @@ * This hook is invoked from comment_save() before the comment is saved to the * database. * - * @param $comment + * @param Comment $comment * The comment object. */ -function hook_comment_presave($comment) { +function hook_comment_presave(Comment $comment) { // Remove leading & trailing spaces from the comment subject. $comment->subject = trim($comment->subject); } @@ -27,10 +27,10 @@ function hook_comment_presave($comment) { /** * Respond to creation of a new comment. * - * @param $comment + * @param Comment $comment * The comment object. */ -function hook_comment_insert($comment) { +function hook_comment_insert(Comment $comment) { // Reindex the node when comments are added. search_touch_node($comment->nid); } @@ -38,10 +38,10 @@ function hook_comment_insert($comment) { /** * Respond to updates to a comment. * - * @param $comment + * @param Comment $comment * The comment object. */ -function hook_comment_update($comment) { +function hook_comment_update(Comment $comment) { // Reindex the node when comments are updated. search_touch_node($comment->nid); } @@ -49,10 +49,10 @@ function hook_comment_update($comment) { /** * Act on comments being loaded from the database. * - * @param $comments + * @param array $comments * An array of comment objects indexed by cid. */ -function hook_comment_load($comments) { +function hook_comment_load(Comment $comments) { $result = db_query('SELECT cid, foo FROM {mytable} WHERE cid IN (:cids)', array(':cids' => array_keys($comments))); foreach ($result as $record) { $comments[$record->cid]->foo = $record->foo; @@ -62,7 +62,7 @@ function hook_comment_load($comments) { /** * Act on a comment that is being assembled before rendering. * - * @param $comment + * @param Comment $comment * Passes in the comment the action is being performed on. * @param $view_mode * View mode, e.g. 'full', 'teaser'... @@ -71,7 +71,7 @@ function hook_comment_load($comments) { * * @see hook_entity_view() */ -function hook_comment_view($comment, $view_mode, $langcode) { +function hook_comment_view(Comment $comment, $view_mode, $langcode) { // how old is the comment $comment->time_ago = time() - $comment->changed; } @@ -108,20 +108,20 @@ function hook_comment_view_alter(&$build) { /** * Respond to a comment being published by a moderator. * - * @param $comment + * @param Comment $comment * The comment the action is being performed on. */ -function hook_comment_publish($comment) { +function hook_comment_publish(Comment $comment) { drupal_set_message(t('Comment: @subject has been published', array('@subject' => $comment->subject))); } /** * Respond to a comment being unpublished by a moderator. * - * @param $comment + * @param Comment $comment * The comment the action is being performed on. */ -function hook_comment_unpublish($comment) { +function hook_comment_unpublish(Comment $comment) { drupal_set_message(t('Comment: @subject has been unpublished', array('@subject' => $comment->subject))); } @@ -132,14 +132,14 @@ function hook_comment_unpublish($comment) { * field_attach_delete() is called and before the comment is actually removed * from the database. * - * @param $comment + * @param Comment $comment * The comment object for the comment that is about to be deleted. * * @see hook_comment_delete() * @see comment_delete_multiple() * @see entity_delete_multiple() */ -function hook_comment_predelete($comment) { +function hook_comment_predelete(Comment $comment) { // Delete a record associated with the comment in a custom table. db_delete('example_comment_table') ->condition('cid', $comment->cid) @@ -153,14 +153,14 @@ function hook_comment_predelete($comment) { * field_attach_delete() has called and after the comment has been removed from * the database. * - * @param $comment + * @param Comment $comment * The comment object for the comment that has been deleted. * * @see hook_comment_predelete() * @see comment_delete_multiple() * @see entity_delete_multiple() */ -function hook_comment_delete($comment) { +function hook_comment_delete(Comment $comment) { drupal_set_message(t('Comment: @subject has been deleted', array('@subject' => $comment->subject))); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 2c28b3533b7..e4dab80f06e 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -164,7 +164,7 @@ function comment_node_type_load($name) { /** * Entity uri callback. */ -function comment_uri($comment) { +function comment_uri(Comment $comment) { return array( 'path' => 'comment/' . $comment->cid, 'options' => array('fragment' => 'comment-' . $comment->cid), @@ -935,7 +935,7 @@ function comment_prepare_thread(&$comments) { /** * Generates an array for rendering a comment. * - * @param $comment + * @param Comment $comment * The comment object. * @param $node * The node the comment is attached to. @@ -948,7 +948,7 @@ function comment_prepare_thread(&$comments) { * @return * An array as expected by drupal_render(). */ -function comment_view($comment, $node, $view_mode = 'full', $langcode = NULL) { +function comment_view(Comment $comment, $node, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { $langcode = $GLOBALS['language_content']->langcode; } @@ -1005,7 +1005,7 @@ function comment_view($comment, $node, $view_mode = 'full', $langcode = NULL) { * The content built for the comment (field values, comments, file attachments * or other comment components) will vary depending on the $view_mode parameter. * - * @param $comment + * @param Comment $comment * A comment object. * @param $node * The node the comment is attached to. @@ -1015,7 +1015,7 @@ function comment_view($comment, $node, $view_mode = 'full', $langcode = NULL) { * (optional) A language code to use for rendering. Defaults to the global * content language of the current request. */ -function comment_build_content($comment, $node, $view_mode = 'full', $langcode = NULL) { +function comment_build_content(Comment $comment, $node, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { $langcode = $GLOBALS['language_content']->langcode; } @@ -1049,7 +1049,7 @@ function comment_build_content($comment, $node, $view_mode = 'full', $langcode = /** * Adds reply, edit, delete, etc. links, depending on user permissions. * - * @param $comment + * @param Comment $comment * The comment object. * @param $node * The node the comment is attached to. @@ -1057,7 +1057,7 @@ function comment_build_content($comment, $node, $view_mode = 'full', $langcode = * @return * A structured array of links. */ -function comment_links($comment, $node) { +function comment_links(Comment $comment, $node) { $links = array(); if ($node->comment == COMMENT_NODE_OPEN) { if (user_access('administer comments') && user_access('post comments')) { @@ -1451,13 +1451,13 @@ function comment_user_predelete($account) { * @param $op * The operation that is to be performed on the comment. Only 'edit' is * recognized now. - * @param $comment + * @param Comment $comment * The comment object. * * @return * TRUE if the current user has acces to the comment, FALSE otherwise. */ -function comment_access($op, $comment) { +function comment_access($op, Comment $comment) { global $user; if ($op == 'edit') { @@ -1468,10 +1468,10 @@ function comment_access($op, $comment) { /** * Accepts a submission of new or changed comment content. * - * @param $comment + * @param Comment $comment * A comment object. */ -function comment_save($comment) { +function comment_save(Comment $comment) { $comment->save(); } @@ -1644,12 +1644,12 @@ function comment_get_display_page($cid, $node_type) { /** * Page callback: Displays the comment editing form. * - * @param $comment + * @param Comment $comment * The comment object representing the comment to be edited. * * @see comment_menu() */ -function comment_edit_page($comment) { +function comment_edit_page(Comment $comment) { drupal_set_title(t('Edit comment %comment', array('%comment' => $comment->subject)), PASS_THROUGH); $node = node_load($comment->nid); return drupal_get_form("comment_node_{$node->type}_form", $comment); @@ -1674,7 +1674,7 @@ function comment_forms() { * @see comment_form_build_preview() * @ingroup forms */ -function comment_form($form, &$form_state, $comment) { +function comment_form($form, &$form_state, Comment $comment) { global $user, $language_content; // During initial form build, add the comment entity to the form state for @@ -1888,9 +1888,11 @@ function comment_form_build_preview($form, &$form_state) { /** * Generates a comment preview. * + * @param Comment $comment + * * @see comment_form_build_preview() */ -function comment_preview($comment) { +function comment_preview(Comment $comment) { global $user; drupal_set_title(t('Preview comment'), PASS_THROUGH); @@ -1987,8 +1989,11 @@ function comment_form_validate($form, &$form_state) { /** * Prepare a comment for submission. + * + * @param Comment $comment + * */ -function comment_submit($comment) { +function comment_submit(Comment $comment) { if (empty($comment->date)) { $comment->date = 'now'; } @@ -2328,15 +2333,15 @@ function comment_action_info() { /** * Publishes a comment. * - * @param $comment - * An optional comment object. + * @param Comment $comment + * (optional) A comment object to publish. * @param array $context * Array with components: * - 'cid': Comment ID. Required if $comment is not given. * * @ingroup actions */ -function comment_publish_action($comment, $context = array()) { +function comment_publish_action(Comment $comment = NULL, $context = array()) { if (isset($comment->subject)) { $subject = $comment->subject; $comment->status = COMMENT_PUBLISHED; @@ -2355,15 +2360,15 @@ function comment_publish_action($comment, $context = array()) { /** * Unpublishes a comment. * - * @param $comment - * An optional comment object. + * @param Comment|null $comment + * (optional) A comment object to unpublish. * @param array $context * Array with components: * - 'cid': Comment ID. Required if $comment is not given. * * @ingroup actions */ -function comment_unpublish_action($comment, $context = array()) { +function comment_unpublish_action(Comment $comment = NULL, $context = array()) { if (isset($comment->subject)) { $subject = $comment->subject; $comment->status = COMMENT_NOT_PUBLISHED; @@ -2382,7 +2387,7 @@ function comment_unpublish_action($comment, $context = array()) { /** * Unpublishes a comment if it contains certain keywords. * - * @param $comment + * @param Comment $comment * Comment object to modify. * @param array $context * Array with components: @@ -2393,7 +2398,7 @@ function comment_unpublish_action($comment, $context = array()) { * @see comment_unpublish_by_keyword_action_form() * @see comment_unpublish_by_keyword_action_submit() */ -function comment_unpublish_by_keyword_action($comment, $context) { +function comment_unpublish_by_keyword_action(Comment $comment, $context) { foreach ($context['keywords'] as $keyword) { $text = drupal_render($comment); if (strpos($text, $keyword) !== FALSE) { @@ -2434,9 +2439,11 @@ function comment_unpublish_by_keyword_action_submit($form, $form_state) { /** * Saves a comment. * + * @param Comment $comment + * * @ingroup actions */ -function comment_save_action($comment) { +function comment_save_action(Comment $comment) { comment_save($comment); cache_clear_all(); watchdog('action', 'Saved comment %title', array('%title' => $comment->subject)); diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc index c9cc96a10ea..02020ffbcda 100644 --- a/core/modules/comment/comment.pages.inc +++ b/core/modules/comment/comment.pages.inc @@ -47,12 +47,9 @@ function comment_reply($node, $pid = NULL) { // $pid indicates that this is a reply to a comment. if ($pid) { if (user_access('access comments')) { - // Load the comment whose cid = $pid - $comment = db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array( - ':cid' => $pid, - ':status' => COMMENT_PUBLISHED, - ))->fetchObject(); - if ($comment) { + // Load the parent comment. + $comment = comment_load($pid); + if ($comment->status = COMMENT_PUBLISHED) { // If that comment exists, make sure that the current comment and the // parent comment both belong to the same parent node. if ($comment->nid != $node->nid) { diff --git a/core/modules/comment/comment.test b/core/modules/comment/comment.test index 925751398ed..259e420c979 100644 --- a/core/modules/comment/comment.test +++ b/core/modules/comment/comment.test @@ -96,7 +96,7 @@ class CommentHelperCase extends DrupalWebTestCase { /** * Checks current page for specified comment. * - * @param object $comment + * @param Comment $comment * The comment object. * @param boolean $reply * Boolean indicating whether the comment is a reply to another comment. @@ -104,8 +104,8 @@ class CommentHelperCase extends DrupalWebTestCase { * @return boolean * Boolean indicating whether the comment was found. */ - function commentExists($comment, $reply = FALSE) { - if ($comment && is_object($comment)) { + function commentExists(Comment $comment = NULL, $reply = FALSE) { + if ($comment) { $regex = '/' . ($reply ? '