[DATABASE] Columns not in GROUP BY must not be queried

This commit is contained in:
Alexei Sorokin 2019-09-11 13:12:41 +03:00
parent 7ee8aa7838
commit 471576d6e8
4 changed files with 78 additions and 83 deletions

View File

@ -1,45 +1,38 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/*
* StatusNet - the distributed open-source microblogging tool
*
* Handler for reminder queue items which send reminder emails to all users
* we would like to complete a given process (e.g.: registration).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Email
* @package StatusNet
* @package GNUsocial
* @author Zach Copley <zach@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Handler for reminder queue items which send reminder emails to all users
* we would like to complete a given process (e.g.: registration)
*
* @category Email
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class SiteConfirmReminderHandler extends QueueHandler
{
@ -52,7 +45,7 @@ class SiteConfirmReminderHandler extends QueueHandler
*
* @return string
*/
function transport()
public function transport()
{
return 'siterem';
}
@ -63,14 +56,14 @@ class SiteConfirmReminderHandler extends QueueHandler
* @param array $remitem type of reminder to send and any special options
* @return boolean true on success, false on failure
*/
function handle($remitem) : bool
public function handle($remitem): bool
{
list($type, $opts) = $remitem;
$qm = QueueManager::get();
try {
switch($type) {
switch ($type) {
case UserConfirmRegReminderHandler::REGISTER_REMINDER:
$confirm = new Confirm_address();
$confirm->address_type = $type;
@ -87,7 +80,11 @@ class SiteConfirmReminderHandler extends QueueHandler
case UserInviteReminderHandler::INVITE_REMINDER:
$invitation = new Invitation();
// Only send one reminder (the latest one), regardless of how many invitations a user has
$sql = 'SELECT * FROM (SELECT * FROM invitation WHERE registered_user_id IS NULL ORDER BY created DESC) invitees GROUP BY invitees.address';
$sql = 'SELECT * FROM invitation ' .
'WHERE (address, created) IN ' .
'(SELECT address, MAX(created) FROM invitation GROUP BY address) AND ' .
'registered_user_id IS NULL ' .
'ORDER BY created DESC';
$invitation->query($sql);
while ($invitation->fetch()) {
try {

View File

@ -1,44 +1,36 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* Data class to mark notices as bookmarks
*
* PHP version 5
*
* @category PollPlugin
* @package StatusNet
* @package GNUsocial
* @author Brion Vibber <brion@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* For storing the poll options and such
*
* @category PollPlugin
* @package StatusNet
* @author Brion Vibber <brion@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see DB_DataObject
*/
@ -136,7 +128,9 @@ class Poll extends Managed_DataObject
$pr = new Poll_response();
$pr->poll_id = $this->id;
$pr->groupBy('selection');
$pr->selectAdd('count(profile_id) as votes');
$pr->selectAdd();
$pr->selectAdd('selection');
$pr->selectAdd('COUNT(profile_id) AS votes');
$pr->find();
$raw = array();

View File

@ -110,6 +110,8 @@ class SearchSubPlugin extends Plugin
// with a lot of searches!
$sub = new SearchSub();
$sub->groupBy('search');
$sub->selectAdd();
$sub->selectAdd('search');
$sub->find();
while ($sub->fetch()) {
$search = $sub->search;

View File

@ -1,21 +1,23 @@
#!/usr/bin/env php
<?php
/*
* StatusNet - a distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
define('INSTALLDIR', dirname(__DIR__));
@ -44,7 +46,7 @@ if (!have_option('y', 'yes')) {
}
$file = new File();
$file->query('SELECT id, url, COUNT(*) AS c FROM file GROUP BY url HAVING c > 1');
$file->query('SELECT url FROM file GROUP BY url HAVING COUNT(*) > 1');
print "\nFound {$file->N} URLs with duplicate entries in file table";
while ($file->fetch()) {
// We've got a URL that is duplicated in the file table
@ -54,7 +56,7 @@ while ($file->fetch()) {
print "\nDeleting duplicate entries in file table for URL: {$file->url} [";
// Leave one of the URLs in the database by using ->find(true)
// and only deleting starting with this fetch.
while($dupfile->fetch()) {
while ($dupfile->fetch()) {
print ".";
$dupfile->delete();
}
@ -65,7 +67,7 @@ while ($file->fetch()) {
}
$file = new File_redirection();
$file->query('SELECT file_id, url, COUNT(*) AS c FROM file_redirection GROUP BY url HAVING c > 1');
$file->query('SELECT url FROM file_redirection GROUP BY url HAVING COUNT(*) > 1');
print "\nFound {$file->N} URLs with duplicate entries in file_redirection table";
while ($file->fetch()) {
// We've got a URL that is duplicated in the file_redirection table
@ -75,7 +77,7 @@ while ($file->fetch()) {
print "\nDeleting duplicate entries in file table for URL: {$file->url} [";
// Leave one of the URLs in the database by using ->find(true)
// and only deleting starting with this fetch.
while($dupfile->fetch()) {
while ($dupfile->fetch()) {
print ".";
$dupfile->delete();
}