From 03b86d37662c59b5ec838105c3e6801b453d8996 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 9 Aug 2017 23:02:57 +0000 Subject: [PATCH] Now we have less than 100 insert commands, yeah --- include/fcontact.php | 12 ++---------- include/group.php | 13 ++----------- include/oembed.php | 2 +- include/plugin.php | 17 +++++------------ src/App.php | 2 +- src/ParseUrl.php | 8 +++----- 6 files changed, 14 insertions(+), 40 deletions(-) diff --git a/include/fcontact.php b/include/fcontact.php index b2706e51a0..a559ede300 100644 --- a/include/fcontact.php +++ b/include/fcontact.php @@ -13,11 +13,7 @@ function fcontact_store($url,$name,$photo) { if (dbm::is_result($r)) return $r[0]['id']; - $r = q("INSERT INTO `fcontact` ( `url`, `name`, `photo` ) VALUES ( '%s', '%s', '%s' ) ", - dbesc($nurl), - dbesc($name), - dbesc($photo) - ); + $r = dba::insert('fcontact', array('url' => $nurl, 'name' => $name, 'photo' => $photo)); if (dbm::is_result($r)) { $r = q("SELECT `id` FROM `fcontact` WHERE `url` = '%s' LIMIT 1", @@ -31,11 +27,7 @@ function fcontact_store($url,$name,$photo) { } function ffinder_store($uid,$cid,$fid) { - $r = q("INSERT INTO `ffinder` ( `uid`, `cid`, `fid` ) VALUES ( %d, %d, %d ) ", - intval($uid), - intval($cid), - intval($fid) - ); + $r = dba::insert('ffinder', array('uid' => $uid, 'cid' => $cid, 'fid' => $fid)); return $r; } diff --git a/include/group.php b/include/group.php index ab805e6874..8956d21c31 100644 --- a/include/group.php +++ b/include/group.php @@ -26,11 +26,7 @@ function group_add($uid,$name) { } return true; } - $r = q("INSERT INTO `group` ( `uid`, `name` ) - VALUES( %d, '%s' ) ", - intval($uid), - dbesc($name) - ); + $r = dba::insert('group', array('uid' => $uid, 'name' => $name)); $ret = $r; } return $ret; @@ -144,12 +140,7 @@ function group_add_member($uid,$name,$member,$gid = 0) { // we indicate success because the group member was in fact created // -- It was just created at another time if (! dbm::is_result($r)) { - $r = q("INSERT INTO `group_member` (`uid`, `gid`, `contact-id`) - VALUES( %d, %d, %d ) ", - intval($uid), - intval($gid), - intval($member) - ); + $r = dba::insert('group_member', array('uid' => $uid, 'gid' => $gid, 'contact-id' => $member)); } return $r; } diff --git a/include/oembed.php b/include/oembed.php index de597bbb37..cb23517cdb 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -83,7 +83,7 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){ $j = json_decode($txt); if ($j->type != "error") { dba::insert('oembed', array('url' => normalise_link($embedurl), - 'content' => $txt, 'created' => datetime_convert())); + 'content' => $txt, 'created' => datetime_convert()), true); } Cache::set($a->videowidth.$embedurl, $txt, CACHE_DAY); diff --git a/include/plugin.php b/include/plugin.php index 60ef6138b9..3a24235754 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -46,13 +46,10 @@ function install_plugin($plugin) { $func = $plugin . '_install'; $func(); - $plugin_admin = (function_exists($plugin."_plugin_admin")?1:0); + $plugin_admin = (function_exists($plugin."_plugin_admin") ? 1 : 0); - $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ", - dbesc($plugin), - intval($t), - $plugin_admin - ); + dba::insert('addon', array('name' => $plugin, 'installed' => true, + 'timestamp' => $t, 'plugin_admin' => $plugin_admin)); // we can add the following with the previous SQL // once most site tables have been updated. @@ -154,12 +151,8 @@ function register_hook($hook,$file,$function,$priority=0) { if (dbm::is_result($r)) return true; - $r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`) VALUES ( '%s', '%s', '%s', '%s' ) ", - dbesc($hook), - dbesc($file), - dbesc($function), - dbesc($priority) - ); + $r = dba::insert('hook', array('hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority)); + return $r; }} diff --git a/src/App.php b/src/App.php index 4cdaa94ccd..c416a0b126 100644 --- a/src/App.php +++ b/src/App.php @@ -717,7 +717,7 @@ class App { $r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid())); if (!dbm::is_result($r)) { - q("INSERT INTO `process` (`pid`,`command`,`created`) VALUES (%d, '%s', '%s')", intval(getmypid()), dbesc($command), dbesc(datetime_convert())); + dba::insert('process', array('pid' => getmypid(), 'command' => $command, 'created' => datetime_convert())); } dba::commit(); } diff --git a/src/ParseUrl.php b/src/ParseUrl.php index 9e21736a84..0de7663e40 100644 --- a/src/ParseUrl.php +++ b/src/ParseUrl.php @@ -66,11 +66,9 @@ class ParseUrl { $data = self::getSiteinfo($url, $no_guessing, $do_oembed); - q("INSERT INTO `parsed_url` (`url`, `guessing`, `oembed`, `content`, `created`) VALUES ('%s', %d, %d, '%s', '%s') - ON DUPLICATE KEY UPDATE `content` = '%s', `created` = '%s'", - dbesc(normalise_link($url)), intval(!$no_guessing), intval($do_oembed), - dbesc(serialize($data)), dbesc(datetime_convert()), - dbesc(serialize($data)), dbesc(datetime_convert())); + dba::insert('parsed_url', array('url' => normalise_link($url), 'guessing' => !$no_guessing, + 'oembed' => $do_oembed, 'content' => serialize($data), + 'created' => datetime_convert()), true); return $data; }