There is now a "global" field in the item table that tells if this item is present as global copy as well.

This commit is contained in:
Michael Vogel 2015-03-09 00:45:53 +01:00
parent 2260415ca9
commit ea06a1ec45
4 changed files with 25 additions and 5 deletions

View file

@ -778,6 +778,7 @@ function db_definition() {
"network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"rendered-hash" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"rendered-html" => array("type" => "mediumtext", "not null" => "1"),
"global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
),
"indexes" => array(
"PRIMARY" => array("id"),

View file

@ -1346,6 +1346,17 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
return 0;
}
// Is this item available in the global items (with uid=0)?
if ($arr["uid"] == 0) {
$arr["global"] = true;
q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($arr["guid"]));
} else {
$isglobal = q("SELECT `global` FROM `item` WHERE `uid` = 0 AND `guid` = '%s'", dbesc($arr["guid"]));
$arr["global"] = (count($isglobal) > 0);
}
// Fill the cache field
put_item_in_cache($arr);

View file

@ -112,8 +112,7 @@ function create_tags_from_itemuri($itemuri, $uid) {
function update_items() {
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);
$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", true);
$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()) {
@ -129,12 +128,21 @@ function update_items() {
$global = (count($isglobal) > 0);
}
echo $message["created"]." - ".$message["guid"]."\n";
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"]));
}
$db->qclose();
}
?>

View file

@ -143,8 +143,8 @@ function search_content(&$a) {
INNER JOIN `item` ON `item`.`id`=`term`.`oid`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `term`.`uid` IN (%d,0) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s' AND `term`.`guid` != ''
GROUP BY `term`.`guid` ORDER BY term.created DESC LIMIT %d , %d ",
AND (`term`.`uid` = 0 OR (`term`.`uid` = %d AND NOT `term`.`global`)) AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`term` = '%s'
ORDER BY term.created DESC LIMIT %d , %d ",
intval(local_user()), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)),
intval($a->pager['start']), intval($a->pager['itemspage']));
} else {