1
0
Fork 0

New item field "Post-type" and new table "permissionset" (#5408)

* "post-type" replaces "bookmark" and "type"

* Removed some more type

* Added index to permission set

* The permission set is now stored

* The permission set is now removed upon expiry

* Post update now stores the permission set

* New file

* Permissions are now sorted

* Changed documentation
This commit is contained in:
Michael Vogel 2018-07-19 15:52:05 +02:00 committed by Hypolite Petovan
commit 5af9596dde
29 changed files with 222 additions and 145 deletions

View file

@ -1174,9 +1174,9 @@ class DBStructure
"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"],
"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" => ""],
"private" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "distribution is restricted"],
"bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been bookmarked"],
"visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been deleted"],
@ -1190,22 +1190,23 @@ class DBStructure
"unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
"mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"],
"forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
// User specific fields. Should possible be replaced with something different
"psid" => ["type" => "int unsigned", "relation" => ["permissionset" => "id"], "comment" => "ID of the permission set of this post"],
// These fields will be replaced by the "psid" from above
"allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
"allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
"deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
"deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
// These fields will be moved into some item-delivery-information table
"postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
"inform" => ["type" => "mediumtext", "comment" => "Additional receivers of this post"],
// It is to be decided whether these fields belong to the user or the structure
"resource-id" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type"],
"event-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
// Will be replaced by the "attach" table
// Could possibly be replaced by the "attach" table?
"attach" => ["type" => "mediumtext", "comment" => "JSON structure representing attachments to this item"],
// Seems to be only used for notes, but is filled at many places.
// Will be replaced with some general field that contain the values of "origin" and "wall" as well.
"type" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""],
// Deprecated fields. Will be removed in upcoming versions
"type" => ["type" => "varchar(20)", "comment" => "Deprecated"],
"bookmark" => ["type" => "boolean", "comment" => "Deprecated"],
"file" => ["type" => "mediumtext", "comment" => "Deprecated"],
"location" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"coord" => ["type" => "varchar(255)", "comment" => "Deprecated"],
@ -1255,6 +1256,7 @@ class DBStructure
"uid_eventid" => ["uid","event-id"],
"icid" => ["icid"],
"iaid" => ["iaid"],
"psid" => ["psid"],
]
];
$database["item-activity"] = [
@ -1485,6 +1487,21 @@ class DBStructure
"uid_cat_k" => ["UNIQUE", "uid", "cat", "k"],
]
];
$database["permissionset"] = [
"comment" => "",
"fields" => [
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id of this permission set"],
"allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
"allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
"deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
"deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
],
"indexes" => [
"PRIMARY" => ["id"],
"uid_allow_cid_allow_gid_deny_cid_deny_gid" => ["allow_cid(50)", "allow_gid(30)", "deny_cid(50)", "deny_gid(30)"],
]
];
$database["photo"] = [
"comment" => "photo storage",
"fields" => [
@ -1768,13 +1785,14 @@ class DBStructure
"visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"ignored" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
"unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
"deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
"bookmark" => ["type" => "boolean", "comment" => ""],
],
"indexes" => [
"PRIMARY" => ["iid"],

View file

@ -8,6 +8,7 @@ use Friendica\Core\Config;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\PermissionSet;
use dba;
require_once 'include/dba.php';
@ -31,7 +32,7 @@ class PostUpdate
if (!self::update1206()) {
return;
}
if (!self::update1276()) {
if (!self::update1278()) {
return;
}
}
@ -227,19 +228,20 @@ class PostUpdate
*
* @return bool "true" when the job is done
*/
private static function update1276()
private static function update1278()
{
// Was the script completed?
if (Config::get("system", "post_update_version") >= 1276) {
if (Config::get("system", "post_update_version") >= 1278) {
return true;
}
$id = Config::get("system", "post_update_version_1276_id", 0);
$id = Config::get("system", "post_update_version_1278_id", 0);
logger("Start from item " . $id, LOGGER_DEBUG);
$fields = array_merge(Item::MIXED_CONTENT_FIELDLIST, ['network', 'author-id', 'owner-id', 'tag', 'file',
'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'id']);
'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'id',
'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'psid', 'post-type', 'bookmark', 'type']);
$start_id = $id;
$rows = 0;
@ -263,18 +265,32 @@ class PostUpdate
$item['owner-id'] = Contact::getIdForURL($item["owner-link"], 0, false, $default);
}
if (empty($item['psid'])) {
$item['psid'] = PermissionSet::fetchIDForPost($item);
}
if ($item['post-type'] == 0) {
if (!empty($item['type']) && ($item['type'] == 'note')) {
$item['post-type'] = Item::PT_PERSONAL_NOTE;
} elseif (!empty($item['type']) && ($item['type'] == 'photo')) {
$item['post-type'] = Item::PT_IMAGE;
} elseif (!empty($item['bookmark']) && $item['bookmark']) {
$item['post-type'] = Item::PT_PAGE;
}
}
Item::update($item, ['id' => $id]);
++$rows;
}
dba::close($items);
Config::set("system", "post_update_version_1276_id", $id);
Config::set("system", "post_update_version_1278_id", $id);
logger("Processed rows: " . $rows . " - last processed item: " . $id, LOGGER_DEBUG);
if ($start_id == $id) {
Config::set("system", "post_update_version", 1276);
Config::set("system", "post_update_version", 1278);
logger("Done", LOGGER_DEBUG);
return true;
}