[DATABASE] Re-introduce PostgreSQL support

This commit is contained in:
Alexei Sorokin
2019-09-11 14:14:40 +03:00
committed by Diogo Peralta Cordeiro
parent e807e3bf08
commit 16b5ddd230
22 changed files with 606 additions and 410 deletions

View File

@@ -83,7 +83,8 @@ class Spam_score extends Managed_DataObject
'notice_id' => array('type' => 'int',
'not null' => true,
'description' => 'notice getting scored'),
'score' => array('type' => 'double',
'score' => array('type' => 'float',
'size' => 'big',
'not null' => true,
'description' => 'score for the notice (0.0, 1.0)'),
'scaled' => array('type' => 'int',

View File

@@ -1,33 +1,32 @@
<?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
*
* Simple-minded queue manager for storing items in the database
*
* PHP version 5
*
* LICENCE: 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 QueueManager
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Brion Vibber <brion@status.net>
* @copyright 2009-2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
class DBQueueManager extends QueueManager
{
/**
@@ -39,7 +38,7 @@ class DBQueueManager extends QueueManager
{
$qi = new Queue_item();
$qi->frame = $this->encode($object);
$qi->frame = DB_DataObject_Cast::blob($this->encode($object));
$qi->transport = $queue;
$qi->created = common_sql_now();
$result = $qi->insert();
@@ -121,7 +120,8 @@ class DBQueueManager extends QueueManager
// What to do if no handler was found. For example, the OpportunisticQM
// should avoid deleting items just because it can't reach XMPP queues etc.
protected function noHandlerFound(Queue_item $qi, $rep=null) {
protected function noHandlerFound(Queue_item $qi, $rep = null)
{
$this->_log(LOG_INFO, "[{$qi->transport}:{$rep}] No handler for queue {$qi->transport}; discarding.");
$this->_done($qi);
}

View File

@@ -1,21 +1,23 @@
#!/usr/bin/env php
<?php
/*
* StatusNet - a distributed open-source microblogging tool
* Copyright (C) 2010, 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 2010 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
@@ -39,7 +41,8 @@ END_OF_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
function showProfileInfo(Ostatus_profile $oprofile) {
function showProfileInfo(Ostatus_profile $oprofile)
{
if ($oprofile->isGroup()) {
echo "group\n";
} else {
@@ -51,7 +54,8 @@ function showProfileInfo(Ostatus_profile $oprofile) {
echo "\n";
}
function fixProfile(Ostatus_profile $oprofile) {
function fixProfile(Ostatus_profile $oprofile)
{
echo "Before:\n";
showProfileInfo($oprofile);
@@ -102,10 +106,10 @@ if (have_option('all')) {
echo "Failed on URI=="._ve($oprofile->uri).": {$e->getMessage()}\n";
}
}
} else if (have_option('suspicious')) {
} elseif (have_option('suspicious')) {
$oprofile = new Ostatus_profile();
$oprofile->joinAdd(array('profile_id', 'profile:id'));
$oprofile->whereAdd("nickname rlike '^[0-9]$'");
$oprofile->joinAdd(['profile_id', 'profile:id']);
$oprofile->whereAdd("CHAR_LENGTH(nickname) = 1 AND nickname BETWEEN '0' AND '9'");
$oprofile->find();
echo "Found $oprofile->N matching profiles:\n\n";
while ($oprofile->fetch()) {
@@ -116,7 +120,7 @@ if (have_option('all')) {
echo "Failed on URI=="._ve($oprofile->uri).": {$e->getMessage()}\n";
}
}
} else if (!empty($args[0]) && $validate->uri($args[0])) {
} elseif (!empty($args[0]) && $validate->uri($args[0])) {
$uri = $args[0];
$oprofile = Ostatus_profile::getKV('uri', $uri);

View File

@@ -1,25 +1,25 @@
<?php
/*
* StatusNet - the 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
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
require_once('Auth/OpenID.php');
require_once('Auth/OpenID/Consumer.php');
@@ -49,19 +49,19 @@ function oid_store()
}
$db = DB::connect($dsn, $options);
if (PEAR::isError($db)) {
if ((new PEAR)->isError($db)) {
throw new ServerException($db->getMessage());
}
switch (common_config('db', 'type')) {
case 'pgsql':
$store = new Auth_OpenID_PostgreSQLStore($db);
break;
case 'mysql':
$store = new Auth_OpenID_MySQLStore($db);
break;
case 'postgresql':
$store = new Auth_OpenID_PostgreSQLStore($db);
break;
default:
throw new ServerException(_m('Unknown DB type for OpenID.'));
throw new ServerException('Unknown DB type selected.');
}
}
return $store;
@@ -90,9 +90,11 @@ function oid_clear_last()
function oid_set_last($openid_url)
{
common_set_cookie(OPENID_COOKIE_KEY,
$openid_url,
time() + OPENID_COOKIE_EXPIRY);
common_set_cookie(
OPENID_COOKIE_KEY,
$openid_url,
time() + OPENID_COOKIE_EXPIRY
);
}
function oid_get_last()
@@ -119,7 +121,7 @@ function oid_link_user($id, $canonical, $display)
$oid->created = common_sql_now();
if (!$oid->insert()) {
$err = &$_PEAR->getStaticProperty('DB_DataObject','lastError');
$err = &$_PEAR->getStaticProperty('DB_DataObject', 'lastError');
return false;
}
@@ -149,9 +151,11 @@ function oid_check_immediate($openid_url, $backto=null)
$_SESSION['openid_immediate_backto'] = $backto;
oid_authenticate($openid_url,
'finishimmediate',
true);
oid_authenticate(
$openid_url,
'finishimmediate',
true
);
}
function oid_authenticate($openid_url, $returnto, $immediate=false)
@@ -177,23 +181,27 @@ function oid_authenticate($openid_url, $returnto, $immediate=false)
common_log(LOG_ERR, __METHOD__ . ": mystery fail contacting $openid_url");
// TRANS: OpenID plugin message. Given when an OpenID is not valid.
throw new ServerException(_m('Not a valid OpenID.'));
} else if (Auth_OpenID::isFailure($auth_request)) {
} elseif (Auth_OpenID::isFailure($auth_request)) {
common_log(LOG_ERR, __METHOD__ . ": OpenID fail to $openid_url: $auth_request->message");
// TRANS: OpenID plugin server error. Given when the OpenID authentication request fails.
// TRANS: %s is the failure message.
throw new ServerException(sprintf(_m('OpenID failure: %s.'), $auth_request->message));
}
$sreg_request = Auth_OpenID_SRegRequest::build(// Required
array(),
// Optional
array('nickname',
'email',
'fullname',
'language',
'timezone',
'postcode',
'country'));
$sreg_request = Auth_OpenID_SRegRequest::build(
// Required
[],
// Optional
[
'nickname',
'email',
'fullname',
'language',
'timezone',
'postcode',
'country',
]
);
if ($sreg_request) {
$auth_request->addExtension($sreg_request);
@@ -224,9 +232,11 @@ function oid_authenticate($openid_url, $returnto, $immediate=false)
// autosubmitter for now.
//
//if ($auth_request->shouldSendRedirect()) {
$redirect_url = $auth_request->redirectURL($trust_root,
$process_url,
$immediate);
$redirect_url = $auth_request->redirectURL(
$trust_root,
$process_url,
$immediate
);
if (Auth_OpenID::isFailure($redirect_url)) {
// TRANS: OpenID plugin server error. Given when the OpenID authentication request cannot be redirected.
// TRANS: %s is the failure message.
@@ -266,11 +276,14 @@ function oid_authenticate($openid_url, $returnto, $immediate=false)
function _oid_print_instructions()
{
common_element('div', 'instructions',
// TRANS: OpenID plugin user instructions.
_m('This form should automatically submit itself. '.
'If not, click the submit button to go to your '.
'OpenID provider.'));
common_element(
'div',
'instructions',
// TRANS: OpenID plugin user instructions.
_m('This form should automatically submit itself. '.
'If not, click the submit button to go to your '.
'OpenID provider.')
);
}
/**
@@ -382,22 +395,22 @@ function oid_check_teams($response)
class AutosubmitAction extends Action
{
var $form_html = null;
var $form_id = null;
public $form_html = null;
public $form_id = null;
function handle()
public function handle()
{
parent::handle();
$this->showPage();
}
function title()
public function title()
{
// TRANS: Title
return _m('OpenID Login Submission');
}
function showContent()
public function showContent()
{
$this->raw('<p style="margin: 20px 80px">');
// @todo FIXME: This would be better using standard CSS class, but the present theme's a bit scary.
@@ -414,10 +427,13 @@ class AutosubmitAction extends Action
$this->raw($this->form_html);
}
function showScripts()
public function showScripts()
{
parent::showScripts();
$this->element('script', null,
'document.getElementById(\'' . $this->form_id . '\').submit();');
$this->element(
'script',
null,
'document.getElementById(\'' . $this->form_id . '\').submit();'
);
}
}

View File

@@ -22,7 +22,7 @@ client side, which itself depends on the sphinx development files.
"pecl install sphinx" should take care of that. Add "extension=sphinx.so"
to your php.ini and reload apache to enable it.
You can update your MySQL or Postgresql databases to drop their fulltext
You can update your MariaDB or PostgreSQL databases to drop their fulltext
search indexes, since they're now provided by sphinx.