+ global $db;
+
+ $messages = $db->q("SELECT `oid`,`item`.`guid`, `item`.`created`, `item`.`received` FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` WHERE `term`.`otype` = 1 AND `term`.`guid` = ''", true);
+
+ logger("fetched messages: ".count($messages));
+ while ($message = $db->qfetch()) {
+
+ if ($message["uid"] == 0) {
+ $global = true;
+
+ q("UPDATE `term` SET `global` = 1 WHERE `otype` = %d AND `guid` = '%s'",
+ intval(TERM_OBJ_POST), dbesc($message["guid"]));
+ } else {
+ $isglobal = q("SELECT `global` FROM `term` WHERE `uid` = 0 AND `otype` = %d AND `guid` = '%s'",
+ intval(TERM_OBJ_POST), dbesc($message["guid"]));
+
+ $global = (count($isglobal) > 0);
+ }
+
+ q("UPDATE `term` SET `guid` = '%s', `created` = '%s', `received` = '%s', `global` = %d WHERE `otype` = %d AND `oid` = %d",
+ dbesc($message["guid"]), dbesc($message["created"]), dbesc($message["received"]),
+ intval($global), intval(TERM_OBJ_POST), intval($message["oid"]));
+ }
+
+ $db->qclose();
+
+ $messages = $db->q("SELECT `guid` FROM `item` WHERE `uid` = 0", true);
+
+ logger("fetched messages: ".count($messages));
+ while ($message = $db->qfetch()) {
+ q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($message["guid"]));
+ }