Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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