Skip to content

Instantly share code, notes, and snippets.

@mitchellurgero
Created April 5, 2017 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchellurgero/daf633fdfcf5958486c95c56d7d898a1 to your computer and use it in GitHub Desktop.
Save mitchellurgero/daf633fdfcf5958486c95c56d7d898a1 to your computer and use it in GitHub Desktop.
PHP7 script for GNU Social that deletes older posts (3 months)
<?php
//Originally from https://ghostbin.com/paste/xjeud by https://social.freedombone.net/bob
//Re-writen to use PHP7.x MySQLi functions as mysql_*() are REMOVED in php7.0
// gnusocial post expiry script, based on StatExpire by Tony Baldwin
// https://github.com/tonybaldwin/statexpire
//Make sure to check and/or change these options
$howfarback="-3 months"; //Check http://php.net/manual/en/function.strtotime.php for syntax
$server="localhost";
$username="username";
$password="password";
$database="gnusocial";
$oldate=date(("Y-m-d"), strtotime($howfarback));
if (!$link = mysqli_connect($server, $username, $password)) {
echo "Could not connect to mariadb";
exit;
}
if (!mysqli_select_db($link, $database)) {
echo "Could not select gnusocial database";
exit;
}
$notice_query="DELETE FROM notice WHERE created <= '$oldate 01:01:01'";
$conversation_query="DELETE FROM conversation WHERE created <= ' 01:01:01'";
$reply_query="DELETE FROM reply WHERE modified <= '$oldate 01:01:01'";
mysqli_query($link, $notice_query);
$rowaff1=mysqli_affected_rows($link);
mysqli_query($link, $conversation_query);
$rowaff2=mysqli_affected_rows($link);
mysqli_query($link, $reply_query);
$rowaff3=mysqli_affected_rows($link);
mysqli_close($link);
echo "Expire gnusocial posts: $rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment