X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FDatabase%2FPostUpdate.php;h=3e2627b9a9f5f585fd06af4fef7f9244d5f79172;hb=bb5e6d248b384192ab070108afbfb58acbee3fc3;hp=a58281e48b3ed62aadaf07c782df16e857d44355;hpb=36357e790e460b438004be6320e5cea8634b0c21;p=friendica.git diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index a58281e48b..3e2627b9a9 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -1,6 +1,6 @@ get("system", "post_update_version") >= 1400) { + return true; + } + + if (!DBStructure::existsTable('item')) { + DI::config()->set("system", "post_update_version", 1400); + return true; + } + + $condition = ["`extid` != ? AND EXISTS(SELECT `id` FROM `post-user` WHERE `uri-id` = `item`.`uri-id` AND `uid` = `item`.`uid` AND `external-id` IS NULL)", '']; + Logger::info('Start', ['rest' => DBA::count('item', $condition)]); + + $rows = 0; + $items = DBA::select('item', ['uri-id', 'uid', 'extid'], $condition, ['order' => ['id'], 'limit' => 10000]); + + if (DBA::errorNo() != 0) { + Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]); + return false; + } + + while ($item = DBA::fetch($items)) { + Post::update(['external-id' => ItemURI::getIdByURI($item['extid'])], ['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); + ++$rows; + } + DBA::close($items); + + Logger::info('Processed', ['rows' => $rows]); + + if ($rows <= 100) { + DI::config()->set("system", "post_update_version", 1400); + Logger::info('Done'); + return true; + } + + return false; + } }