[DATABASE] Fix index identifiers and clean up redundant ones

This commit is contained in:
Alexei Sorokin 2020-07-31 16:12:48 +03:00 committed by Diogo Peralta Cordeiro
parent f3ab63957d
commit 665e4574da
33 changed files with 249 additions and 259 deletions

View File

@ -51,7 +51,6 @@ class Attention extends Managed_DataObject
'attention_profile_id_fkey' => array('profile', array('profile_id' => 'id')), 'attention_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
), ),
'indexes' => array( 'indexes' => array(
'attention_notice_id_idx' => array('notice_id'),
'attention_profile_id_idx' => array('profile_id'), 'attention_profile_id_idx' => array('profile_id'),
), ),
); );

View File

@ -52,9 +52,6 @@ class Avatar extends Managed_DataObject
'foreign keys' => array( 'foreign keys' => array(
'avatar_profile_id_fkey' => array('profile', array('profile_id' => 'id')), 'avatar_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
), ),
'indexes' => array(
'avatar_profile_id_idx' => array('profile_id'),
),
); );
} }

View File

@ -51,7 +51,6 @@ class File_thumbnail extends Managed_DataObject
), ),
'primary key' => array('file_id', 'width', 'height'), 'primary key' => array('file_id', 'width', 'height'),
'indexes' => array( 'indexes' => array(
'file_thumbnail_file_id_idx' => array('file_id'),
'file_thumbnail_urlhash_idx' => array('urlhash'), 'file_thumbnail_urlhash_idx' => array('urlhash'),
), ),
'foreign keys' => array( 'foreign keys' => array(

View File

@ -50,8 +50,7 @@ class File_to_post extends Managed_DataObject
'file_to_post_post_id_fkey' => array('notice', array('post_id' => 'id')), 'file_to_post_post_id_fkey' => array('notice', array('post_id' => 'id')),
), ),
'indexes' => array( 'indexes' => array(
'file_id_idx' => array('file_id'), 'file_to_post_post_id_idx' => array('post_id'),
'post_id_idx' => array('post_id'),
), ),
); );
} }

View File

@ -60,12 +60,9 @@ class Foreign_link extends Managed_DataObject
'primary key' => array('user_id', 'foreign_id', 'service'), 'primary key' => array('user_id', 'foreign_id', 'service'),
'foreign keys' => array( 'foreign keys' => array(
'foreign_link_user_id_fkey' => array('user', array('user_id' => 'id')), 'foreign_link_user_id_fkey' => array('user', array('user_id' => 'id')),
'foreign_link_foreign_id_fkey' => array('foreign_user', array('foreign_id' => 'id', 'service' => 'service')), 'foreign_link_foreign_id_service_fkey' => array('foreign_user', array('foreign_id' => 'id', 'service' => 'service')),
'foreign_link_service_fkey' => array('foreign_service', array('service' => 'id')), 'foreign_link_service_fkey' => array('foreign_service', array('service' => 'id')),
), ),
'indexes' => array(
'foreign_user_user_id_idx' => array('user_id'),
),
); );
} }

View File

@ -47,12 +47,11 @@ class Foreign_subscription extends Managed_DataObject
'primary key' => array('service', 'subscriber', 'subscribed'), 'primary key' => array('service', 'subscriber', 'subscribed'),
'foreign keys' => array( 'foreign keys' => array(
'foreign_subscription_service_fkey' => array('foreign_service', array('service' => 'id')), 'foreign_subscription_service_fkey' => array('foreign_service', array('service' => 'id')),
'foreign_subscription_subscriber_fkey' => array('foreign_user', array('subscriber' => 'id', 'service' => 'service')), 'foreign_subscription_subscriber_service_fkey' => array('foreign_user', array('subscriber' => 'id', 'service' => 'service')),
'foreign_subscription_subscribed_fkey' => array('foreign_user', array('subscribed' => 'id', 'service' => 'service')), 'foreign_subscription_subscribed_service_fkey' => array('foreign_user', array('subscribed' => 'id', 'service' => 'service')),
), ),
'indexes' => array( 'indexes' => array(
'foreign_subscription_subscriber_idx' => array('service', 'subscriber'), 'foreign_subscription_service_subscribed_idx' => array('service', 'subscribed'),
'foreign_subscription_subscribed_idx' => array('service', 'subscribed'),
), ),
); );
} }

View File

@ -56,8 +56,6 @@ class Group_member extends Managed_DataObject
'group_member_profile_id_fkey' => array('profile', array('profile_id' => 'id')), 'group_member_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
), ),
'indexes' => array( 'indexes' => array(
// @fixme probably we want a (profile_id, created) index here?
'group_member_profile_id_idx' => array('profile_id'),
'group_member_created_idx' => array('created'), 'group_member_created_idx' => array('created'),
'group_member_profile_id_created_idx' => array('profile_id', 'created'), 'group_member_profile_id_created_idx' => array('profile_id', 'created'),
'group_member_group_id_created_idx' => array('group_id', 'created'), 'group_member_group_id_created_idx' => array('group_id', 'created'),

View File

@ -61,7 +61,7 @@ class Invitation extends Managed_DataObject
'invitation_registered_user_id_fkey' => array('user', array('registered_user_id' => 'id')), 'invitation_registered_user_id_fkey' => array('user', array('registered_user_id' => 'id')),
), ),
'indexes' => array( 'indexes' => array(
'invitation_address_idx' => array('address', 'address_type'), 'invitation_address_address_type_idx' => array('address', 'address_type'),
'invitation_user_id_idx' => array('user_id'), 'invitation_user_id_idx' => array('user_id'),
'invitation_registered_user_id_idx' => array('registered_user_id'), 'invitation_registered_user_id_idx' => array('registered_user_id'),
), ),

View File

@ -114,7 +114,7 @@ class Notice extends Managed_DataObject
'notice_object_type_idx' => array('object_type'), 'notice_object_type_idx' => array('object_type'),
'notice_verb_idx' => array('verb'), 'notice_verb_idx' => array('verb'),
'notice_url_idx' => array('url'), // Qvitter wants this 'notice_url_idx' => array('url'), // Qvitter wants this
'notice_replyto_idx' => array('reply_to') 'notice_reply_to_idx' => array('reply_to')
) )
); );

View File

@ -52,9 +52,6 @@ class Notice_prefs extends Managed_DataObject
'foreign keys' => array( 'foreign keys' => array(
'notice_prefs_notice_id_fkey' => array('notice', array('notice_id' => 'id')), 'notice_prefs_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
), ),
'indexes' => array(
'notice_prefs_notice_id_idx' => array('notice_id'),
),
); );
} }

View File

@ -65,9 +65,9 @@ class Oauth_token_association extends Managed_DataObject
), ),
'primary key' => array('profile_id', 'application_id', 'token'), 'primary key' => array('profile_id', 'application_id', 'token'),
'foreign keys' => array( 'foreign keys' => array(
'oauth_token_association_profile_fkey' => array('profile', array('profile_id' => 'id')), 'oauth_token_association_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
'oauth_token_association_application_fkey' => array('oauth_application', array('application_id' => 'id')), 'oauth_token_association_application_id_fkey' => array('oauth_application', array('application_id' => 'id')),
) ),
); );
} }
} }

View File

@ -67,7 +67,6 @@ class Profile_list extends Managed_DataObject
'indexes' => array( 'indexes' => array(
'profile_list_modified_idx' => array('modified'), 'profile_list_modified_idx' => array('modified'),
'profile_list_tag_idx' => array('tag'), 'profile_list_tag_idx' => array('tag'),
'profile_list_tagger_tag_idx' => array('tagger', 'tag'),
'profile_list_tagged_count_idx' => array('tagged_count'), 'profile_list_tagged_count_idx' => array('tagged_count'),
'profile_list_subscriber_count_idx' => array('subscriber_count'), 'profile_list_subscriber_count_idx' => array('subscriber_count'),
), ),

View File

@ -51,9 +51,6 @@ class Profile_prefs extends Managed_DataObject
'foreign keys' => array( 'foreign keys' => array(
'profile_prefs_profile_id_fkey' => array('profile', array('profile_id' => 'id')), 'profile_prefs_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
), ),
'indexes' => array(
'profile_prefs_profile_id_idx' => array('profile_id'),
),
); );
} }

View File

@ -46,7 +46,7 @@ class Profile_tag_subscription extends Managed_DataObject
), ),
'primary key' => array('profile_tag_id', 'profile_id'), 'primary key' => array('profile_tag_id', 'profile_id'),
'foreign keys' => array( 'foreign keys' => array(
'profile_tag_subscription_profile_list_id_fkey' => array('profile_list', array('profile_tag_id' => 'id')), 'profile_tag_subscription_profile_tag_id_fkey' => array('profile_list', array('profile_tag_id' => 'id')),
'profile_tag_subscription_profile_id_fkey' => array('profile', array('profile_id' => 'id')), 'profile_tag_subscription_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
), ),
'indexes' => array( 'indexes' => array(

View File

@ -49,7 +49,6 @@ class Reply extends Managed_DataObject
'reply_profile_id_fkey' => array('profile', array('profile_id' => 'id')), 'reply_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
), ),
'indexes' => array( 'indexes' => array(
'reply_notice_id_idx' => array('notice_id'),
'reply_profile_id_idx' => array('profile_id'), 'reply_profile_id_idx' => array('profile_id'),
'reply_replied_id_idx' => array('replied_id'), 'reply_replied_id_idx' => array('replied_id'),
'reply_profile_id_modified_notice_id_idx' => array('profile_id', 'modified', 'notice_id') 'reply_profile_id_modified_notice_id_idx' => array('profile_id', 'modified', 'notice_id')

View File

@ -15,7 +15,7 @@
// along with GNU social. If not, see <http://www.gnu.org/licenses/>. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* @copyright 2008, 2009, StatusNet, Inc. * @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
@ -59,8 +59,8 @@ class Subscription extends Managed_DataObject
'subscription_uri_key' => array('uri'), 'subscription_uri_key' => array('uri'),
), ),
'indexes' => array( 'indexes' => array(
'subscription_subscriber_idx' => array('subscriber', 'created'), 'subscription_subscriber_created_idx' => array('subscriber', 'created'),
'subscription_subscribed_idx' => array('subscribed', 'created'), 'subscription_subscribed_created_idx' => array('subscribed', 'created'),
'subscription_token_idx' => array('token'), 'subscription_token_idx' => array('token'),
), ),
); );

View File

@ -88,7 +88,7 @@ class User_group extends Managed_DataObject
// when it's safe and everyone's run upgrade.php 'user_profile_id_key' => array('profile_id'), // when it's safe and everyone's run upgrade.php 'user_profile_id_key' => array('profile_id'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'user_group_id_fkey' => array('profile', array('profile_id' => 'id')), 'user_group_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
), ),
'indexes' => array( 'indexes' => array(
'user_group_nickname_idx' => array('nickname'), 'user_group_nickname_idx' => array('nickname'),

View File

@ -59,7 +59,7 @@ class User_im_prefs extends Managed_DataObject
), ),
'primary key' => array('user_id', 'transport'), 'primary key' => array('user_id', 'transport'),
'unique keys' => array( 'unique keys' => array(
'transport_screenname_key' => array('transport', 'screenname'), 'user_im_prefs_transport_screenname_key' => array('transport', 'screenname'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'user_im_prefs_user_id_fkey' => array('user', array('user_id' => 'id')), 'user_im_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),

View File

@ -46,12 +46,12 @@ class User_username extends Managed_DataObject
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'), 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
), ),
'primary key' => array('provider_name', 'username'), 'primary key' => array('provider_name', 'username'),
'indexes' => array(
'user_id_idx' => array('user_id')
),
'foreign keys' => array( 'foreign keys' => array(
'user_username_user_id_fkey' => array('user', array('user_id' => 'id')), 'user_username_user_id_fkey' => array('user', array('user_id' => 'id')),
), ),
'indexes' => array(
'user_username_user_id_idx' => array('user_id'),
),
); );
} }

View File

@ -90,7 +90,9 @@ class Realtime_channel extends Managed_DataObject
'description' => 'date this record was modified'], 'description' => 'date this record was modified'],
], ],
'primary key' => ['channel_key'], 'primary key' => ['channel_key'],
'unique keys' => ['realtime_channel_user_page_idx' => ['user_id', 'action', 'arg1', 'arg2']], 'unique keys' => [
'realtime_channel_user_id_action_arg1_arg2_key' => ['user_id', 'action', 'arg1', 'arg2'],
],
'foreign keys' => [ 'foreign keys' => [
'realtime_channel_user_id_fkey' => ['user', ['user_id' => 'id']], 'realtime_channel_user_id_fkey' => ['user', ['user_id' => 'id']],
], ],

View File

@ -48,8 +48,7 @@ class Fave extends Managed_DataObject
'fave_user_id_fkey' => array('profile', array('user_id' => 'id')), // note: formerly referenced notice.id, but we can now record remote users' favorites 'fave_user_id_fkey' => array('profile', array('user_id' => 'id')), // note: formerly referenced notice.id, but we can now record remote users' favorites
), ),
'indexes' => array( 'indexes' => array(
'fave_notice_id_idx' => array('notice_id'), 'fave_user_id_modified_idx' => array('user_id', 'modified'),
'fave_user_id_idx' => array('user_id', 'modified'),
'fave_modified_idx' => array('modified'), 'fave_modified_idx' => array('modified'),
), ),
); );

View File

@ -84,24 +84,24 @@ class Message extends Managed_DataObject
'indexes' => array( 'indexes' => array(
// @fixme these are really terrible indexes, since you can only sort on one of them at a time. // @fixme these are really terrible indexes, since you can only sort on one of them at a time.
// looks like we really need a (to_profile, created) for inbox and a (from_profile, created) for outbox // looks like we really need a (to_profile, created) for inbox and a (from_profile, created) for outbox
'message_from_idx' => array('from_profile'), 'message_from_profile_idx' => array('from_profile'),
'message_to_idx' => array('to_profile'), 'message_to_profile_idx' => array('to_profile'),
'message_created_idx' => array('created'), 'message_created_idx' => array('created'),
), ),
); );
} }
function getFrom() public function getFrom()
{ {
return Profile::getKV('id', $this->from_profile); return Profile::getKV('id', $this->from_profile);
} }
function getTo() public function getTo()
{ {
return Profile::getKV('id', $this->to_profile); return Profile::getKV('id', $this->to_profile);
} }
function getSource() public function getSource()
{ {
if (empty($this->source)) { if (empty($this->source)) {
return false; return false;
@ -133,7 +133,7 @@ class Message extends Managed_DataObject
return $ns; return $ns;
} }
function asActivity() public function asActivity()
{ {
$act = new Activity(); $act = new Activity();

View File

@ -135,7 +135,7 @@ class Email_reminder extends Managed_DataObject
), ),
'primary key' => array('type', 'code', 'days'), 'primary key' => array('type', 'code', 'days'),
'indexes' => array( 'indexes' => array(
'sent_idx' => array('sent'), 'email_reminder_sent_idx' => array('sent'),
), ),
); );
} }

View File

@ -1,33 +1,30 @@
<?php <?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 for happenings * Data class for happenings
* *
* PHP version 5
*
* @category Data * @category Data
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @copyright 2011 StatusNet, Inc.
* @link http://status.net/ * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* 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/>.
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* Data class for happenings * Data class for happenings
@ -38,10 +35,9 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* "Happening" seemed good enough. * "Happening" seemed good enough.
* *
* @category Event * @category Event
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
* *
* @see Managed_DataObject * @see Managed_DataObject
*/ */
@ -98,8 +94,10 @@ class Happening extends Managed_DataObject
'happening_profile_id_fkey' => array('profile', array('profile_id' => 'id')), 'happening_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
'happening_uri_fkey' => array('notice', array('uri' => 'uri')) 'happening_uri_fkey' => array('notice', array('uri' => 'uri'))
), ),
'indexes' => array('happening_created_idx' => array('created'), 'indexes' => array(
'happening_start_end_idx' => array('start_time', 'end_time')), 'happening_created_idx' => array('created'),
'happening_start_time_end_time_idx' => array('start_time', 'end_time'),
),
); );
} }
@ -131,6 +129,7 @@ class Happening extends Managed_DataObject
switch ($extra[0]) { switch ($extra[0]) {
case 'dtstart': case 'dtstart':
$dtstart = $extra[2]; $dtstart = $extra[2];
break;
case 'dtend': case 'dtend':
$dtend = $extra[2]; $dtend = $extra[2];
break; break;
@ -211,7 +210,7 @@ class Happening extends Managed_DataObject
return Notice::getByKeys(array('uri'=>$this->getUri())); return Notice::getByKeys(array('uri'=>$this->getUri()));
} }
static function fromStored(Notice $stored) public static function fromStored(Notice $stored)
{ {
if (!ActivityUtils::compareTypes($stored->getObjectType(), [self::OBJECT_TYPE])) { if (!ActivityUtils::compareTypes($stored->getObjectType(), [self::OBJECT_TYPE])) {
throw new ServerException('Notice is not of type '.self::OBJECT_TYPE); throw new ServerException('Notice is not of type '.self::OBJECT_TYPE);
@ -219,18 +218,20 @@ class Happening extends Managed_DataObject
return self::getByKeys(array('uri'=>$stored->getUri())); return self::getByKeys(array('uri'=>$stored->getUri()));
} }
function getRSVPs() public function getRSVPs()
{ {
return RSVP::forEvent($this); return RSVP::forEvent($this);
} }
function getRSVP($profile) public function getRSVP($profile)
{ {
return RSVP::pkeyGet(array('profile_id' => $profile->getID(), return RSVP::pkeyGet([
'event_uri' => $this->getUri())); 'profile_id' => $profile->getID(),
'event_uri' => $this->getUri(),
]);
} }
static public function getObjectType() public static function getObjectType()
{ {
return self::OBJECT_TYPE; return self::OBJECT_TYPE;
} }

View File

@ -1,42 +1,38 @@
<?php <?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 for event RSVPs * Data class for event RSVPs
* *
* PHP version 5
*
* @category Data * @category Data
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @copyright 2011 StatusNet, Inc.
* @link http://status.net/ * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* 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/>.
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* Data class for event RSVPs * Data class for event RSVPs
* *
* @category Event * @category Event
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
* *
* @see Managed_DataObject * @see Managed_DataObject
*/ */
@ -83,7 +79,7 @@ class RSVP extends Managed_DataObject
'primary key' => array('id'), 'primary key' => array('id'),
'unique keys' => array( 'unique keys' => array(
'rsvp_uri_key' => array('uri'), 'rsvp_uri_key' => array('uri'),
'rsvp_profile_event_key' => array('profile_id', 'event_uri'), 'rsvp_profile_id_event_uri_key' => array('profile_id', 'event_uri'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'rsvp_event_uri_fkey' => array('happening', array('event_uri' => 'uri')), 'rsvp_event_uri_fkey' => array('happening', array('event_uri' => 'uri')),
@ -93,7 +89,7 @@ class RSVP extends Managed_DataObject
); );
} }
static public function beforeSchemaUpdate() public static function beforeSchemaUpdate()
{ {
$table = strtolower(get_called_class()); $table = strtolower(get_called_class());
$schema = Schema::get(); $schema = Schema::get();
@ -128,7 +124,7 @@ class RSVP extends Managed_DataObject
print "Resuming core schema upgrade..."; print "Resuming core schema upgrade...";
} }
static function saveActivityObject(Activity $act, Notice $stored) public static function saveActivityObject(Activity $act, Notice $stored)
{ {
$target = Notice::getByKeys(array('uri'=>$act->target->id)); $target = Notice::getByKeys(array('uri'=>$act->target->id));
if (!ActivityUtils::compareTypes($target->getObjectType(), [ Happening::OBJECT_TYPE ])) { if (!ActivityUtils::compareTypes($target->getObjectType(), [ Happening::OBJECT_TYPE ])) {
@ -138,7 +134,8 @@ class RSVP extends Managed_DataObject
// FIXME: Maybe we need some permission handling here, though I think it's taken care of in saveActivity? // FIXME: Maybe we need some permission handling here, though I think it's taken care of in saveActivity?
try { try {
$other = RSVP::getByKeys( [ 'profile_id' => $stored->getProfile()->getID(), $other = RSVP::getByKeys([
'profile_id' => $stored->getProfile()->getID(),
'event_uri' => $target->getUri(), 'event_uri' => $target->getUri(),
]); ]);
// TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond"). // TRANS: Client exception thrown when trying to save an already existing RSVP ("please respond").
@ -162,7 +159,7 @@ class RSVP extends Managed_DataObject
return $rsvp; return $rsvp;
} }
static public function getObjectType() public static function getObjectType()
{ {
return ActivityObject::ACTIVITY; return ActivityObject::ACTIVITY;
} }
@ -181,7 +178,7 @@ class RSVP extends Managed_DataObject
return $actobj; return $actobj;
} }
static function codeFor($verb) public static function codeFor($verb)
{ {
switch (true) { switch (true) {
case ActivityUtils::compareVerbs($verb, [RSVP::POSITIVE]): case ActivityUtils::compareVerbs($verb, [RSVP::POSITIVE]):
@ -199,7 +196,7 @@ class RSVP extends Managed_DataObject
} }
} }
static function verbFor($code) public static function verbFor($code)
{ {
switch ($code) { switch ($code) {
case 'Y': case 'Y':
@ -235,18 +232,18 @@ class RSVP extends Managed_DataObject
return Notice::getByKeys(['uri' => $this->getUri()]); return Notice::getByKeys(['uri' => $this->getUri()]);
} }
static function fromStored(Notice $stored) public static function fromStored(Notice $stored)
{ {
return self::getByKeys(['uri' => $stored->getUri()]); return self::getByKeys(['uri' => $stored->getUri()]);
} }
static function byEventAndActor(Happening $event, Profile $actor) public static function byEventAndActor(Happening $event, Profile $actor)
{ {
return self::getByKeys(['event_uri' => $event->getUri(), return self::getByKeys(['event_uri' => $event->getUri(),
'profile_id' => $actor->getID()]); 'profile_id' => $actor->getID()]);
} }
static function forEvent(Happening $event) public static function forEvent(Happening $event)
{ {
$keypart = sprintf('rsvp:for-event:%s', $event->getUri()); $keypart = sprintf('rsvp:for-event:%s', $event->getUri());
@ -287,31 +284,35 @@ class RSVP extends Managed_DataObject
return $rsvps; return $rsvps;
} }
function getProfile() public function getProfile()
{ {
return Profile::getByID($this->profile_id); return Profile::getByID($this->profile_id);
} }
function getEvent() public function getEvent()
{ {
return Happening::getByKeys(['uri' => $this->getEventUri()]); return Happening::getByKeys(['uri' => $this->getEventUri()]);
} }
function asHTML() public function asHTML()
{ {
return self::toHTML($this->getProfile(), return self::toHTML(
$this->getProfile(),
$this->getEvent(), $this->getEvent(),
$this->response); $this->response
);
} }
function asString() public function asString()
{ {
return self::toString($this->getProfile(), return self::toString(
$this->getProfile(),
$this->getEvent(), $this->getEvent(),
$this->response); $this->response
);
} }
static function toHTML(Profile $profile, Happening $event, $response) public static function toHTML(Profile $profile, Happening $event, $response)
{ {
$fmt = null; $fmt = null;
@ -350,14 +351,16 @@ class RSVP extends Managed_DataObject
$eventTitle = $event->title; $eventTitle = $event->title;
} }
return sprintf($fmt, return sprintf(
$fmt,
htmlspecialchars($profile->getUrl()), htmlspecialchars($profile->getUrl()),
htmlspecialchars($profile->getBestName()), htmlspecialchars($profile->getBestName()),
htmlspecialchars($eventUrl), htmlspecialchars($eventUrl),
htmlspecialchars($eventTitle)); htmlspecialchars($eventTitle)
);
} }
static function toString($profile, $event, $response) public static function toString($profile, $event, $response)
{ {
$fmt = null; $fmt = null;
@ -392,9 +395,11 @@ class RSVP extends Managed_DataObject
$eventTitle = $event->title; $eventTitle = $event->title;
} }
return sprintf($fmt, return sprintf(
$fmt,
$profile->getBestName(), $profile->getBestName(),
$eventTitle); $eventTitle
);
} }
public function delete($useWhere=false) public function delete($useWhere=false)

View File

@ -1,25 +1,25 @@
<?php <?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 * @copyright 1012 StatusNet, Inc.
* Copyright (C) 2011, StatusNet, Inc. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* 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/>.
*/ */
if (!defined('STATUSNET')) { defined('GNUSOCIAL') || die();
exit(1);
}
/** /**
* DataObject class to store extended profile fields. Allows for storing * DataObject class to store extended profile fields. Allows for storing
@ -98,7 +98,7 @@ class Profile_detail extends Managed_DataObject
], ],
'primary key' => ['id'], 'primary key' => ['id'],
'unique keys' => [ 'unique keys' => [
'profile_detail_profile_id_field_name_value_index' => ['profile_id', 'field_name', 'value_index'] 'profile_detail_profile_id_field_name_value_index_key' => ['profile_id', 'field_name', 'value_index']
], ],
]; ];
} }

View File

@ -48,36 +48,49 @@ class ModLog extends Managed_DataObject
*/ */
public static function schemaDef() public static function schemaDef()
{ {
return array('description' => 'Log of moderation events', return [
'fields' => array( 'description' => 'Log of moderation events',
'id' => array('type' => 'varchar', 'fields' => [
'id' => [
'type' => 'varchar',
'length' => 36, 'length' => 36,
'not null' => true, 'not null' => true,
'description' => 'unique event ID'), 'description' => 'unique event ID',
'profile_id' => array('type' => 'int', ],
'profile_id' => [
'type' => 'int',
'not null' => true, 'not null' => true,
'description' => 'profile getting the role'), 'description' => 'profile getting the role',
'moderator_id' => array('type' => 'int', ],
'description' => 'profile granting or revoking the role'), 'moderator_id' => [
'role' => array('type' => 'varchar', 'type' => 'int',
'description' => 'profile granting or revoking the role',
],
'role' => [
'type' => 'varchar',
'length' => 32, 'length' => 32,
'not null' => true, 'not null' => true,
'description' => 'role granted or revoked'), 'description' => 'role granted or revoked',
'is_grant' => array('type' => 'bool', ],
'is_grant' => [
'type' => 'bool',
'default' => true, 'default' => true,
'description' => 'Was this a grant or revocation of a role'), 'description' => 'Was this a grant or revocation of a role',
'created' => array('type' => 'datetime', ],
'created' => [
'type' => 'datetime',
'not null' => true, 'not null' => true,
'description' => 'date this record was created') 'description' => 'date this record was created',
), ],
'primary key' => array('id'), ],
'foreign keys' => array( 'primary key' => ['id'],
'mod_log_profile_id_fkey' => array('profile', array('profile_id' => 'id')), 'foreign keys' => [
'mod_log_moderator_id_fkey' => array('user', array('moderator_id' => 'id')) 'modlog_profile_id_fkey' => ['profile', ['profile_id' => 'id']],
), 'modlog_moderator_id_fkey' => ['user', ['moderator_id' => 'id']],
'indexes' => array( ],
'mod_log_profile_id_created_idx' => array('profile_id', 'created'), 'indexes' => [
), 'modlog_profile_id_created_idx' => ['profile_id', 'created'],
); ],
];
} }
} }

View File

@ -53,9 +53,6 @@ class Usage_stats extends Managed_DataObject
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'], 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
], ],
'primary key' => ['type'], 'primary key' => ['type'],
'indexes' => [
'user_stats_idx' => ['type'],
],
]; ];
} }

View File

@ -1,45 +1,38 @@
<?php <?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
* Copyright (C) 2012, StatusNet, Inc.
*
* User_openid_prefs.php * User_openid_prefs.php
* *
* PHP version 5
*
* 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 OpenID * @category OpenID
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2012 StatusNet, Inc. * @copyright 2012 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
if (!defined('STATUSNET')) { defined('GNUSOCIAL') || die();
exit(1);
}
/** /**
* Store preferences for OpenID use in StatusNet * Store preferences for OpenID use in StatusNet
* *
* @category OpenID * @category OpenID
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
* *
* @see DB_DataObject * @see DB_DataObject
*/ */
@ -85,9 +78,9 @@ class User_openid_prefs extends Managed_DataObject
], ],
], ],
'primary key' => ['user_id'], 'primary key' => ['user_id'],
'foreign keys' => ['user_openid_prefs_user_id_fkey' => ['user', ['user_id' => 'id']], 'foreign keys' => [
'user_openid_prefs_user_id_fkey' => ['user', ['user_id' => 'id']],
], ],
'indexes' => [],
]; ];
} }
} }

View File

@ -20,7 +20,7 @@
* @category PollPlugin * @category PollPlugin
* @package GNUsocial * @package GNUsocial
* @author Brion Vibber <brion@status.net> * @author Brion Vibber <brion@status.net>
* @copyright 2011, StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
@ -29,7 +29,7 @@ defined('GNUSOCIAL') || die();
/** /**
* For storing the poll options and such * For storing the poll options and such
* *
* @copyright 2011, StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* *
* @see DB_DataObject * @see DB_DataObject
@ -65,7 +65,7 @@ class Poll_response extends Managed_DataObject
'poll_response_poll_id_profile_id_key' => array('poll_id', 'profile_id'), 'poll_response_poll_id_profile_id_key' => array('poll_id', 'profile_id'),
), ),
'indexes' => array( 'indexes' => array(
'poll_response_profile_id_poll_id_index' => array('profile_id', 'poll_id'), 'poll_response_profile_id_poll_id_idx' => array('profile_id', 'poll_id'),
) )
); );
} }

View File

@ -60,7 +60,7 @@ class SearchSub extends Managed_DataObject
), ),
'indexes' => array( 'indexes' => array(
'searchsub_created_idx' => array('created'), 'searchsub_created_idx' => array('created'),
'searchsub_profile_id_tag_idx' => array('profile_id', 'search'), 'searchsub_profile_id_search_idx' => array('profile_id', 'search'),
), ),
); );
} }

View File

@ -64,7 +64,7 @@ class Notice_to_status extends Managed_DataObject
), ),
'primary key' => array('notice_id'), 'primary key' => array('notice_id'),
'unique keys' => array( 'unique keys' => array(
'status_id_key' => array('status_id'), 'notice_to_status_status_id_key' => array('status_id'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'notice_to_status_notice_id_fkey' => array('notice', array('notice_id' => 'id')), 'notice_to_status_notice_id_fkey' => array('notice', array('notice_id' => 'id')),