return;
}
- q("DELETE FROM `contact` WHERE `id` = %d", intval($id));
+ dba::delete('contact', array('id' => $id));
// Delete the rest in the background
proc_run(PRIORITY_LOW, 'include/remove_contact.php', $id);
}
if (count($contacts) > 1 && $uid == 0 && $contact_id != 0 && $data["url"] != "") {
- dba::e("DELETE FROM `contact` WHERE `nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`",
- normalise_link($data["url"]), $contact_id);
+ dba::delete('contact', array("`nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`",
+ normalise_link($data["url"]), $contact_id));
}
}
$hashtags = array();
$mentions = array();
- $taglist = dba::p("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?) ORDER BY `tid`",
- intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
+ $taglist = dba::select('term', array('type', 'term', 'url'),
+ array("`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION),
+ array('order' => array('tid')));
while ($tag = dba::fetch($taglist)) {
if ($tag["url"] == "") {
proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_photo_albums");
// Delete all done workerqueue entries
- dba::e('DELETE FROM `workerqueue` WHERE `done` AND `executed` < UTC_TIMESTAMP() - INTERVAL 12 HOUR');
+ dba::delete('workerqueue', array('`done` AND `executed` < UTC_TIMESTAMP() - INTERVAL 12 HOUR'));
}
// Poll contacts
*
*/
function poller_kill_stale_workers() {
- $entries = dba::p("SELECT `id`, `pid`, `executed`, `priority`, `parameter` FROM `workerqueue` WHERE `executed` > ? AND NOT `done` AND `pid` != 0 ORDER BY `priority`, `created`", NULL_DATE);
-
+ $entries = dba::select('workerqueue', array('id', 'pid', 'executed', 'priority', 'parameter'),
+ array('`executed` > ? AND NOT `done` AND `pid` != 0', NULL_DATE),
+ array('order' => array('priority', 'created')));
while ($entry = dba::fetch($entries)) {
if (!posix_kill($entry["pid"], 0)) {
dba::update('workerqueue', array('executed' => NULL_DATE, 'pid' => 0),
if (poller_passing_slow($highest_priority)) {
// Are there waiting processes with a higher priority than the currently highest?
- $result = dba::p("SELECT `id` FROM `workerqueue`
- WHERE `executed` <= ? AND `priority` < ? AND NOT `done`
- ORDER BY `priority`, `created` LIMIT ".intval($limit),
- NULL_DATE, $highest_priority);
+ $result = dba::select('workerqueue', array('id'), array("`executed` <= ? AND `priority` < ? AND NOT `done`", NULL_DATE, $highest_priority),
+ array('limit' => $limit, 'order' => array('priority', 'created'), 'only_query' => true));
while ($id = dba::fetch($result)) {
$ids[] = $id["id"];
if (!$found) {
// Give slower processes some processing time
- $result = dba::p("SELECT `id` FROM `workerqueue`
- WHERE `executed` <= ? AND `priority` > ? AND NOT `done`
- ORDER BY `priority`, `created` LIMIT ".intval($limit),
- NULL_DATE, $highest_priority);
+ $result = dba::select('workerqueue', array('id'), array("`executed` <= ? AND `priority` > ? AND NOT `done`", NULL_DATE, $highest_priority),
+ array('limit' => $limit, 'order' => array('priority', 'created'), 'only_query' => true));
while ($id = dba::fetch($result)) {
$ids[] = $id["id"];
// If there is no result (or we shouldn't pass lower processes) we check without priority limit
if (!$found) {
- $result = dba::p("SELECT `id` FROM `workerqueue` WHERE `executed` <= ? AND NOT `done` ORDER BY `priority`, `created` LIMIT ".intval($limit), NULL_DATE);
+ $result = dba::select('workerqueue', array('id'), array("`executed` <= ? AND NOT `done`", NULL_DATE),
+ array('limit' => $limit, 'order' => array('priority', 'created'), 'only_query' => true));
while ($id = dba::fetch($result)) {
$ids[] = $id["id"];
}
if ($found) {
- $sql = "UPDATE `workerqueue` SET `executed` = ?, `pid` = ? WHERE `id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`;";
- array_unshift($ids, datetime_convert(), $mypid);
- dba::e($sql, $ids);
+ $condition = "`id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`";
+ array_unshift($ids, $condition);
+ dba::update('workerqueue', array('executed' => datetime_convert(), 'pid' => $mypid), $ids);
}
return $found;
if (dbm::is_result($servers) && ($orig_server_url == $server_url) &&
($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
- dba::p("UPDATE `gserver` SET `last_failure` = ? WHERE `nurl` = ?", datetime_convert(), normalise_link($server_url));
+ dba::update('gserver', array('last_failure' => datetime_convert()), array('nurl' => normalise_link($server_url)));
return false;
}
// Quit if there is a timeout
if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) {
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
- dba::p("UPDATE `gserver` SET `last_failure` = ? WHERE `nurl` = ?", datetime_convert(), normalise_link($server_url));
+ dba::update('gserver', array('last_failure' => datetime_convert()), array('nurl' => normalise_link($server_url)));
return false;
}
function update_threads() {
logger("update_threads: start");
- $messages = dba::p("SELECT `id` FROM `item` WHERE `id` = `parent`");
+ $messages = dba::select('item', array('id'), array("`id` = `parent`"));
logger("update_threads: fetched messages: ".dba::num_rows($messages));
function update_shadow_copy() {
logger("start");
- $messages = dba::p("SELECT `iid` FROM `thread` WHERE `uid` != 0 AND `network` IN ('', ?, ?, ?)
- AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private` ORDER BY `created`",
- NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS);
+ $condition = "`uid` != 0 AND `network` IN ('', ?, ?, ?) AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private`";
+ $messages = dba::select('thread', array('iid'), array($condition, NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS),
+ array('order' => 'created'));
logger("fetched messages: ".dba::num_rows($messages));
while ($message = dba::fetch($messages))
// We really should change this need for the future since it scales very bad.
$contactid = get_contact($r['owner-link'], local_user());
if ($contactid) {
- $items = dba::p("SELECT * FROM `item` WHERE `parent` = ? ORDER BY `id`", $r["id"]);
+ $items = dba::select('item', array(), array('parent' => $r["id"]), array('order' => array('id')));
while ($item = dba::fetch($items)) {
$itemcontactid = get_contact($item['owner-link'], local_user());
if (!$itemcontactid) {