Some of the last direct SQL calls to the item table had been changed
This commit is contained in:
parent
dd1e6dd4a5
commit
70af2cecf2
|
@ -1859,20 +1859,17 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
|
|||
return true;
|
||||
}
|
||||
|
||||
function file_tag_save_file($uid, $item, $file)
|
||||
function file_tag_save_file($uid, $item_id, $file)
|
||||
{
|
||||
if (!intval($uid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = q("SELECT `file` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($item),
|
||||
intval($uid)
|
||||
);
|
||||
if (DBM::is_result($r)) {
|
||||
if (!stristr($r[0]['file'],'[' . file_tag_encode($file) . ']')) {
|
||||
$fields = ['file' => $r[0]['file'] . '[' . file_tag_encode($file) . ']'];
|
||||
Item::update($fields, ['id' => $item]);
|
||||
$item = Item::selectFirst(['file'], ['id' => $item_id, 'uid' => $uid]);
|
||||
if (DBM::is_result($item)) {
|
||||
if (!stristr($item['file'],'[' . file_tag_encode($file) . ']')) {
|
||||
$fields = ['file' => $item['file'] . '[' . file_tag_encode($file) . ']'];
|
||||
Item::update($fields, ['id' => $item_id]);
|
||||
}
|
||||
$saved = PConfig::get($uid, 'system', 'filetags');
|
||||
if (!strlen($saved) || !stristr($saved, '[' . file_tag_encode($file) . ']')) {
|
||||
|
@ -1883,7 +1880,7 @@ function file_tag_save_file($uid, $item, $file)
|
|||
return true;
|
||||
}
|
||||
|
||||
function file_tag_unsave_file($uid, $item, $file, $cat = false)
|
||||
function file_tag_unsave_file($uid, $item_id, $file, $cat = false)
|
||||
{
|
||||
if (!intval($uid)) {
|
||||
return false;
|
||||
|
@ -1897,16 +1894,13 @@ function file_tag_unsave_file($uid, $item, $file, $cat = false)
|
|||
$termtype = TERM_FILE;
|
||||
}
|
||||
|
||||
$r = q("SELECT `file` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($item),
|
||||
intval($uid)
|
||||
);
|
||||
if (! DBM::is_result($r)) {
|
||||
$item = Item::selectFirst(['file'], ['id' => $item_id, 'uid' => $uid]);
|
||||
if (!DBM::is_result($item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fields = ['file' => str_replace($pattern,'',$r[0]['file'])];
|
||||
Item::update($fields, ['id' => $item]);
|
||||
$fields = ['file' => str_replace($pattern,'',$item['file'])];
|
||||
Item::update($fields, ['id' => $item_id]);
|
||||
|
||||
$r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",
|
||||
dbesc($file),
|
||||
|
|
|
@ -21,22 +21,19 @@ function starred_init(App $a) {
|
|||
killme();
|
||||
}
|
||||
|
||||
$r = q("SELECT `starred` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
|
||||
intval(local_user()),
|
||||
intval($message_id)
|
||||
);
|
||||
if (! DBM::is_result($r)) {
|
||||
$item = Item::selectForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $message_id]);
|
||||
if (!DBM::is_result($item)) {
|
||||
killme();
|
||||
}
|
||||
|
||||
if (! intval($r[0]['starred'])) {
|
||||
if (!intval($item['starred'])) {
|
||||
$starred = 1;
|
||||
}
|
||||
|
||||
Item::update(['starred' => $starred], ['id' => $message_id]);
|
||||
|
||||
// See if we've been passed a return path to redirect to
|
||||
$return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
|
||||
$return_path = (x($_REQUEST,'return') ? $_REQUEST['return'] : '');
|
||||
if ($return_path) {
|
||||
$rand = '_=' . time();
|
||||
if (strpos($return_path, '?')) {
|
||||
|
|
|
@ -175,23 +175,19 @@ EOT;
|
|||
}
|
||||
|
||||
// if the original post is on this site, update it.
|
||||
|
||||
$r = q("SELECT `tag`,`id`,`uid` FROM `item` WHERE `origin`=1 AND `uri`='%s' LIMIT 1",
|
||||
dbesc($item['uri'])
|
||||
);
|
||||
|
||||
if (DBM::is_result($r)) {
|
||||
$original_item = Item::selectFirst(['tag','id','uid'], ['origin' => true, 'uri' => $item['uri']]);
|
||||
if (DBM::is_result($original_item)) {
|
||||
$x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
|
||||
intval($r[0]['uid'])
|
||||
intval($original_item['uid'])
|
||||
);
|
||||
$t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
|
||||
intval($r[0]['id']),
|
||||
intval($original_item['id']),
|
||||
dbesc($term)
|
||||
);
|
||||
|
||||
if (DBM::is_result($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
|
||||
q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
|
||||
intval($r[0]['id']),
|
||||
intval($original_item['id']),
|
||||
$term_objtype,
|
||||
TERM_HASHTAG,
|
||||
dbesc($term),
|
||||
|
|
|
@ -938,10 +938,10 @@ class DFRN
|
|||
|
||||
if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
|
||||
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
|
||||
$parent = q("SELECT `guid`,`plink` FROM `item` WHERE `uri` = '%s' AND `uid` = %d", dbesc($parent_item), intval($item['uid']));
|
||||
$parent = Item::selectFirst(['guid','plink'], ['uri' => $parent_item, 'uid' => $item['uid']]);
|
||||
$attributes = ["ref" => $parent_item, "type" => "text/html",
|
||||
"href" => $parent[0]['plink'],
|
||||
"dfrn:diaspora_guid" => $parent[0]['guid']];
|
||||
"href" => $parent['plink'],
|
||||
"dfrn:diaspora_guid" => $parent['guid']];
|
||||
XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
|
||||
}
|
||||
|
||||
|
@ -2161,13 +2161,8 @@ class DFRN
|
|||
|
||||
$is_a_remote_action = false;
|
||||
|
||||
$r = q(
|
||||
"SELECT `item`.`parent-uri` FROM `item`
|
||||
WHERE `item`.`uri` = '%s'
|
||||
LIMIT 1",
|
||||
dbesc($item["parent-uri"])
|
||||
);
|
||||
if (DBM::is_result($r)) {
|
||||
$parent = Item::selectFirst(['parent-uri'], ['uri' => $item["parent-uri"]]);
|
||||
if (DBM::is_result($parent)) {
|
||||
$r = q(
|
||||
"SELECT `item`.`forum_mode`, `item`.`wall` FROM `item`
|
||||
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
||||
|
@ -2175,9 +2170,9 @@ class DFRN
|
|||
AND `item`.`uid` = %d
|
||||
$sql_extra
|
||||
LIMIT 1",
|
||||
dbesc($r[0]["parent-uri"]),
|
||||
dbesc($r[0]["parent-uri"]),
|
||||
dbesc($r[0]["parent-uri"]),
|
||||
dbesc($parent["parent-uri"]),
|
||||
dbesc($parent["parent-uri"]),
|
||||
dbesc($parent["parent-uri"]),
|
||||
intval($importer["importer_uid"])
|
||||
);
|
||||
if (DBM::is_result($r)) {
|
||||
|
@ -2318,25 +2313,15 @@ class DFRN
|
|||
$item["gravity"] = GRAVITY_LIKE;
|
||||
// only one like or dislike per person
|
||||
// splitted into two queries for performance issues
|
||||
$r = q(
|
||||
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-id` = %d AND `verb` = '%s' AND `parent-uri` = '%s' AND NOT `deleted` LIMIT 1",
|
||||
intval($item["uid"]),
|
||||
intval($item["author-id"]),
|
||||
dbesc($item["verb"]),
|
||||
dbesc($item["parent-uri"])
|
||||
);
|
||||
if (DBM::is_result($r)) {
|
||||
$condition = ['uid' => $item["uid"], 'author-id' => $item["author-id"],
|
||||
'verb' => $item["verb"], 'parent-uri' => $item["parent-uri"]];
|
||||
if (dba::exists('item', $condition)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = q(
|
||||
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-id` = %d AND `verb` = '%s' AND `thr-parent` = '%s' AND NOT `deleted` LIMIT 1",
|
||||
intval($item["uid"]),
|
||||
intval($item["author-id"]),
|
||||
dbesc($item["verb"]),
|
||||
dbesc($item["parent-uri"])
|
||||
);
|
||||
if (DBM::is_result($r)) {
|
||||
$condition = ['uid' => $item["uid"], 'author-id' => $item["author-id"],
|
||||
'verb' => $item["verb"], 'thr-parent' => $item["parent-uri"]];
|
||||
if (dba::exists('item', $condition)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
@ -2348,22 +2333,17 @@ class DFRN
|
|||
$xt = XML::parseString($item["target"], false);
|
||||
|
||||
if ($xt->type == ACTIVITY_OBJ_NOTE) {
|
||||
$r = q(
|
||||
"SELECT `id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($xt->id),
|
||||
intval($importer["importer_uid"])
|
||||
);
|
||||
|
||||
if (!DBM::is_result($r)) {
|
||||
$item_tag = Item::selectFirst(['id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
|
||||
if (!DBM::is_result($item_tag)) {
|
||||
logger("Query failed to execute, no result returned in " . __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
|
||||
// extract tag, if not duplicate, add to parent item
|
||||
if ($xo->content) {
|
||||
if (!stristr($r[0]["tag"], trim($xo->content))) {
|
||||
$tag = $r[0]["tag"] . (strlen($r[0]["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]';
|
||||
Item::update(['tag' => $tag], ['id' => $r[0]["id"]]);
|
||||
if (!stristr($item_tag["tag"], trim($xo->content))) {
|
||||
$tag = $item_tag["tag"] . (strlen($item_tag["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]';
|
||||
Item::update(['tag' => $tag], ['id' => $item_tag["id"]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -438,12 +438,10 @@ class OnePoll
|
|||
$refs_arr[$x] = "'" . Email::msgid2iri(str_replace(['<', '>', ' '],['', '', ''],dbesc($refs_arr[$x]))) . "'";
|
||||
}
|
||||
}
|
||||
$qstr = implode(',', $refs_arr);
|
||||
$r = q("SELECT `parent-uri` FROM `item` USE INDEX (`uid_uri`) WHERE `uri` IN ($qstr) AND `uid` = %d LIMIT 1",
|
||||
intval($importer_uid)
|
||||
);
|
||||
if (DBM::is_result($r)) {
|
||||
$datarray['parent-uri'] = $r[0]['parent-uri']; // Set the parent as the top-level item
|
||||
$condition = ['uri' => $refs_arr, 'uid' => $importer_uid];
|
||||
$parent = Item::selectFirst(['parent-uri'], $condition);
|
||||
if (DBM::is_result($parent)) {
|
||||
$datarray['parent-uri'] = $parent['parent-uri']; // Set the parent as the top-level item
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -472,12 +470,11 @@ class OnePoll
|
|||
|
||||
// If it seems to be a reply but a header couldn't be found take the last message with matching subject
|
||||
if (empty($datarray['parent-uri']) && $reply) {
|
||||
$r = q("SELECT `parent-uri` FROM `item` WHERE `title` = \"%s\" AND `uid` = %d AND `network` = '%s' ORDER BY `created` DESC LIMIT 1",
|
||||
dbesc(protect_sprintf($datarray['title'])),
|
||||
intval($importer_uid),
|
||||
dbesc(NETWORK_MAIL));
|
||||
if (DBM::is_result($r)) {
|
||||
$datarray['parent-uri'] = $r[0]['parent-uri'];
|
||||
$condition = ['title' => $datarray['title'], 'uid' => importer_uid, 'network' => NETWORK_MAIL];
|
||||
$params = ['order' => ['created' => true]];
|
||||
$parent = Item::selectFirst(['parent-uri'], $condition, $params);
|
||||
if (DBM::is_result($parent)) {
|
||||
$datarray['parent-uri'] = $parent['parent-uri'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class TagUpdate
|
|||
|
||||
dba::close($messages);
|
||||
|
||||
$messages = dba::p("SELECT `guid` FROM `item` WHERE `uid` = 0");
|
||||
$messages = dba::select('item', ['guid'], ['uid' => 0]);
|
||||
|
||||
logger('fetched messages: ' . dba::num_rows($messages));
|
||||
while ($message = dba::fetch(messages)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user