Preparations for "featured" posts
This commit is contained in:
parent
29f65d250f
commit
a1dd299eb3
17
database.sql
17
database.sql
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2022.05-dev (Siberian Iris)
|
||||
-- DB_UPDATE_VERSION 1455
|
||||
-- DB_UPDATE_VERSION 1456
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -1062,6 +1062,17 @@ CREATE TABLE IF NOT EXISTS `post-category` (
|
|||
FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
|
||||
|
||||
--
|
||||
-- TABLE post-collection
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS `post-collection` (
|
||||
`uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
|
||||
`type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
|
||||
PRIMARY KEY(`uri-id`,`type`),
|
||||
INDEX `type` (`type`),
|
||||
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Collection of posts';
|
||||
|
||||
--
|
||||
-- TABLE post-content
|
||||
--
|
||||
|
@ -1617,6 +1628,7 @@ CREATE VIEW `post-user-view` AS SELECT
|
|||
`post-thread-user`.`origin` AS `parent-origin`,
|
||||
`post-thread-user`.`mention` AS `mention`,
|
||||
`post-user`.`global` AS `global`,
|
||||
EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-user`.`uri-id`) AS `featured`,
|
||||
`post-user`.`network` AS `network`,
|
||||
`post-user`.`vid` AS `vid`,
|
||||
`post-user`.`psid` AS `psid`,
|
||||
|
@ -1777,6 +1789,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
|
|||
`post-thread-user`.`origin` AS `origin`,
|
||||
`post-thread-user`.`mention` AS `mention`,
|
||||
`post-user`.`global` AS `global`,
|
||||
EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread-user`.`uri-id`) AS `featured`,
|
||||
`post-thread-user`.`network` AS `network`,
|
||||
`post-user`.`vid` AS `vid`,
|
||||
`post-thread-user`.`psid` AS `psid`,
|
||||
|
@ -1923,6 +1936,7 @@ CREATE VIEW `post-view` AS SELECT
|
|||
`post`.`visible` AS `visible`,
|
||||
`post`.`deleted` AS `deleted`,
|
||||
`post`.`global` AS `global`,
|
||||
EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post`.`uri-id`) AS `featured`,
|
||||
`post`.`network` AS `network`,
|
||||
`post`.`vid` AS `vid`,
|
||||
IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
|
||||
|
@ -2044,6 +2058,7 @@ CREATE VIEW `post-thread-view` AS SELECT
|
|||
`post`.`visible` AS `visible`,
|
||||
`post`.`deleted` AS `deleted`,
|
||||
`post`.`global` AS `global`,
|
||||
EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread`.`uri-id`) AS `featured`,
|
||||
`post-thread`.`network` AS `network`,
|
||||
`post`.`vid` AS `vid`,
|
||||
IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
|
||||
|
|
|
@ -47,6 +47,7 @@ Database Tables
|
|||
| [photo](help/database/db_photo) | photo storage |
|
||||
| [post](help/database/db_post) | Structure for all posts |
|
||||
| [post-category](help/database/db_post-category) | post relation to categories |
|
||||
| [post-collection](help/database/db_post-collection) | Collection of posts |
|
||||
| [post-content](help/database/db_post-content) | Content for all posts |
|
||||
| [post-delivery-data](help/database/db_post-delivery-data) | Delivery data for items |
|
||||
| [post-link](help/database/db_post-link) | Post related external links |
|
||||
|
|
29
doc/database/db_post-collection.md
Normal file
29
doc/database/db_post-collection.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
Table post-collection
|
||||
===========
|
||||
|
||||
Collection of posts
|
||||
|
||||
Fields
|
||||
------
|
||||
|
||||
| Field | Description | Type | Null | Key | Default | Extra |
|
||||
| ------ | --------------------------------------------------------- | ---------------- | ---- | --- | ------- | ----- |
|
||||
| uri-id | Id of the item-uri table entry that contains the item uri | int unsigned | NO | PRI | NULL | |
|
||||
| type | | tinyint unsigned | NO | PRI | 0 | |
|
||||
|
||||
Indexes
|
||||
------------
|
||||
|
||||
| Name | Fields |
|
||||
| ------- | ------------ |
|
||||
| PRIMARY | uri-id, type |
|
||||
| type | type |
|
||||
|
||||
Foreign Keys
|
||||
------------
|
||||
|
||||
| Field | Target Table | Target Field |
|
||||
|-------|--------------|--------------|
|
||||
| uri-id | [item-uri](help/database/db_item-uri) | id |
|
||||
|
||||
Return to [database documentation](help/database)
|
|
@ -39,7 +39,6 @@ use Friendica\Util\DateTimeFormat;
|
|||
use Friendica\Util\HTTPSignature;
|
||||
use Friendica\Util\JsonLD;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class APContact
|
||||
{
|
||||
|
|
61
src/Model/Post/Collection.php
Normal file
61
src/Model/Post/Collection.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Model\Post;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
use \BadMethodCallException;
|
||||
use Friendica\Database\Database;
|
||||
|
||||
class Collection
|
||||
{
|
||||
const FEATURED = 0;
|
||||
|
||||
/**
|
||||
* Add a post to a collection
|
||||
*
|
||||
* @param integer $uri_id
|
||||
* @param integer $type
|
||||
*/
|
||||
public static function add(int $uri_id, int $type)
|
||||
{
|
||||
if (empty($uri_id)) {
|
||||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
DBA::insert('post-collection', ['uri-id' => $uri_id, 'type' => $type], Database::INSERT_IGNORE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a post from a collection
|
||||
*
|
||||
* @param integer $uri_id
|
||||
* @param integer $type
|
||||
*/
|
||||
public static function remove(int $uri_id, int $type)
|
||||
{
|
||||
if (empty($uri_id)) {
|
||||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
DBA::delete('post-collection', ['uri-id' => $uri_id, 'type' => $type]);
|
||||
}
|
||||
}
|
|
@ -492,7 +492,7 @@ class Processor
|
|||
|
||||
Logger::debug('Add post to featured collection', ['uri-id' => $uriid]);
|
||||
|
||||
// @todo Add functionality
|
||||
Post\Collection::add($uriid, Post\Collection::FEATURED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -509,7 +509,7 @@ class Processor
|
|||
|
||||
Logger::debug('Remove post from featured collection', ['uri-id' => $uriid]);
|
||||
|
||||
// @todo Add functionality
|
||||
Post\Collection::remove($uriid, Post\Collection::FEATURED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1455);
|
||||
define('DB_UPDATE_VERSION', 1456);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -1103,6 +1103,17 @@ return [
|
|||
"uid" => ["uid"],
|
||||
]
|
||||
],
|
||||
"post-collection" => [
|
||||
"comment" => "Collection of posts",
|
||||
"fields" => [
|
||||
"uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
|
||||
"type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "comment" => ""],
|
||||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["uri-id", "type"],
|
||||
"type" => ["type"],
|
||||
]
|
||||
],
|
||||
"post-content" => [
|
||||
"comment" => "Content for all posts",
|
||||
"fields" => [
|
||||
|
|
|
@ -93,6 +93,7 @@
|
|||
"parent-origin" => ["post-thread-user", "origin"],
|
||||
"mention" => ["post-thread-user", "mention"],
|
||||
"global" => ["post-user", "global"],
|
||||
"featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-user`.`uri-id`)",
|
||||
"network" => ["post-user", "network"],
|
||||
"vid" => ["post-user", "vid"],
|
||||
"psid" => ["post-user", "psid"],
|
||||
|
@ -251,6 +252,7 @@
|
|||
"origin" => ["post-thread-user", "origin"],
|
||||
"mention" => ["post-thread-user", "mention"],
|
||||
"global" => ["post-user", "global"],
|
||||
"featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread-user`.`uri-id`)",
|
||||
"network" => ["post-thread-user", "network"],
|
||||
"vid" => ["post-user", "vid"],
|
||||
"psid" => ["post-thread-user", "psid"],
|
||||
|
@ -395,6 +397,7 @@
|
|||
"visible" => ["post", "visible"],
|
||||
"deleted" => ["post", "deleted"],
|
||||
"global" => ["post", "global"],
|
||||
"featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post`.`uri-id`)",
|
||||
"network" => ["post", "network"],
|
||||
"vid" => ["post", "vid"],
|
||||
"verb" => "IF (`post`.`vid` IS NULL, '', `verb`.`name`)",
|
||||
|
@ -514,6 +517,7 @@
|
|||
"visible" => ["post", "visible"],
|
||||
"deleted" => ["post", "deleted"],
|
||||
"global" => ["post", "global"],
|
||||
"featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread`.`uri-id`)",
|
||||
"network" => ["post-thread", "network"],
|
||||
"vid" => ["post", "vid"],
|
||||
"verb" => "IF (`post`.`vid` IS NULL, '', `verb`.`name`)",
|
||||
|
|
Loading…
Reference in a new issue