Improved SQL scripts

pull/185/head
Michael Vogel 2014-03-16 19:13:57 +01:00
parent 0568a5d8bb
commit c4578aafa0
6 changed files with 44 additions and 43 deletions

View File

@ -75,8 +75,8 @@ function communityhome_home(&$a, &$o){
// this query don't work on some mysql versions // this query don't work on some mysql versions
if (get_config('communityhome','showactiveusers')===true){ if (get_config('communityhome','showactiveusers')===true){
$r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM $r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM
(SELECT COUNT(`id`) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`, (SELECT COUNT(*) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`,
(SELECT COUNT(`id`) as `items`, `uid` FROM `item` WHERE `item`.`changed` > DATE(NOW() - INTERVAL 1 MONTH) AND `item`.`wall` = 1 GROUP BY `uid`) AS `ite`, (SELECT COUNT(*) as `items`, `uid` FROM `item` WHERE `item`.`changed` > DATE(NOW() - INTERVAL 1 MONTH) AND `item`.`wall` = 1 GROUP BY `uid`) AS `ite`,
( (
SELECT `contacts`,`items`,`ite`.`uid` FROM `con` RIGHT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid` SELECT `contacts`,`items`,`ite`.`uid` FROM `con` RIGHT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
UNION ALL UNION ALL

View File

@ -289,7 +289,7 @@ function fb_get_friends_sync_parsecontact($uid, $contact) {
`name-date` = '%s', `name-date` = '%s',
`uri-date` = '%s', `uri-date` = '%s',
`avatar-date` = '%s' `avatar-date` = '%s'
WHERE `id` = %d LIMIT 1 WHERE `id` = %d
", ",
dbesc($photos[0]), dbesc($photos[0]),
dbesc($photos[1]), dbesc($photos[1]),
@ -356,7 +356,7 @@ function fb_get_friends_sync_parsecontact($uid, $contact) {
`name-date` = '%s', `name-date` = '%s',
`uri-date` = '%s', `uri-date` = '%s',
`avatar-date` = '%s' `avatar-date` = '%s'
WHERE `id` = %d LIMIT 1 WHERE `id` = %d
", ",
dbesc($photos[0]), dbesc($photos[0]),
dbesc($photos[1]), dbesc($photos[1]),
@ -1171,7 +1171,7 @@ function facebook_post_hook(&$a,&$b) {
$retj = json_decode($x); $retj = json_decode($x);
if($retj->id) { if($retj->id) {
q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d LIMIT 1", q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d",
dbesc('fb::' . $retj->id), dbesc('fb::' . $retj->id),
intval($b['id']) intval($b['id'])
); );
@ -1307,7 +1307,7 @@ function fb_queue_hook(&$a,&$b) {
$retj = json_decode($j); $retj = json_decode($j);
if($retj->id) { if($retj->id) {
q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d LIMIT 1", q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d",
dbesc('fb::' . $retj->id), dbesc('fb::' . $retj->id),
intval($item) intval($item)
); );

View File

@ -36,7 +36,7 @@ function public_server_register_account($a,$b) {
if(! $days) if(! $days)
return; return;
$r = q("UPDATE user set account_expires_on = '%s', expire = %d where uid = %d limit 1", $r = q("UPDATE user set account_expires_on = '%s', expire = %d where uid = %d",
dbesc(datetime_convert('UTC','UTC','now +' . $days . ' days')), dbesc(datetime_convert('UTC','UTC','now +' . $days . ' days')),
intval($days_posts), intval($days_posts),
intval($uid) intval($uid)
@ -66,7 +66,7 @@ function public_server_cron($a,$b) {
'source_photo' => $a->get_baseurl() . '/images/person-80.jpg', 'source_photo' => $a->get_baseurl() . '/images/person-80.jpg',
)); ));
q("update user set expire_notification_sent = '%s' where uid = %d limit 1", q("update user set expire_notification_sent = '%s' where uid = %d",
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval($rr['uid']) intval($rr['uid'])
); );
@ -85,7 +85,7 @@ function public_server_cron($a,$b) {
$r = q("select uid from user where account_expired = 0 and login_date = '0000-00-00 00:00:00' and register_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00'",intval($nologin)); $r = q("select uid from user where account_expired = 0 and login_date = '0000-00-00 00:00:00' and register_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00'",intval($nologin));
if(count($r)) { if(count($r)) {
foreach($r as $rr) foreach($r as $rr)
q("update user set account_expires_on = '%s' where uid = %d limit 1", q("update user set account_expires_on = '%s' where uid = %d",
dbesc(datetime_convert('UTC','UTC','now +' . '6 days')), dbesc(datetime_convert('UTC','UTC','now +' . '6 days')),
intval($rr['uid']) intval($rr['uid'])
); );
@ -98,7 +98,7 @@ function public_server_cron($a,$b) {
$r = q("select uid from user where account_expired = 0 and login_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00' and `page-flags` = 0",intval($flagusers)); $r = q("select uid from user where account_expired = 0 and login_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00' and `page-flags` = 0",intval($flagusers));
if(count($r)) { if(count($r)) {
foreach($r as $rr) foreach($r as $rr)
q("update user set account_expires_on = '%s' where uid = %d limit 1", q("update user set account_expires_on = '%s' where uid = %d",
dbesc(datetime_convert('UTC','UTC','now +' . '6 days')), dbesc(datetime_convert('UTC','UTC','now +' . '6 days')),
intval($rr['uid']) intval($rr['uid'])
); );
@ -111,7 +111,7 @@ function public_server_cron($a,$b) {
$r = q("select uid from user where account_expired = 0 and login_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00' and expire = 0 and `page-flags` = 0",intval($flagposts)); $r = q("select uid from user where account_expired = 0 and login_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00' and expire = 0 and `page-flags` = 0",intval($flagposts));
if(count($r)) { if(count($r)) {
foreach($r as $rr) foreach($r as $rr)
q("update user set expire = %d where uid = %d limit 1", q("update user set expire = %d where uid = %d",
intval($flagpostsexpire), intval($flagpostsexpire),
intval($rr['uid']) intval($rr['uid'])
); );
@ -136,7 +136,7 @@ function public_server_login($a,$b) {
$days = get_config('public_server','expiredays'); $days = get_config('public_server','expiredays');
if(! $days) if(! $days)
return; return;
$r = q("UPDATE user set account_expires_on = '%s' where uid = %d and account_expires_on > '0000-00-00 00:00:00' limit 1", $r = q("UPDATE user set account_expires_on = '%s' where uid = %d and account_expires_on > '0000-00-00 00:00:00'",
dbesc(datetime_convert('UTC','UTC','now +' . $days . ' days')), dbesc(datetime_convert('UTC','UTC','now +' . $days . ' days')),
local_user() local_user()
); );

View File

@ -1022,6 +1022,7 @@ function pumpio_dodelete(&$a, $uid, $self, $post, $own_id) {
function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcompletion = false) { function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcompletion = false) {
require_once('include/items.php'); require_once('include/items.php');
require_once('include/html2bbcode.php');
if (($post->verb == "like") OR ($post->verb == "favorite")) if (($post->verb == "like") OR ($post->verb == "favorite"))
return pumpio_dolike($a, $uid, $self, $post, $own_id); return pumpio_dolike($a, $uid, $self, $post, $own_id);

View File

@ -41,7 +41,7 @@ function testdrive_register_account($a,$b) {
if(! $days) if(! $days)
return; return;
$r = q("UPDATE user set account_expires_on = '%s' where uid = %d limit 1", $r = q("UPDATE user set account_expires_on = '%s' where uid = %d",
dbesc(datetime_convert('UTC','UTC','now +' . $days . ' days')), dbesc(datetime_convert('UTC','UTC','now +' . $days . ' days')),
intval($uid) intval($uid)
); );
@ -69,7 +69,7 @@ function testdrive_cron($a,$b) {
'source_photo' => $a->get_baseurl() . '/images/person-80.jpg', 'source_photo' => $a->get_baseurl() . '/images/person-80.jpg',
)); ));
q("update user set expire_notification_sent = '%s' where uid = %d limit 1", q("update user set expire_notification_sent = '%s' where uid = %d",
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval($rr['uid']) intval($rr['uid'])
); );