From 8f27715d8b864fb31bf96ba481f1a10c7d70659c Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sat, 6 Feb 2021 13:42:21 +0000
Subject: [PATCH] "item" is replaced whenever possible at the moment

---
 src/Database/DBA.php               |  4 ++--
 src/Database/Database.php          |  4 ++--
 src/Model/Item.php                 |  8 ++++----
 src/Module/Admin/Site.php          |  2 +-
 src/Module/Settings/UserExport.php |  2 +-
 src/Worker/CleanItemUri.php        |  3 ++-
 src/Worker/Expire.php              |  5 +++--
 src/Worker/MergeContact.php        | 12 +++++-------
 src/Worker/RepairDatabase.php      |  2 +-
 9 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/Database/DBA.php b/src/Database/DBA.php
index 41ab456b8..3bdcfb617 100644
--- a/src/Database/DBA.php
+++ b/src/Database/DBA.php
@@ -478,7 +478,7 @@ class DBA
 	 * @return boolean|object
 	 *
 	 * Example:
-	 * $table = "item";
+	 * $table = "post";
 	 * $fields = array("id", "uri", "uid", "network");
 	 *
 	 * $condition = array("uid" => 1, "network" => 'dspr');
@@ -505,7 +505,7 @@ class DBA
 	 * @return int
 	 *
 	 * Example:
-	 * $table = "item";
+	 * $table = "post";
 	 *
 	 * $condition = ["uid" => 1, "network" => 'dspr'];
 	 * or:
diff --git a/src/Database/Database.php b/src/Database/Database.php
index ae06f00e2..ec95a8301 100644
--- a/src/Database/Database.php
+++ b/src/Database/Database.php
@@ -1512,7 +1512,7 @@ class Database
 	 *
 	 *
 	 * Example:
-	 * $table = 'item';
+	 * $table = 'post';
 	 * or:
 	 * $table = ['schema' => 'table'];
 	 * @see DBA::buildTableString()
@@ -1575,7 +1575,7 @@ class Database
 	 * @return int
 	 *
 	 * Example:
-	 * $table = "item";
+	 * $table = "post";
 	 *
 	 * $condition = ["uid" => 1, "network" => 'dspr'];
 	 * or:
diff --git a/src/Model/Item.php b/src/Model/Item.php
index 106d50e76..8eeb77d32 100644
--- a/src/Model/Item.php
+++ b/src/Model/Item.php
@@ -319,7 +319,7 @@ class Item
 
 		// Set the item to "deleted"
 		$item_fields = ['deleted' => true, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
-		DBA::update('item', $item_fields, ['id' => $item['id']]);
+		Post::update($item_fields, ['id' => $item['id']]);
 
 		Post\Category::storeTextByURIId($item['uri-id'], $item['uid'], '');
 		self::deleteThread($item['id'], $item['parent-uri-id']);
@@ -919,7 +919,7 @@ class Item
 			$item["global"] = true;
 
 			// Set the global flag on all items if this was a global item entry
-			DBA::update('item', ['global' => true], ['uri-id' => $item['uri-id']]);
+			Post::update(['global' => true], ['uri-id' => $item['uri-id']]);
 		} else {
 			$item['global'] = Post::exists(['uid' => 0, 'uri-id' => $item['uri-id']]);
 		}
@@ -1068,9 +1068,9 @@ class Item
 		}
 
 		if ($update_commented) {
-			DBA::update('item', ['commented' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]);
+			Post::update(['commented' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]);
 		} else {
-			DBA::update('item', ['changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]);
+			Post::update(['changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]);
 		}
 
 		if ($item['gravity'] === GRAVITY_PARENT) {
diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php
index 0e0753a40..8cd2648cf 100644
--- a/src/Module/Admin/Site.php
+++ b/src/Module/Admin/Site.php
@@ -104,7 +104,7 @@ class Site extends BaseAdmin
 			// update profile links in the format "http://server.tld"
 			update_table($a, "profile", ['photo', 'thumb'], $old_url, $new_url);
 			update_table($a, "contact", ['photo', 'thumb', 'micro', 'url', 'nurl', 'alias', 'request', 'notify', 'poll', 'confirm', 'poco', 'avatar'], $old_url, $new_url);
-			update_table($a, "item", ['owner-link', 'author-link', 'body', 'plink', 'tag'], $old_url, $new_url);
+			update_table($a, "post-content", ['body'], $old_url, $new_url);
 
 			// update profile addresses in the format "user@server.tld"
 			update_table($a, "contact", ['addr'], $old_host, $new_host);
diff --git a/src/Module/Settings/UserExport.php b/src/Module/Settings/UserExport.php
index 42ee4eb1f..2b668182e 100644
--- a/src/Module/Settings/UserExport.php
+++ b/src/Module/Settings/UserExport.php
@@ -242,7 +242,7 @@ class UserExport extends BaseSettings
 		self::exportAccount($a);
 		echo "\n";
 
-		$total = DBA::count('item', ['uid' => local_user()]);
+		$total = Post::count(['uid' => local_user()]);
 		// chunk the output to avoid exhausting memory
 
 		for ($x = 0; $x < $total; $x += 500) {
diff --git a/src/Worker/CleanItemUri.php b/src/Worker/CleanItemUri.php
index d7a99153f..268fe29dc 100644
--- a/src/Worker/CleanItemUri.php
+++ b/src/Worker/CleanItemUri.php
@@ -23,6 +23,7 @@ namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
 use Friendica\Database\DBA;
+use Friendica\Model\Post;
 
 class CleanItemUri
 {
@@ -33,7 +34,7 @@ class CleanItemUri
 	{
 		// We have to avoid deleting newly created "item-uri" entries.
 		// So we fetch a post that had been stored yesterday and only delete older ones.
-		$item = DBA::selectFirst('item', ['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY", 0, 1],
+		$item = Post::selectFirst(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY", 0, 1],
 			['order' => ['received' => true]]);
 		if (empty($item['uri-id'])) {
 			Logger::warning('No item with uri-id found - we better quit here');
diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php
index 70a4f913a..ca92bd1ee 100644
--- a/src/Worker/Expire.php
+++ b/src/Worker/Expire.php
@@ -44,11 +44,12 @@ class Expire
 			Logger::log('Delete expired items', Logger::DEBUG);
 			// physically remove anything that has been deleted for more than two months
 			$condition = ["`deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY"];
-			$rows = DBA::select('item', ['id', 'guid', 'uri-id', 'uid'],  $condition);
-			while ($row = DBA::fetch($rows)) {
+			$rows = Post::select(['id', 'guid', 'uri-id', 'uid'],  $condition);
+			while ($row = Post::fetch($rows)) {
 				Logger::info('Delete expired item', ['id' => $row['id'], 'guid' => $row['guid']]);
 				DBA::delete('item', ['id' => $row['id']]);
 				Post\User::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
+				Post\ThreadUser::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
 			}
 			DBA::close($rows);
 
diff --git a/src/Worker/MergeContact.php b/src/Worker/MergeContact.php
index e04dfb6ac..7a4c07540 100644
--- a/src/Worker/MergeContact.php
+++ b/src/Worker/MergeContact.php
@@ -23,6 +23,7 @@ namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
 use Friendica\Database\DBA;
+use Friendica\Model\Post;
 
 class MergeContact
 {
@@ -43,8 +44,7 @@ class MergeContact
 		Logger::info('Handling duplicate', ['search' => $old_cid, 'replace' => $new_cid]);
 
 		// Search and replace
-		DBA::update('item', ['contact-id' => $new_cid], ['contact-id' => $old_cid]);
-		DBA::update('thread', ['contact-id' => $new_cid], ['contact-id' => $old_cid]);
+		Post::update(['contact-id' => $new_cid], ['contact-id' => $old_cid]);
 		DBA::update('mail', ['contact-id' => $new_cid], ['contact-id' => $old_cid]);
 		DBA::update('photo', ['contact-id' => $new_cid], ['contact-id' => $old_cid]);
 		DBA::update('event', ['cid' => $new_cid], ['cid' => $old_cid]);
@@ -53,11 +53,9 @@ class MergeContact
 		if ($uid == 0) {
 			DBA::update('post-tag', ['cid' => $new_cid], ['cid' => $old_cid]);
 			DBA::delete('post-tag', ['cid' => $old_cid]);
-			DBA::update('item', ['author-id' => $new_cid], ['author-id' => $old_cid]);
-			DBA::update('item', ['owner-id' => $new_cid], ['owner-id' => $old_cid]);
-			DBA::update('item', ['causer-id' => $new_cid], ['causer-id' => $old_cid]);
-			DBA::update('thread', ['author-id' => $new_cid], ['author-id' => $old_cid]);
-			DBA::update('thread', ['owner-id' => $new_cid], ['owner-id' => $old_cid]);
+			Post::update(['author-id' => $new_cid], ['author-id' => $old_cid]);
+			Post::update(['owner-id' => $new_cid], ['owner-id' => $old_cid]);
+			Post::update(['causer-id' => $new_cid], ['causer-id' => $old_cid]);
 		} else {
 			/// @todo Check if some other data needs to be adjusted as well, possibly the "rel" status?
 		}
diff --git a/src/Worker/RepairDatabase.php b/src/Worker/RepairDatabase.php
index 3524c3d15..ef9035d89 100644
--- a/src/Worker/RepairDatabase.php
+++ b/src/Worker/RepairDatabase.php
@@ -26,7 +26,7 @@ use Friendica\Model\ItemURI;
 
 /**
  * Do some repairs in database entries
- *
+ * @todo This class can be deleted without replacement when the item table is removed
  */
 class RepairDatabase
 {