My Site getting Spammed spammer creating blog post which i want to delete all blogs

My Site getting Spammed spammer creating blog post which i want to delete all blogs, is there a way to delete all blogs of all users at once ? also is there a way to turn of Blog feature, i have capthca enabled also user needs to upload photo to sign up een inspite of it spammer creating profile and blog every second, so first want to delete all blogs of all users and want to turn of blog feature

  • Delete the user and all the blogs for the user will be deleted.

  • @Rohith There were too many users spammers is created like every new user every 5 min so its 100s of users got created and thousands of junk blogs, so i was looking for how to delete all blogs? also i turned off new registrations now ... there is a captcha to answer and photo to upload as mandatory still i dont know how they can automate and create so much of spam users and junk blogs, any idea?  

  • how to delete all blogs? 

    This function will delete ALL blog posts from your site:

    function deleteBlogs() {
        $blogs = elgg_get_entities([
            'type' => 'object',
            'subtype' => 'blog',
            'limit' => false,
            'batch' => true,
            'batch_inc_offset' => false,
        ]);
        foreach ($blogs as $blog) {
            if ($blog) {
                $blog->delete();
            }
        }
    }

    i dont know how they can automate and create so much of spam users and junk blogs

    They use tools for bulk account creation and posting, for example, xrumer.

    You can never completely get rid of spam. You need additional protection at the server configuration level.

  • @Rvr i executed the above pieced of code my site crashed and from error logs i can get this  

    [Thu Apr 18 11:25:18.496089 2019] [php7:notice] [pid 25773] [client 54.36.150.36:17992] Exception at time 1555586718 : fatal error in exception handler : An exception occured in driver: SQLSTATE[HY000] [1040] Too many connections

  • @Rvr i rebooted mysql issue resolved, it seems like there is limitation on number f connection to mysql to have, how to limit connnection to say 10?

  • Set in above code:

    'limit' => 10,