From: Michael Vogel <icarus@dabo.de>
Date: Sat, 23 Jan 2016 21:05:27 +0000 (+0100)
Subject: Frequently repair of database entries
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b76dc8b129eeee465f1c288b1c4e6d726a0a0c9e;p=friendica.git

Frequently repair of database entries
---

diff --git a/include/cron.php b/include/cron.php
index bf3243cb60..71af5d826f 100644
--- a/include/cron.php
+++ b/include/cron.php
@@ -164,6 +164,9 @@ function cron_run(&$argv, &$argc){
 	// Repair missing Diaspora values in contacts
 	cron_repair_diaspora($a);
 
+	// Repair entries in the database
+	cron_repair_database();
+
 	$manual_id  = 0;
 	$generation = 0;
 	$force      = false;
@@ -417,6 +420,24 @@ function cron_repair_diaspora(&$a) {
 	}
 }
 
+/**
+ * @brief Do some repairs in database entries
+ *
+ */
+function cron_repair_database() {
+
+	// Set the parent if it wasn't set. (Shouldn't happen - but does sometimes)
+	// This call is very "cheap" so we can do it at any time without a problem
+	q("UPDATE `item` INNER JOIN `item` AS `parent` ON `parent`.`uri` = `item`.`parent-uri` AND `parent`.`uid` = `item`.`uid` SET `item`.`parent` = `parent`.`id` WHERE `item`.`parent` = 0");
+
+	/// @todo
+	// - remove duplicated contacts with uid=0 (We could do this at the place where the contacts are stored)
+	// - remove thread entries without item
+	// - remove sign entries without item
+	// - remove children when parent got lost
+	// - set contact-id in item when not present
+}
+
 if (array_search(__file__,get_included_files())===0){
 	cron_run($_SERVER["argv"],$_SERVER["argc"]);
 	killme();