Many item calls are now isolated in a single function

This commit is contained in:
Michael 2018-02-06 12:40:22 +00:00
commit e609de2957
23 changed files with 161 additions and 387 deletions

View file

@ -505,7 +505,7 @@ function admin_page_deleteitem_post(App $a)
// associated threads.
$r = dba::select('item', ['id'], ['guid' => $guid]);
while ($row = dba::fetch($r)) {
Item::delete($row['id']);
Item::deleteById($row['id']);
}
dba::close($r);
}

View file

@ -348,9 +348,6 @@ function _contact_archive($contact_id, $orig_record)
intval($contact_id),
intval(local_user())
);
if ($archived) {
q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
}
return DBM::is_result($r);
}

View file

@ -550,7 +550,7 @@ function events_content(App $a) {
// Delete only real events (no birthdays)
if (DBM::is_result($ev) && $ev[0]['type'] == 'event') {
$del = Item::delete($ev[0]['itemid']);
$del = Item::deleteById($ev[0]['itemid']);
}
if ($del == 0) {

View file

@ -876,7 +876,7 @@ function item_content(App $a) {
$o = '';
if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
if (is_ajax()) {
$o = Item::delete($a->argv[2]);
$o = Item::deleteById($a->argv[2]);
} else {
$o = drop_item($a->argv[2]);
}

View file

@ -17,6 +17,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Module\Login;
use Friendica\Util\DateTimeFormat;
@ -326,7 +327,7 @@ function networkSetSeen($condition)
$unseen = dba::exists('item', $condition);
if ($unseen) {
$r = dba::update('item', ['unseen' => false], $condition);
$r = Item::update(['unseen' => false], $condition);
}
}

View file

@ -285,25 +285,12 @@ function photos_post(App $a)
);
// find and delete the corresponding item with all the comments and likes/dislikes
$r = q("SELECT `id`, `parent-uri`, `visible` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
$r = q("SELECT `id` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
intval($page_owner_uid)
);
if (DBM::is_result($r)) {
foreach ($r as $rr) {
q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
dbesc(DateTimeFormat::utcNow()),
dbesc($rr['parent-uri']),
intval($page_owner_uid)
);
Term::insertFromTagFieldByItemUri($rr['parent-uri'], $page_owner_uid);
Item::deleteThreadByUri($rr['parent-uri'], $page_owner_uid);
$drop_id = intval($rr['id']);
// send the notification upstream/downstream as the case may be
if ($rr['visible']) {
Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
}
Item::deleteById($rr['id']);
}
}
@ -358,29 +345,15 @@ function photos_post(App $a)
intval($page_owner_uid),
dbesc($r[0]['resource-id'])
);
$i = q("SELECT `id`, `uri`, `visible` FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
$i = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
dbesc($r[0]['resource-id']),
intval($page_owner_uid)
);
if (DBM::is_result($i)) {
q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
dbesc(DateTimeFormat::utcNow()),
dbesc(DateTimeFormat::utcNow()),
dbesc($i[0]['uri']),
intval($page_owner_uid)
);
Term::insertFromTagFieldByItemUri($i[0]['uri'], $page_owner_uid);
Item::deleteThreadByUri($i[0]['uri'], $page_owner_uid);
$url = System::baseUrl();
$drop_id = intval($i[0]['id']);
Item::deleteById($i[0]['id']);
// Update the photo albums cache
Photo::clearAlbumCache($page_owner_uid);
if ($i[0]['visible']) {
Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
}
}
}
@ -646,16 +619,9 @@ function photos_post(App $a)
}
$newinform .= $inform;
$r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc($newtag),
dbesc($newinform),
dbesc(DateTimeFormat::utcNow()),
dbesc(DateTimeFormat::utcNow()),
intval($item_id),
intval($page_owner_uid)
);
Term::insertFromTagFieldByItemId($item_id);
Item::updateThread($item_id);
$fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
$condition = ['id' => $item_id];
Item::update($fields, $condition);
$best = 0;
foreach ($p as $scales) {
@ -1427,11 +1393,7 @@ function photos_content(App $a)
);
if (local_user() && (local_user() == $link_item['uid'])) {
q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
intval($link_item['parent']),
intval(local_user())
);
Item::updateThread($link_item['parent']);
Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
}
if ($link_item['coord']) {

View file

@ -135,11 +135,6 @@ function poke_init(App $a) {
$item_id = Item::insert($arr);
if($item_id) {
//q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
// dbesc(System::baseUrl() . '/display/' . $poster['nickname'] . '/' . $item_id),
// intval($uid),
// intval($item_id)
//);
Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
}

View file

@ -13,6 +13,7 @@ use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Module\Login;
use Friendica\Protocol\DFRN;
@ -359,7 +360,7 @@ function profile_content(App $a, $update = 0)
if ($is_owner) {
$unseen = dba::exists('item', ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
if ($unseen) {
$r = dba::update('item', ['unseen' => false],
$r = Item::update(['unseen' => false],
['wall' => true, 'unseen' => true, 'uid' => local_user()]);
}
}

View file

@ -32,13 +32,7 @@ function starred_init(App $a) {
$starred = 1;
}
$r = q("UPDATE `item` SET `starred` = %d WHERE `uid` = %d AND `id` = %d",
intval($starred),
intval(local_user()),
intval($message_id)
);
Item::updateThread($message_id);
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'] : '');

View file

@ -152,11 +152,8 @@ EOT;
$post_id = Item::insert($arr);
if (! $item['visible']) {
$r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
intval($item['id']),
intval($owner_uid)
);
if (!$item['visible']) {
Item::update(['visible' => true], ['id' => $item['id']]);
}
$arr['id'] = $post_id;

View file

@ -148,24 +148,16 @@ EOT;
$post_id = Item::insert($arr);
if(! $item['visible']) {
$r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
intval($item['id']),
intval($owner_uid)
);
if (!$item['visible']) {
Item::update(['visible' => true], ['id' => $item['id']]);
}
$term_objtype = (($item['resource-id']) ? TERM_OBJ_PHOTO : TERM_OBJ_POST );
$term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
$t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
intval($item['id']),
dbesc($term)
);
if((! $blocktags) && $t[0]['tcount']==0 ) {
/*q("update item set tag = '%s' where id = %d",
dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . System::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
intval($item['id'])
);*/
q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
intval($item['id']),
$term_objtype,
@ -199,14 +191,6 @@ EOT;
intval($owner_uid)
);
}
/*if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
q("update item set tag = '%s' where id = %d",
dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . System::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
intval($r[0]['id'])
);
}*/
}
@ -219,6 +203,4 @@ EOT;
killme();
return; // NOTREACHED
}

View file

@ -6,12 +6,13 @@ use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Item;
require_once 'include/bbcode.php';
function tagrm_post(App $a) {
if (! local_user()) {
if (!local_user()) {
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
}
@ -27,7 +28,7 @@ function tagrm_post(App $a) {
intval(local_user())
);
if (! DBM::is_result($r)) {
if (!DBM::is_result($r)) {
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
}
@ -41,17 +42,12 @@ function tagrm_post(App $a) {
$tag_str = implode(',',$arr);
q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc($tag_str),
intval($item),
intval(local_user())
);
Item::update(['tag' => $tag_str], ['id' => $item]);
info(L10n::t('Tag removed') . EOL );
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
// NOTREACHED
}
@ -60,13 +56,13 @@ function tagrm_content(App $a) {
$o = '';
if (! local_user()) {
if (!local_user()) {
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
// NOTREACHED
}
$item = (($a->argc > 1) ? intval($a->argv[1]) : 0);
if (! $item) {
if (!$item) {
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
// NOTREACHED
}
@ -76,13 +72,13 @@ function tagrm_content(App $a) {
intval(local_user())
);
if (! DBM::is_result($r)) {
if (!DBM::is_result($r)) {
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
}
$arr = explode(',', $r[0]['tag']);
if (! count($arr)) {
if (!count($arr)) {
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
}

View file

@ -165,27 +165,13 @@ function videos_post(App $a) {
intval(local_user()),
dbesc($video_id)
);
$i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
$i = q("SELECT `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
dbesc($video_id),
intval(local_user())
);
//echo "<pre>"; var_dump($i); killme();
if (DBM::is_result($i)) {
q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
dbesc(DateTimeFormat::utcNow()),
dbesc(DateTimeFormat::utcNow()),
dbesc($i[0]['uri']),
intval(local_user())
);
Term::insertFromTagFieldByItemUri($i[0]['uri'], local_user());
Item::deleteThreadByUri($i[0]['uri'], local_user());
$url = System::baseUrl();
$drop_id = intval($i[0]['id']);
if ($i[0]['visible']) {
Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
}
Item::deleteById($i[0]['id']);
}
}