Some standards and dba

update some calls to use dba functions and some standards updates
This commit is contained in:
Adam Magness 2018-02-05 08:09:39 -05:00
parent 8906b98426
commit 992836e261

View file

@ -1873,14 +1873,16 @@ EOT;
return true; return true;
} }
private static function addThread($itemid, $onlyshadow = false) { private static function addThread($itemid, $onlyshadow = false)
{
$items = q("SELECT `uid`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, $items = q("SELECT `uid`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`,
`moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
`deleted`, `origin`, `forum_mode`, `mention`, `network`, `author-id`, `owner-id` `deleted`, `origin`, `forum_mode`, `mention`, `network`, `author-id`, `owner-id`
FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid)); FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
if (!$items) if (!$items) {
return; return;
}
$item = $items[0]; $item = $items[0];
$item['iid'] = $itemid; $item['iid'] = $itemid;
@ -1892,8 +1894,9 @@ EOT;
} }
} }
public static function updateThreadFromUri($itemuri, $uid) { public static function updateThreadFromUri($itemuri, $uid)
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid)); {
$messages = dba::select('item', ['id'], ['uri' => $itemuri, 'uid' => $uid]);
if (DBM::is_result($messages)) { if (DBM::is_result($messages)) {
foreach ($messages as $message) { foreach ($messages as $message) {
@ -1902,7 +1905,8 @@ EOT;
} }
} }
public static function updateThread($itemid, $setmention = false) { public static function updateThread($itemid, $setmention = false)
{
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`, $items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
`deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid)); `deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
@ -1918,7 +1922,7 @@ EOT;
$sql = ""; $sql = "";
foreach ($item AS $field => $data) foreach ($item as $field => $data)
if (!in_array($field, ["guid", "title", "body", "rendered-html", "rendered-hash"])) { if (!in_array($field, ["guid", "title", "body", "rendered-html", "rendered-hash"])) {
if ($sql != "") { if ($sql != "") {
$sql .= ", "; $sql .= ", ";
@ -1932,24 +1936,24 @@ EOT;
logger("Update thread for item ".$itemid." - guid ".$item["guid"]." - ".print_r($result, true)." ".print_r($item, true), LOGGER_DEBUG); logger("Update thread for item ".$itemid." - guid ".$item["guid"]." - ".print_r($result, true)." ".print_r($item, true), LOGGER_DEBUG);
// Updating a shadow item entry // Updating a shadow item entry
$items = q("SELECT `id` FROM `item` WHERE `guid` = '%s' AND `uid` = 0 LIMIT 1", dbesc($item["guid"])); $items = dba::selectFirst('item', ['id'], ['guid' => $item['guid'], 'uid' => 0]);
if (!DBM::is_result($items)) { if (!DBM::is_result($items)) {
return; return;
} }
$result = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d", $result = dba::update(
dbesc($item["title"]), 'item',
dbesc($item["body"]), ['title' => $item['title'], 'body' => $item['body'], 'rendered-html' => $item['rendered-html'], 'rendered-hash' => $item['rendered-hash']],
dbesc($item["rendered-html"]), ['id' => $items['id']]
dbesc($item["rendered-hash"]), );
intval($items[0]["id"])
); logger("Updating public shadow for post ".$items["id"]." - guid ".$item["guid"]." Result: ".print_r($result, true), LOGGER_DEBUG);
logger("Updating public shadow for post ".$items[0]["id"]." - guid ".$item["guid"]." Result: ".print_r($result, true), LOGGER_DEBUG);
} }
public static function deleteThreadFromUri($itemuri, $uid) { public static function deleteThreadFromUri($itemuri, $uid)
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid)); {
$messages = dba::select('item', ['id'], ['uri' => $itemuri, 'uid' => $uid]);
if (DBM::is_result($messages)) { if (DBM::is_result($messages)) {
foreach ($messages as $message) { foreach ($messages as $message) {
@ -1958,8 +1962,9 @@ EOT;
} }
} }
public static function deleteThread($itemid, $itemuri = "") { public static function deleteThread($itemid, $itemuri = "")
$item = q("SELECT `uid` FROM `thread` WHERE `iid` = %d", intval($itemid)); {
$item = dba::select('thread', ['uid'], ['iid' => $itemid]);
if (!DBM::is_result($item)) { if (!DBM::is_result($item)) {
logger('No thread found for id '.$itemid, LOGGER_DEBUG); logger('No thread found for id '.$itemid, LOGGER_DEBUG);