function updateGroupUrls() { printfnq("Updating group URLs...\n"); $group = new User_group(); if ($group->find()) { while ($group->fetch()) { try { printfv("Updating group {$group->nickname}..."); $orig = User_group::getKV('id', $group->id); if (!empty($group->original_logo)) { $group->original_logo = Avatar::url(basename($group->original_logo)); $group->homepage_logo = Avatar::url(basename($group->homepage_logo)); $group->stream_logo = Avatar::url(basename($group->stream_logo)); $group->mini_logo = Avatar::url(basename($group->mini_logo)); } // XXX: this is a hack to see if a group is local or not $localUri = common_local_url('groupbyid', array('id' => $group->id)); if ($group->getUri() != $localUri) { $group->mainpage = common_local_url('showgroup', array('nickname' => $group->nickname)); } $group->update($orig); printfv("DONE."); } catch (Exception $e) { echo "Can't update avatars for group " . $group->nickname . ": " . $e->getMessage(); } } } }
function silencespammer($filter, $user, $minimum, $percent) { printfnq("Testing user %s\n", $user->nickname); $profile = Profile::getKV('id', $user->id); if ($profile->isSilenced()) { printfnq("Already silenced %s\n", $user->nickname); return; } $cnt = $profile->noticeCount(); if ($cnt < $minimum) { printfnq("Only %d notices posted (minimum %d); skipping\n", $cnt, $minimum); return; } $ss = new Spam_score(); $ss->query(sprintf("SELECT count(*) as spam_count " . "FROM notice join spam_score on notice.id = spam_score.notice_id " . "WHERE notice.profile_id = %d AND spam_score.is_spam = 1", $profile->id)); while ($ss->fetch()) { $spam_count = $ss->spam_count; } $spam_percent = $spam_count * 100.0 / $cnt; if ($spam_percent > $percent) { printfnq("Silencing user %s (%d/%d = %0.2f%% spam)\n", $user->nickname, $spam_count, $cnt, $spam_percent); try { $profile->silence(); } catch (Exception $e) { printfnq("Error: %s", $e->getMessage()); } } }
function testUser($filter, $user) { printfnq("Testing user %s\n", $user->nickname); $profile = Profile::getKV('id', $user->id); $str = new ProfileNoticeStream($profile, $profile); $offset = 0; $limit = 100; do { $notice = $str->getNotices($offset, $limit); while ($notice->fetch()) { try { printfv("Testing notice %d...", $notice->id); $result = $filter->test($notice); Spam_score::save($notice, $result); printfv("%s\n", $result->isSpam ? "SPAM" : "HAM"); } catch (Exception $e) { printfnq("ERROR testing notice %d: %s\n", $notice->id, $e->getMessage()); } } $offset += $notice->N; } while ($notice->N > 0); }
public function onEndUpgrade() { printfnq("Ensuring all faves have a URI..."); $fave = new Fave(); $fave->whereAdd('uri IS NULL'); if ($fave->find()) { while ($fave->fetch()) { try { $fave->decache(); $fave->query(sprintf('UPDATE fave ' . 'SET uri = "%s", ' . ' modified = "%s" ' . 'WHERE user_id = %d ' . 'AND notice_id = %d', Fave::newUri($fave->getActor(), $fave->getTarget(), $fave->modified), common_sql_date(strtotime($fave->modified)), $fave->user_id, $fave->notice_id)); } catch (Exception $e) { common_log(LOG_ERR, "Error updating fave URI: " . $e->getMessage()); } } } printfnq("DONE.\n"); }
function initProfileLists() { printfnq("Ensuring all profile tags have a corresponding list..."); $ptag = new Profile_tag(); $ptag->selectAdd(); $ptag->selectAdd('tagger, tag, count(*) as tagged_count'); $ptag->whereAdd('NOT EXISTS (SELECT tagger, tagged from profile_list ' . 'where profile_tag.tagger = profile_list.tagger ' . 'and profile_tag.tag = profile_list.tag)'); $ptag->groupBy('tagger, tag'); $ptag->orderBy('tagger, tag'); if ($ptag->find()) { while ($ptag->fetch()) { $plist = new Profile_list(); $plist->tagger = $ptag->tagger; $plist->tag = $ptag->tag; $plist->private = 0; $plist->created = common_sql_now(); $plist->modified = $plist->created; $plist->mainpage = common_local_url('showprofiletag', array('tagger' => $plist->getTagger()->nickname, 'tag' => $plist->tag)); $plist->tagged_count = $ptag->tagged_count; $plist->subscriber_count = 0; $plist->insert(); $orig = clone $plist; // After insert since it uses auto-generated ID $plist->uri = common_local_url('profiletagbyid', array('id' => $plist->id, 'tagger_id' => $plist->tagger)); $plist->update($orig); } } printfnq("DONE.\n"); }
function setFilehashOnLocalFiles() { printfnq('Ensuring all local files have the filehash field set...'); $file = new File(); $file->whereAdd('filename IS NOT NULL'); // local files $file->whereAdd('filehash IS NULL', 'AND'); // without filehash value if ($file->find()) { while ($file->fetch()) { try { $orig = clone $file; $file->filehash = hash_file(File::FILEHASH_ALG, $file->getPath()); $file->update($orig); } catch (FileNotFoundException $e) { echo "\n WARNING: file ID {$file->id} does not exist on path '{$e->path}'. If there is no file system error, run: php scripts/clean_file_table.php"; } } } printfnq("DONE.\n"); }