Instantly share code, notes, and snippets.

What would you like to do?
PHP7 script for GNU Social that deletes older posts (3 months)
//Originally from by
//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
//Make sure to check and/or change these options
$howfarback="-3 months"; //Check for syntax
$oldate=date(("Y-m-d"), strtotime($howfarback));
if (!$link = mysqli_connect($server, $username, $password)) {
echo "Could not connect to mariadb";
if (!mysqli_select_db($link, $database)) {
echo "Could not select gnusocial database";
$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);
mysqli_query($link, $conversation_query);
mysqli_query($link, $reply_query);
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