[DATABASE] Set all primary keys as "not null" explicitly

This commit is contained in:
Alexei Sorokin 2019-09-11 12:27:40 +03:00
parent 95c7344557
commit af63e9a7ad
4 changed files with 117 additions and 83 deletions

View File

@ -1,28 +1,29 @@
<?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) 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/>.
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Table Definition for file_thumbnail
*/
class File_thumbnail extends Managed_DataObject
{
public $__table = 'file_thumbnail'; // table name
@ -44,8 +45,8 @@ class File_thumbnail extends Managed_DataObject
'urlhash' => array('type' => 'varchar', 'length' => 64, 'description' => 'sha256 of url field if non-empty'),
'url' => array('type' => 'text', 'description' => 'URL of thumbnail'),
'filename' => array('type' => 'text', 'description' => 'if stored locally, filename is put here'),
'width' => array('type' => 'int', 'description' => 'width of thumbnail'),
'height' => array('type' => 'int', 'description' => 'height of thumbnail'),
'width' => array('type' => 'int', 'not null' => true, 'description' => 'width of thumbnail'),
'height' => array('type' => 'int', 'not null' => true, 'description' => 'height of thumbnail'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
),
'primary key' => array('file_id', 'width', 'height'),
@ -65,21 +66,26 @@ class File_thumbnail extends Managed_DataObject
* @param object $data
* @param int $file_id
*/
public static function saveNew($data, $file_id) {
public static function saveNew($data, $file_id)
{
if (!empty($data->thumbnail_url)) {
// Non-photo types such as video will usually
// show us a thumbnail, though it's not required.
self::saveThumbnail($file_id,
self::saveThumbnail(
$file_id,
$data->thumbnail_url,
$data->thumbnail_width,
$data->thumbnail_height);
$data->thumbnail_height
);
} elseif ($data->type == 'photo') {
// The inline photo URL given should also fit within
// our requested thumbnail size, per oEmbed spec.
self::saveThumbnail($file_id,
self::saveThumbnail(
$file_id,
$data->url,
$data->width,
$data->height);
$data->height
);
}
}
@ -92,7 +98,8 @@ class File_thumbnail extends Managed_DataObject
* @return File_thumbnail
* @throws NoResultException if no File_thumbnail matched the criteria
*/
static function byFile(File $file, $notNullUrl=true) {
public static function byFile(File $file, $notNullUrl = true)
{
$thumb = new File_thumbnail();
$thumb->file_id = $file->getID();
if ($notNullUrl) {
@ -116,7 +123,7 @@ class File_thumbnail extends Managed_DataObject
* @param int $width
* @param int $height
*/
static function saveThumbnail($file_id, $url, $width, $height, $filename=null)
public static function saveThumbnail($file_id, $url, $width, $height, $filename = null)
{
$tn = new File_thumbnail;
$tn->file_id = $file_id;
@ -128,7 +135,7 @@ class File_thumbnail extends Managed_DataObject
return $tn;
}
static function path($filename)
public static function path($filename)
{
File::tryFilename($filename);
@ -142,7 +149,7 @@ class File_thumbnail extends Managed_DataObject
return $dir . $filename;
}
static function url($filename)
public static function url($filename)
{
File::tryFilename($filename);
@ -276,7 +283,7 @@ class File_thumbnail extends Managed_DataObject
return $this->file_id;
}
static public function hashurl($url)
public static function hashurl($url)
{
if (!mb_strlen($url)) {
throw new Exception('No URL provided to hash algorithm.');

View File

@ -1,4 +1,21 @@
<?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/>.
defined('GNUSOCIAL') || die();
/**
* Table Definition for request_queue
*/
@ -23,7 +40,7 @@ class Group_join_queue extends Managed_DataObject
'description' => 'Holder for group join requests awaiting moderation.',
'fields' => array(
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
'group_id' => array('type' => 'int', 'description' => 'remote or local group to join, if any'),
'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local group to join, if any'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
),
'primary key' => array('profile_id', 'group_id'),
@ -48,7 +65,7 @@ class Group_join_queue extends Managed_DataObject
return $rq;
}
function getMember()
public function getMember()
{
$member = Profile::getKV('id', $this->profile_id);
@ -61,7 +78,7 @@ class Group_join_queue extends Managed_DataObject
return $member;
}
function getGroup()
public function getGroup()
{
$group = User_group::getKV('id', $this->group_id);
@ -77,7 +94,7 @@ class Group_join_queue extends Managed_DataObject
/**
* Abort the pending group join...
*/
function abort()
public function abort()
{
$profile = $this->getMember();
$group = $this->getGroup();
@ -93,7 +110,7 @@ class Group_join_queue extends Managed_DataObject
*
* @return Group_member object on success
*/
function complete()
public function complete()
{
$join = null;
$profile = $this->getMember();

View File

@ -1,9 +1,26 @@
<?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/>.
defined('GNUSOCIAL') || die();
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
/**
* Table Definition for user_username
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class User_username extends Managed_DataObject
{
###START_AUTOCODE
@ -23,8 +40,8 @@ class User_username extends Managed_DataObject
{
return array(
'fields' => array(
'provider_name' => array('type' => 'varchar', 'length' => 191, 'description' => 'provider name'),
'username' => array('type' => 'varchar', 'length' => 191, 'description' => 'username'),
'provider_name' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'provider name'),
'username' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'username'),
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
@ -46,7 +63,7 @@ class User_username extends Managed_DataObject
* @param provider_name string name of the provider
* @return mixed User_username instance if the registration succeeded, false if it did not
*/
static function register($user, $username, $provider_name)
public static function register($user, $username, $provider_name)
{
$user_username = new User_username();
$user_username->user_id = $user->id;

View File

@ -1,35 +1,30 @@
<?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/>.
/**
* Store last-touched ID for various timelines
*
* PHP version 5
*
* @category Data
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@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) 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/>.
* @copyright 2010 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 INSTALLDIR . '/classes/Memcached_DataObject.php';
@ -41,10 +36,8 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
* around, we use that ID in the since_id parameter.
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @copyright 2010 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see DB_DataObject
*/
@ -62,7 +55,7 @@ class Twitter_synch_status extends Managed_DataObject
return array(
'fields' => array(
'foreign_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'Foreign message ID'),
'timeline' => array('type' => 'varchar', 'length' => 191, 'description' => 'timeline name'),
'timeline' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'timeline name'),
'last_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'last id fetched'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
@ -71,7 +64,7 @@ class Twitter_synch_status extends Managed_DataObject
);
}
static function getLastId($foreign_id, $timeline)
public static function getLastId($foreign_id, $timeline)
{
$tss = self::pkeyGet(array('foreign_id' => $foreign_id,
'timeline' => $timeline));
@ -83,7 +76,7 @@ class Twitter_synch_status extends Managed_DataObject
}
}
static function setLastId($foreign_id, $timeline, $last_id)
public static function setLastId($foreign_id, $timeline, $last_id)
{
$tss = self::pkeyGet(array('foreign_id' => $foreign_id,
'timeline' => $timeline));