Merge branch 'develop' of https://github.com/friendica/friendica into develop
[friendica.git/.git] / update.php
index 85a0689..5295d0b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2023, the Friendica project
+ * @copyright Copyright (C) 2010-2024, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -59,8 +59,11 @@ use Friendica\Model\Photo;
 use Friendica\Model\Post;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
+use Friendica\Protocol\Activity;
 use Friendica\Protocol\Delivery;
 use Friendica\Security\PermissionSet\Repository\PermissionSet;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Worker\UpdateContact;
 
 // Post-update script of PR 5751
 function update_1298()
@@ -78,7 +81,7 @@ function update_1298()
                                        $a = new \stdClass();
                                        $a->strings = [];
 
-                                       // First we get the the localizations
+                                       // First we get the localizations
                                        if (file_exists('view/lang/$lang/strings.php')) {
                                                include 'view/lang/$lang/strings.php';
                                        }
@@ -1227,3 +1230,231 @@ function update_1510()
        }
        return Update::SUCCESS;
 }
+
+function update_1512()
+{
+       DI::keyValue()->set('nodeinfo_total_users', DI::config()->get('nodeinfo', 'total_users'));
+       DI::keyValue()->set('nodeinfo_active_users_halfyear', DI::config()->get('nodeinfo', 'active_users_halfyear'));
+       DI::keyValue()->set('nodeinfo_active_users_monthly', DI::config()->get('nodeinfo', 'active_users_monthly'));
+       DI::keyValue()->set('nodeinfo_active_users_weekly', DI::config()->get('nodeinfo', 'active_users_weekly'));
+       DI::keyValue()->set('nodeinfo_local_posts', DI::config()->get('nodeinfo', 'local_posts'));
+       DI::keyValue()->set('nodeinfo_local_comments', DI::config()->get('nodeinfo', 'local_comments'));
+
+       DI::config()->delete('nodeinfo', 'total_users');
+       DI::config()->delete('nodeinfo', 'active_users_halfyear');
+       DI::config()->delete('nodeinfo', 'active_users_monthly');
+       DI::config()->delete('nodeinfo', 'active_users_weekly');
+       DI::config()->delete('nodeinfo', 'local_posts');
+       DI::config()->delete('nodeinfo', 'local_comments');
+}
+
+function update_1513()
+{
+       DI::keyValue()->set('git_friendica_version', DI::config()->get('system', 'git_friendica_version'));
+       DI::keyValue()->set('twitter_application_name', DI::config()->get('twitter', 'application_name'));
+
+       DI::config()->delete('system', 'git_friendica_version');
+       DI::config()->delete('twitter', 'application_name');
+}
+
+function update_1514()
+{
+       if (file_exists(dirname(__FILE__) . '/config/node.config.php')) {
+
+               $transactionalConfig = DI::config()->beginTransaction();
+               $oldConfig = include dirname(__FILE__) . '/config/node.config.php';
+
+               if (is_array($oldConfig)) {
+                       $categories = array_keys($oldConfig);
+
+                       foreach ($categories as $category) {
+                               if (is_array($oldConfig[$category])) {
+                                       $keys = array_keys($oldConfig[$category]);
+
+                                       foreach ($keys as $key) {
+                                               $transactionalConfig->set($category, $key, $oldConfig[$category][$key]);
+                                       }
+                               }
+                       }
+               }
+
+               $transactionalConfig->commit();
+
+               // Rename the node.config.php so it won't get used, but it isn't deleted.
+               if (rename(dirname(__FILE__) . '/config/node.config.php', dirname(__FILE__) . '/config/node.config.php.bak')) {
+                       return Update::SUCCESS;
+               } else {
+                       return Update::FAILED;
+               }
+       }
+
+       return Update::SUCCESS;
+}
+
+function update_1515()
+{
+       DBA::update('verb', ['name' => Activity::READ], ['name' => 'https://www.w3.org/ns/activitystreams#read']);
+       DBA::update('verb', ['name' => Activity::VIEW], ['name' => 'https://joinpeertube.org/view']);
+       return Update::SUCCESS;
+}
+
+function update_1516()
+{
+       // Fixes https://github.com/friendica/friendica/issues/12803
+       // de-serialize multiple serialized values
+       $configTrans = DI::config()->beginTransaction();
+       $configArray = DI::config()->getCache()->getDataBySource(Cache::SOURCE_DATA);
+
+       foreach ($configArray as $category => $keyValues) {
+               if (is_array($keyValues)) {
+                       foreach ($keyValues as $key => $value) {
+                               $configTrans->set($category, $key, $value);
+                       }
+               }
+       }
+
+       $configTrans->commit();
+
+       return Update::SUCCESS;
+}
+
+function update_1518()
+{
+       $users = DBA::select('user', ['uid']);
+       while ($user = DBA::fetch($users)) {
+               Contact::updateSelfFromUserID($user['uid']);
+       }
+       DBA::close($users);
+
+       return Update::SUCCESS;
+}
+
+function update_1520(): int
+{
+       DBA::update('user', ['parent-uid' => null], ['parent-uid' => 0]);
+
+       return Update::SUCCESS;
+}
+
+/**
+ * user-contact.remote_self was wrongly declared as boolean, possibly truncating integer values from contact.remote_self
+ *
+ * @return int
+ * @throws Exception
+ */
+function update_1524(): int
+{
+       $contacts = DBA::select('contact', ['uid', 'uri-id', 'remote_self'], ["`uid` != ?", 0]);
+       while ($contact = DBA::fetch($contacts)) {
+               Contact\User::insertForContactArray($contact);
+       }
+
+       return Update::SUCCESS;
+}
+
+function update_1525(): int
+{
+       // Use expected value for user.username
+       if (!DBA::e('UPDATE `user` u
+    JOIN `profile` p
+    ON p.`uid` = u.`uid`
+    SET u.`username` = p.`name`
+    WHERE p.`name` != ""')) {
+               return Update::FAILED;
+       }
+
+       // Blank out deprecated field profile.name to avoid future confusion
+       if (!DBA::e('UPDATE `profile` p
+    SET p.`name` = ""')) {
+               return Update::FAILED;
+       }
+
+       // Update users' self-contact name if needed
+       if (!DBA::e('UPDATE `contact` c
+    JOIN `user` u
+    ON u.`uid` = c.`uid` AND c.`self` = 1
+    SET c.`name` = u.`username`')) {
+               return Update::FAILED;
+       }
+
+       return Update::SUCCESS;
+}
+
+function update_1531()
+{
+       $threads = Post::selectThread(Item::DELIVER_FIELDLIST, ["`uid` = ? AND `created` > ?", 0, DateTimeFormat::utc('now - ' . DI::config()->get('channel', 'engagement_hours') . ' hour')]);
+       while ($post = Post::fetch($threads)) {
+               $post['gravity'] = Item::GRAVITY_COMMENT;
+               Post\Engagement::storeFromItem($post);
+       }
+       DBA::close($threads);
+
+       return Update::SUCCESS;
+}
+
+function update_1535()
+{
+       if (DI::config()->get('system', 'compute_group_counts')) {
+               DI::config()->set('system', 'compute_circle_counts', true);
+       }
+       DI::config()->delete('system', 'compute_group_counts');
+       
+       return Update::SUCCESS;
+}
+
+function update_1539()
+{
+       $users = DBA::select('user', ['uid'], ['account-type' => User::ACCOUNT_TYPE_COMMUNITY]);
+       while ($user = DBA::fetch($users)) {
+               User::setCommunityUserSettings($user['uid']);
+       }
+       DBA::close($users);
+
+       return Update::SUCCESS;
+}
+
+function pre_update_1550()
+{
+       if (DBStructure::existsTable('post-engagement') && DBStructure::existsColumn('post-engagement', ['language'])) {
+               DBA::e("ALTER TABLE `post-engagement` DROP `language`");
+       }
+       if (DBStructure::existsTable('post-searchindex') && DBStructure::existsColumn('post-searchindex', ['network'])) {
+               DBA::e("ALTER TABLE `post-searchindex` DROP `network`, DROP `private`");
+       }
+       return Update::SUCCESS;
+}
+
+function update_1552()
+{
+       DBA::e("UPDATE `post-content` INNER JOIN `post-tag` ON `post-tag`.`uri-id` = `post-content`.`uri-id` INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid` SET `sensitive` = ? WHERE `name` = ?", true, 'nsfw');
+
+       return Update::SUCCESS;
+}
+
+function update_1554()
+{
+       DBA::e("UPDATE `post-engagement` INNER JOIN `post` ON `post`.`uri-id` = `post-engagement`.`uri-id` SET `post-engagement`.`network` = `post`.`network`");
+
+       return Update::SUCCESS;
+}
+
+function update_1556()
+{
+       $users = DBA::select('user', ['uid'], ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
+       while ($user = DBA::fetch($users)) {
+               Worker::add(Worker::PRIORITY_LOW, 'ProfileUpdate', $user['uid']);
+       }
+       DBA::close($users);
+
+       return Update::SUCCESS;
+}
+
+function update_1557()
+{
+       $contacts = DBA::select('account-view', ['id'], ['platform' => 'friendica', 'contact-type' => Contact::TYPE_RELAY]);
+       while ($contact = DBA::fetch($contacts)) {
+               UpdateContact::add(Worker::PRIORITY_LOW, $contact['id']);
+       }
+       DBA::close($contacts);
+       return Update::SUCCESS;
+}