Merge pull request #8615 from annando/verb
We now store verbs in a new side table
This commit is contained in:
commit
1e53f28b18
6 changed files with 143 additions and 3 deletions
12
database.sql
12
database.sql
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2020.06-dev (Red Hot Poker)
|
||||
-- DB_UPDATE_VERSION 1346
|
||||
-- DB_UPDATE_VERSION 1347
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -589,6 +589,7 @@ CREATE TABLE IF NOT EXISTS `item` (
|
|||
`author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
|
||||
`icid` int unsigned COMMENT 'Id of the item-content table entry that contains the whole item content',
|
||||
`iaid` int unsigned COMMENT 'Id of the item-activity table entry that contains the activity data',
|
||||
`vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
|
||||
`extid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||
`post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
|
||||
`global` boolean NOT NULL DEFAULT '0' COMMENT '',
|
||||
|
@ -1362,6 +1363,15 @@ CREATE TABLE IF NOT EXISTS `user-item` (
|
|||
INDEX `iid_uid` (`iid`,`uid`)
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data';
|
||||
|
||||
--
|
||||
-- TABLE verb
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS `verb` (
|
||||
`id` int unsigned NOT NULL auto_increment,
|
||||
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '',
|
||||
PRIMARY KEY(`id`)
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Activity Verbs';
|
||||
|
||||
--
|
||||
-- TABLE worker-ipc
|
||||
--
|
||||
|
|
|
@ -32,6 +32,7 @@ use Friendica\Model\Post\Category;
|
|||
use Friendica\Model\Tag;
|
||||
use Friendica\Model\Term;
|
||||
use Friendica\Model\UserItem;
|
||||
use Friendica\Model\Verb;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
/**
|
||||
|
@ -80,6 +81,9 @@ class PostUpdate
|
|||
if (!self::update1346()) {
|
||||
return false;
|
||||
}
|
||||
if (!self::update1347()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -787,5 +791,56 @@ class PostUpdate
|
|||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* update the "vid" (verb) field in the item table
|
||||
*
|
||||
* @return bool "true" when the job is done
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
private static function update1347()
|
||||
{
|
||||
// Was the script completed?
|
||||
if (DI::config()->get("system", "post_update_version") >= 1347) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$id = DI::config()->get("system", "post_update_version_1347_id", 0);
|
||||
|
||||
Logger::info('Start', ['item' => $id]);
|
||||
|
||||
$start_id = $id;
|
||||
$rows = 0;
|
||||
$condition = ["`id` > ? AND `vid` IS NULL", $id];
|
||||
$params = ['order' => ['id'], 'limit' => 10000];
|
||||
$items = Item::select(['id', 'verb'], $condition, $params);
|
||||
|
||||
if (DBA::errorNo() != 0) {
|
||||
Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
|
||||
return false;
|
||||
}
|
||||
|
||||
while ($item = Item::fetch($items)) {
|
||||
$id = $item['id'];
|
||||
|
||||
DBA::update('item', ['vid' => Verb::getID($item['verb'])], ['id' => $item['id']]);
|
||||
|
||||
++$rows;
|
||||
}
|
||||
DBA::close($items);
|
||||
|
||||
DI::config()->set("system", "post_update_version_1347_id", $id);
|
||||
|
||||
Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
|
||||
|
||||
if ($start_id == $id) {
|
||||
DI::config()->set("system", "post_update_version", 1347);
|
||||
Logger::info('Done');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1505,6 +1505,10 @@ class Item
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (empty($item['vid']) && !empty($item['verb'])) {
|
||||
$item['vid'] = Verb::getID($item['verb']);
|
||||
}
|
||||
|
||||
self::addLanguageToItemArray($item);
|
||||
|
||||
// Items cannot be stored before they happen ...
|
||||
|
|
51
src/Model/Verb.php
Normal file
51
src/Model/Verb.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @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;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
|
||||
class Verb
|
||||
{
|
||||
/**
|
||||
* Insert a verb record and return its id
|
||||
*
|
||||
* @param string $verb
|
||||
*
|
||||
* @return integer verb id
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getID($verb)
|
||||
{
|
||||
if (empty($verb)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$verb_record = DBA::selectFirst('verb', ['id'], ['name' => $verb]);
|
||||
if (DBA::isResult($verb_record)) {
|
||||
return $verb_record['id'];
|
||||
}
|
||||
|
||||
DBA::insert('verb', ['name' => $verb], true);
|
||||
|
||||
return DBA::lastInsertId();
|
||||
}
|
||||
}
|
|
@ -51,7 +51,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1346);
|
||||
define('DB_UPDATE_VERSION', 1347);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -670,6 +670,7 @@ return [
|
|||
"author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Link to the contact table with uid=0 of the author of this item"],
|
||||
"icid" => ["type" => "int unsigned", "relation" => ["item-content" => "id"], "comment" => "Id of the item-content table entry that contains the whole item content"],
|
||||
"iaid" => ["type" => "int unsigned", "relation" => ["item-activity" => "id"], "comment" => "Id of the item-activity table entry that contains the activity data"],
|
||||
"vid" => ["type" => "smallint unsigned", "relation" => ["verb" => "id"], "comment" => "Id of the verb table entry that contains the activity verbs"],
|
||||
"extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
|
||||
"global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
|
||||
|
@ -1489,6 +1490,16 @@ return [
|
|||
"iid_uid" => ["iid", "uid"]
|
||||
]
|
||||
],
|
||||
"verb" => [
|
||||
"comment" => "Activity Verbs",
|
||||
"fields" => [
|
||||
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"],
|
||||
"name" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => ""]
|
||||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["id"]
|
||||
]
|
||||
],
|
||||
"worker-ipc" => [
|
||||
"comment" => "Inter process communication between the frontend and the worker",
|
||||
"fields" => [
|
||||
|
|
|
@ -422,3 +422,12 @@ function update_1332()
|
|||
|
||||
return Update::SUCCESS;
|
||||
}
|
||||
|
||||
function update_1347()
|
||||
{
|
||||
foreach (Item::ACTIVITIES as $index => $activity) {
|
||||
DBA::insert('verb', ['id' => $index + 1, 'name' => $activity], true);
|
||||
}
|
||||
|
||||
return Update::SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue