Fix code style

This commit is contained in:
Art4 2025-01-13 13:31:54 +00:00
parent d4697a17a3
commit 0e59dba914
102 changed files with 3038 additions and 2764 deletions

View file

@ -73,8 +73,11 @@ class DBStructure
'deliverq', 'dsprphotoq', 'ffinder', 'sign', 'spam', 'term', 'user-item', 'thread', 'item', 'challenge',
'auth_codes', 'tokens', 'clients', 'profile_check', 'host', 'conversation', 'fcontact', 'addon', 'push_subscriber'];
$tables = DBA::selectToArray('INFORMATION_SCHEMA.TABLES', ['TABLE_NAME'],
['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_TYPE' => 'BASE TABLE']);
$tables = DBA::selectToArray(
'INFORMATION_SCHEMA.TABLES',
['TABLE_NAME'],
['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_TYPE' => 'BASE TABLE']
);
if (empty($tables)) {
echo DI::l10n()->t('No unused tables found.');
@ -143,8 +146,11 @@ class DBStructure
*/
private static function printUpdateError(string $message): string
{
echo DI::l10n()->t("\nError %d occurred during database update:\n%s\n",
DBA::errorNo(), DBA::errorMessage());
echo DI::l10n()->t(
"\nError %d occurred during database update:\n%s\n",
DBA::errorNo(),
DBA::errorMessage()
);
return DI::l10n()->t('Errors encountered performing database changes: ') . $message . '<br />';
}
@ -522,30 +528,36 @@ class DBStructure
// This query doesn't seem to be executable as a prepared statement
$indexes = DBA::toArray(DBA::p("SHOW INDEX FROM " . DBA::quoteIdentifier($table)));
$fields = DBA::selectToArray('INFORMATION_SCHEMA.COLUMNS',
$fields = DBA::selectToArray(
'INFORMATION_SCHEMA.COLUMNS',
['COLUMN_NAME', 'COLUMN_TYPE', 'IS_NULLABLE', 'COLUMN_DEFAULT', 'EXTRA',
'COLUMN_KEY', 'COLLATION_NAME', 'COLUMN_COMMENT'],
'COLUMN_KEY', 'COLLATION_NAME', 'COLUMN_COMMENT'],
["`TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?",
DBA::databaseName(), $table]);
DBA::databaseName(), $table]
);
$foreign_keys = DBA::selectToArray('INFORMATION_SCHEMA.KEY_COLUMN_USAGE',
$foreign_keys = DBA::selectToArray(
'INFORMATION_SCHEMA.KEY_COLUMN_USAGE',
['COLUMN_NAME', 'CONSTRAINT_NAME', 'REFERENCED_TABLE_NAME', 'REFERENCED_COLUMN_NAME'],
["`TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? AND `REFERENCED_TABLE_SCHEMA` IS NOT NULL",
DBA::databaseName(), $table]);
DBA::databaseName(), $table]
);
$table_status = DBA::selectFirst('INFORMATION_SCHEMA.TABLES',
$table_status = DBA::selectFirst(
'INFORMATION_SCHEMA.TABLES',
['ENGINE', 'TABLE_COLLATION', 'TABLE_COMMENT'],
["`TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?",
DBA::databaseName(), $table]);
DBA::databaseName(), $table]
);
$fielddata = [];
$indexdata = [];
$fielddata = [];
$indexdata = [];
$foreigndata = [];
if (DBA::isResult($foreign_keys)) {
foreach ($foreign_keys as $foreign_key) {
$parameters = ['foreign' => [$foreign_key['REFERENCED_TABLE_NAME'] => $foreign_key['REFERENCED_COLUMN_NAME']]];
$constraint = self::getConstraintName($table, $foreign_key['COLUMN_NAME'], $parameters);
$parameters = ['foreign' => [$foreign_key['REFERENCED_TABLE_NAME'] => $foreign_key['REFERENCED_COLUMN_NAME']]];
$constraint = self::getConstraintName($table, $foreign_key['COLUMN_NAME'], $parameters);
$foreigndata[$constraint] = $foreign_key;
}
}
@ -573,8 +585,8 @@ class DBStructure
$fielddata = [];
if (DBA::isResult($fields)) {
foreach ($fields as $field) {
$search = ['tinyint(1)', 'tinyint(3) unsigned', 'tinyint(4)', 'smallint(5) unsigned', 'smallint(6)', 'mediumint(8) unsigned', 'mediumint(9)', 'bigint(20)', 'int(10) unsigned', 'int(11)'];
$replace = ['boolean', 'tinyint unsigned', 'tinyint', 'smallint unsigned', 'smallint', 'mediumint unsigned', 'mediumint', 'bigint', 'int unsigned', 'int'];
$search = ['tinyint(1)', 'tinyint(3) unsigned', 'tinyint(4)', 'smallint(5) unsigned', 'smallint(6)', 'mediumint(8) unsigned', 'mediumint(9)', 'bigint(20)', 'int(10) unsigned', 'int(11)'];
$replace = ['boolean', 'tinyint unsigned', 'tinyint', 'smallint unsigned', 'smallint', 'mediumint unsigned', 'mediumint', 'bigint', 'int unsigned', 'int'];
$field['COLUMN_TYPE'] = str_replace($search, $replace, $field['COLUMN_TYPE']);
$fielddata[$field['COLUMN_NAME']]['type'] = $field['COLUMN_TYPE'];
@ -596,13 +608,13 @@ class DBStructure
}
$fielddata[$field['COLUMN_NAME']]['Collation'] = $field['COLLATION_NAME'];
$fielddata[$field['COLUMN_NAME']]['comment'] = $field['COLUMN_COMMENT'];
$fielddata[$field['COLUMN_NAME']]['comment'] = $field['COLUMN_COMMENT'];
}
}
return [
'fields' => $fielddata,
'indexes' => $indexdata,
'fields' => $fielddata,
'indexes' => $indexdata,
'foreign_keys' => $foreigndata,
'table_status' => $table_status
];
@ -731,9 +743,11 @@ class DBStructure
*/
public static function existsForeignKeyForField(string $table, string $field): bool
{
return DBA::exists('INFORMATION_SCHEMA.KEY_COLUMN_USAGE',
return DBA::exists(
'INFORMATION_SCHEMA.KEY_COLUMN_USAGE',
["`TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? AND `COLUMN_NAME` = ? AND `REFERENCED_TABLE_SCHEMA` IS NOT NULL",
DBA::databaseName(), $table, $field]);
DBA::databaseName(), $table, $field]
);
}
/**
@ -806,8 +820,8 @@ class DBStructure
if (self::existsTable('user') && !DBA::exists('user', ['uid' => 0])) {
$user = [
'verified' => true,
'page-flags' => User::PAGE_FLAGS_SOAPBOX,
'verified' => true,
'page-flags' => User::PAGE_FLAGS_SOAPBOX,
'account-type' => User::ACCOUNT_TYPE_RELAY,
];
DBA::insert('user', $user);
@ -883,7 +897,7 @@ class DBStructure
$permission = '';
}
$fields = ['id' => $set['psid'], 'uid' => $set['uid'], 'allow_cid' => $permission,
'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''];
'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''];
DBA::insert('permissionset', $fields, Database::INSERT_IGNORE);
}
DBA::close($sets);
@ -913,7 +927,7 @@ class DBStructure
$isUpdate = false;
$processes = DBA::select('information_schema.processlist', ['info'], [
'db' => DBA::databaseName(),
'db' => DBA::databaseName(),
'command' => ['Query', 'Execute']
]);

View file

@ -35,7 +35,7 @@ use GuzzleHttp\Psr7\Uri;
class PostUpdate
{
// Needed for the helper function to read from the legacy term table
const OBJECT_TYPE_POST = 1;
const OBJECT_TYPE_POST = 1;
const VERSION = 1550;
@ -138,7 +138,7 @@ class PostUpdate
}
$max_item_delivery_data = DBA::selectFirst('item-delivery-data', ['iid'], ['queue_count > 0 OR queue_done > 0'], ['order' => ['iid']]);
$max_iid = $max_item_delivery_data['iid'] ?? 0;
$max_iid = $max_item_delivery_data['iid'] ?? 0;
DI::logger()->info('Start update1297 with max iid: ' . $max_iid);
@ -174,12 +174,19 @@ class PostUpdate
DI::logger()->info('Start');
$contacts = DBA::p("SELECT `nurl`, `uid` FROM `contact`
$contacts = DBA::p(
"SELECT `nurl`, `uid` FROM `contact`
WHERE EXISTS (SELECT `nurl` FROM `contact` AS `c2`
WHERE `c2`.`nurl` = `contact`.`nurl` AND `c2`.`id` != `contact`.`id` AND `c2`.`uid` = `contact`.`uid` AND `c2`.`network` IN (?, ?, ?) AND NOT `deleted`)
AND (`network` IN (?, ?, ?) OR (`uid` = ?)) AND NOT `deleted` GROUP BY `nurl`, `uid`",
Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB,
Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB, 0);
Protocol::DIASPORA,
Protocol::OSTATUS,
Protocol::ACTIVITYPUB,
Protocol::DIASPORA,
Protocol::OSTATUS,
Protocol::ACTIVITYPUB,
0
);
while ($contact = DBA::fetch($contacts)) {
DI::logger()->info('Remove duplicates', ['nurl' => $contact['nurl'], 'uid' => $contact['uid']]);
@ -216,11 +223,11 @@ class PostUpdate
DI::logger()->info('Start', ['item' => $id]);
$start_id = $id;
$rows = 0;
$start_id = $id;
$rows = 0;
$condition = ["`id` > ?", $id];
$params = ['order' => ['id'], 'limit' => 10000];
$items = DBA::select('item', ['id', 'uri-id', 'uid'], $condition, $params);
$params = ['order' => ['id'], 'limit' => 10000];
$items = DBA::select('item', ['id', 'uri-id', 'uid'], $condition, $params);
if (DBA::errorNo() != 0) {
DI::logger()->error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
@ -331,12 +338,18 @@ class PostUpdate
$rows = 0;
$terms = DBA::p("SELECT `term`.`tid`, `item`.`uri-id`, `term`.`type`, `term`.`term`, `term`.`url`, `item-content`.`body`
$terms = DBA::p(
"SELECT `term`.`tid`, `item`.`uri-id`, `term`.`type`, `term`.`term`, `term`.`url`, `item-content`.`body`
FROM `term`
INNER JOIN `item` ON `item`.`id` = `term`.`oid`
INNER JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id`
WHERE term.type IN (?, ?, ?, ?) AND `tid` >= ? ORDER BY `tid` LIMIT 100000",
Tag::HASHTAG, Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION, $id);
Tag::HASHTAG,
Tag::MENTION,
Tag::EXCLUSIVE_MENTION,
Tag::IMPLICIT_MENTION,
$id
);
if (DBA::errorNo() != 0) {
DI::logger()->error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
@ -345,17 +358,17 @@ class PostUpdate
while ($term = DBA::fetch($terms)) {
if (($term['type'] == Tag::MENTION) && !empty($term['url']) && !strstr($term['body'], $term['url'])) {
$condition = ['nurl' => Strings::normaliseLink($term['url']), 'uid' => 0, 'deleted' => false];
$contact = DBA::selectFirst('contact', ['url', 'alias'], $condition, ['order' => ['id']]);
if (!DBA::isResult($contact)) {
$ssl_url = str_replace('http://', 'https://', $term['url']);
$condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $term['url'], Strings::normaliseLink($term['url']), $ssl_url, 0];
$contact = DBA::selectFirst('contact', ['url', 'alias'], $condition, ['order' => ['id']]);
}
$condition = ['nurl' => Strings::normaliseLink($term['url']), 'uid' => 0, 'deleted' => false];
$contact = DBA::selectFirst('contact', ['url', 'alias'], $condition, ['order' => ['id']]);
if (!DBA::isResult($contact)) {
$ssl_url = str_replace('http://', 'https://', $term['url']);
$condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $term['url'], Strings::normaliseLink($term['url']), $ssl_url, 0];
$contact = DBA::selectFirst('contact', ['url', 'alias'], $condition, ['order' => ['id']]);
}
if (DBA::isResult($contact) && (!strstr($term['body'], $contact['url']) && (empty($contact['alias']) || !strstr($term['body'], $contact['alias'])))) {
$term['type'] = Tag::IMPLICIT_MENTION;
}
if (DBA::isResult($contact) && (!strstr($term['body'], $contact['url']) && (empty($contact['alias']) || !strstr($term['body'], $contact['alias'])))) {
$term['type'] = Tag::IMPLICIT_MENTION;
}
}
Tag::store($term['uri-id'], $term['type'], $term['term'], $term['url']);
@ -454,7 +467,7 @@ class PostUpdate
$file_text = '';
$condition = ['otype' => self::OBJECT_TYPE_POST, 'oid' => $item_id, 'type' => [Category::FILE, Category::CATEGORY]];
$tags = DBA::selectToArray('term', ['type', 'term', 'url'], $condition);
$tags = DBA::selectToArray('term', ['type', 'term', 'url'], $condition);
foreach ($tags as $tag) {
if ($tag['type'] == Category::CATEGORY) {
$file_text .= '<' . $tag['term'] . '>';
@ -490,9 +503,12 @@ class PostUpdate
$rows = 0;
$terms = DBA::select('term', ['oid'],
$terms = DBA::select(
'term',
['oid'],
["`type` IN (?, ?) AND `oid` >= ?", Category::CATEGORY, Category::FILE, $id],
['order' => ['oid'], 'limit' => 1000, 'group_by' => ['oid']]);
['order' => ['oid'], 'limit' => 1000, 'group_by' => ['oid']]
);
if (DBA::errorNo() != 0) {
DI::logger()->error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
@ -557,7 +573,7 @@ class PostUpdate
DI::logger()->info('Start', ['item' => $id]);
$start_id = $id;
$rows = 0;
$rows = 0;
$items = DBA::p("SELECT `item`.`id`, `item`.`verb` AS `item-verb`, `item-content`.`verb`, `item-activity`.`activity`
FROM `item` LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id`
@ -570,7 +586,7 @@ class PostUpdate
}
while ($item = DBA::fetch($items)) {
$id = $item['id'];
$id = $item['id'];
$verb = $item['item-verb'];
if (empty($verb)) {
$verb = $item['verb'];
@ -618,11 +634,11 @@ class PostUpdate
DI::logger()->info('Start', ['contact' => $id]);
$start_id = $id;
$rows = 0;
$start_id = $id;
$rows = 0;
$condition = ["`id` > ? AND `gsid` IS NULL AND `baseurl` != '' AND NOT `baseurl` IS NULL", $id];
$params = ['order' => ['id'], 'limit' => 10000];
$contacts = DBA::select('contact', ['id', 'baseurl'], $condition, $params);
$params = ['order' => ['id'], 'limit' => 10000];
$contacts = DBA::select('contact', ['id', 'baseurl'], $condition, $params);
if (DBA::errorNo() != 0) {
DI::logger()->error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
@ -632,9 +648,11 @@ class PostUpdate
while ($contact = DBA::fetch($contacts)) {
$id = $contact['id'];
DBA::update('contact',
DBA::update(
'contact',
['gsid' => GServer::getID($contact['baseurl'], true), 'baseurl' => GServer::cleanURL($contact['baseurl'])],
['id' => $contact['id']]);
['id' => $contact['id']]
);
++$rows;
}
@ -671,10 +689,10 @@ class PostUpdate
DI::logger()->info('Start', ['apcontact' => $id]);
$start_id = $id;
$rows = 0;
$condition = ["`url` > ? AND `gsid` IS NULL AND `baseurl` != '' AND NOT `baseurl` IS NULL", $id];
$params = ['order' => ['url'], 'limit' => 10000];
$start_id = $id;
$rows = 0;
$condition = ["`url` > ? AND `gsid` IS NULL AND `baseurl` != '' AND NOT `baseurl` IS NULL", $id];
$params = ['order' => ['url'], 'limit' => 10000];
$apcontacts = DBA::select('apcontact', ['url', 'baseurl'], $condition, $params);
if (DBA::errorNo() != 0) {
@ -685,9 +703,11 @@ class PostUpdate
while ($apcontact = DBA::fetch($apcontacts)) {
$id = $apcontact['url'];
DBA::update('apcontact',
DBA::update(
'apcontact',
['gsid' => GServer::getID($apcontact['baseurl'], true), 'baseurl' => GServer::cleanURL($apcontact['baseurl'])],
['url' => $apcontact['url']]);
['url' => $apcontact['url']]
);
++$rows;
}
@ -723,7 +743,7 @@ class PostUpdate
DI::logger()->info('Start');
$deleted = 0;
$avatar = [4 => 'photo', 5 => 'thumb', 6 => 'micro'];
$avatar = [4 => 'photo', 5 => 'thumb', 6 => 'micro'];
$photos = DBA::select('photo', ['id', 'contact-id', 'resource-id', 'scale'], ["`contact-id` != ? AND `album` = ?", 0, Photo::CONTACT_PHOTOS]);
while ($photo = DBA::fetch($photos)) {
@ -764,7 +784,7 @@ class PostUpdate
$condition = ["`hash` IS NULL"];
DI::logger()->info('Start', ['rest' => DBA::count('photo', $condition)]);
$rows = 0;
$rows = 0;
$photos = DBA::select('photo', [], $condition, ['limit' => 100]);
if (DBA::errorNo() != 0) {
@ -814,7 +834,7 @@ class PostUpdate
$condition = ["`extid` != ? AND EXISTS(SELECT `id` FROM `post-user` WHERE `uri-id` = `item`.`uri-id` AND `uid` = `item`.`uid` AND `external-id` IS NULL)", ''];
DI::logger()->info('Start', ['rest' => DBA::count('item', $condition)]);
$rows = 0;
$rows = 0;
$items = DBA::select('item', ['uri-id', 'uid', 'extid'], $condition, ['order' => ['id'], 'limit' => 10000]);
if (DBA::errorNo() != 0) {
@ -856,7 +876,7 @@ class PostUpdate
$condition = ["`uri-id` IS NULL"];
DI::logger()->info('Start', ['rest' => DBA::count('contact', $condition)]);
$rows = 0;
$rows = 0;
$contacts = DBA::select('contact', ['id', 'url'], $condition, ['limit' => 1000]);
if (DBA::errorNo() != 0) {
@ -903,7 +923,7 @@ class PostUpdate
$condition = ["`uri-id` IS NULL"];
DI::logger()->info('Start', ['rest' => DBA::count('fcontact', $condition)]);
$rows = 0;
$rows = 0;
$fcontacts = DBA::select('fcontact', ['id', 'url', 'guid'], $condition, ['limit' => 1000]);
if (DBA::errorNo() != 0) {
@ -950,7 +970,7 @@ class PostUpdate
$condition = ["`uri-id` IS NULL"];
DI::logger()->info('Start', ['rest' => DBA::count('apcontact', $condition)]);
$rows = 0;
$rows = 0;
$apcontacts = DBA::select('apcontact', ['url', 'uuid'], $condition, ['limit' => 1000]);
if (DBA::errorNo() != 0) {
@ -997,7 +1017,7 @@ class PostUpdate
$condition = ["`uri-id` IS NULL"];
DI::logger()->info('Start', ['rest' => DBA::count('event', $condition)]);
$rows = 0;
$rows = 0;
$events = DBA::select('event', ['id', 'uri', 'guid'], $condition, ['limit' => 1000]);
if (DBA::errorNo() != 0) {
@ -1053,10 +1073,14 @@ class PostUpdate
$rows = 0;
$received = '';
$conversations = DBA::p("SELECT `post-view`.`uri-id`, `conversation`.`source`, `conversation`.`received` FROM `conversation`
$conversations = DBA::p(
"SELECT `post-view`.`uri-id`, `conversation`.`source`, `conversation`.`received` FROM `conversation`
INNER JOIN `post-view` ON `post-view`.`uri` = `conversation`.`item-uri`
WHERE NOT `source` IS NULL AND `conversation`.`protocol` = ? AND `uri-id` > ? LIMIT ?",
Conversation::PARCEL_ACTIVITYPUB, $id, 1000);
Conversation::PARCEL_ACTIVITYPUB,
$id,
1000
);
if (DBA::errorNo() != 0) {
DI::logger()->error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
@ -1199,11 +1223,11 @@ class PostUpdate
DI::logger()->info('Start', ['contact' => $id]);
$start_id = $id;
$rows = 0;
$start_id = $id;
$rows = 0;
$condition = ["`id` > ? AND `gsid` IS NULL AND `network` = ?", $id, Protocol::DIASPORA];
$params = ['order' => ['id'], 'limit' => 10000];
$contacts = DBA::select('contact', ['id', 'url'], $condition, $params);
$params = ['order' => ['id'], 'limit' => 10000];
$contacts = DBA::select('contact', ['id', 'url'], $condition, $params);
if (DBA::errorNo() != 0) {
DI::logger()->error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
@ -1217,9 +1241,11 @@ class PostUpdate
unset($parts['path']);
$server = (string)Uri::fromParts($parts);
DBA::update('contact',
DBA::update(
'contact',
['gsid' => GServer::getID($server, true), 'baseurl' => GServer::cleanURL($server)],
['id' => $contact['id']]);
['id' => $contact['id']]
);
++$rows;
}
@ -1256,10 +1282,10 @@ class PostUpdate
DI::logger()->info('Start', ['apcontact' => $id]);
$start_id = $id;
$rows = 0;
$condition = ["`url` > ? AND NOT `gsid` IS NULL", $id];
$params = ['order' => ['url'], 'limit' => 10000];
$start_id = $id;
$rows = 0;
$condition = ["`url` > ? AND NOT `gsid` IS NULL", $id];
$params = ['order' => ['url'], 'limit' => 10000];
$apcontacts = DBA::select('apcontact', ['url', 'gsid', 'sharedinbox', 'inbox'], $condition, $params);
if (DBA::errorNo() != 0) {
@ -1310,7 +1336,7 @@ class PostUpdate
$id = (int)(DI::keyValue()->get('post_update_version_1544_id') ?? 0);
if ($id == 0) {
$post = Post::selectFirstPost(['uri-id'], [], ['order' => ['uri-id' => true]]);
$id = (int)($post['uri-id'] ?? 0);
$id = (int)($post['uri-id'] ?? 0);
}
DI::logger()->info('Start', ['uri-id' => $id]);
@ -1375,7 +1401,7 @@ class PostUpdate
$id = (int)(DI::keyValue()->get('post_update_version_1550_id') ?? 0);
if ($id == 0) {
$post = Post::selectFirstPost(['uri-id'], [], ['order' => ['uri-id' => true]]);
$id = (int)($post['uri-id'] ?? 0);
$id = (int)($post['uri-id'] ?? 0);
}
DI::logger()->info('Start', ['uri-id' => $id]);