Old quiz and question attempts deletion

General plugins (Local) ::: local_deleteoldquizattempts
Maintained by Vadim Dvorovenko
Deletes old quiz and question attempts by scheduler task or by CLI command.
Latest release:
214 sites
272 downloads
13 fans
Current versions available: 2

Installation

Copy the deleteoldquizattempts folder into your Moodle /local directory and visit your Admin Notification page to complete the installation.

Usage

Navigate to plugin settings and specify maximum lifetime of quiz attempts. Older attempts will be automatically deleted with scheduler task.

You can also specify to delete unused hidden questions. Hidden questions are questions, that were logically deleted, but were not deleted physically, because they were referenced in some quiz attempts. After quiz attempts deletion, such questions are probably no longer required.

You can also delete quiz attempts and unused hidden questions with command line job.

Deleting quiz attempts with CLI

Dispay help.

sudo -u www-data /usr/bin/php local/deleteoldquizattempts/cli/delete_attempts.php --help

Delete attempts that are older than 90 days and shows progress.

sudo -u www-data /usr/bin/php local/deleteoldquizattempts/cli/delete_attempts.php --days=90 --verbose

Delete attempts that are created before specified timestamp.

sudo -u www-data /usr/bin/php local/deleteoldquizattempts/cli/delete_attempts.php --timestamp=1514764800 --timelimit=300

Delete attempts that are created before 2018-01-01 00:00:00 (UTC).

sudo -u www-data /usr/bin/php local/deleteoldquizattempts/cli/delete_attempts.php --date="2018-01-01 00:00:00"

Delete attempts for specified quiz (check id in *_quiz table).

sudo -u www-data /usr/bin/php local/deleteoldquizattempts/cli/delete_attempts.php --days=90 --quizid=99

Delete attempts for all quizzes in specified course.

sudo -u www-data /usr/bin/php local/deleteoldquizattempts/cli/delete_attempts.php --days=90 --courseid=99

Deleting unused hidden questions with CLI

Dispay help.

sudo -u www-data /usr/bin/php local/deleteoldquizattempts/cli/delete_unused_questions.php --help

Delete unused hidden questions.

sudo -u www-data /usr/bin/php local/deleteoldquizattempts/cli/delete_unused_questions.php --timelimit=300 --verbose

Screenshots

Screenshot #0

Contributors

Vadim Dvorovenko (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Comments

  • Plugins bot
    Sun, 6 Jan 2019, 8:30 PM
    Approval issue created: CONTRIB-7591
  • David Bugyi
    Thu, 29 Oct 2020, 11:57 PM
    Is it possible to modify the plugin to remove attempts based on grades? Thanks,
  • Vadim Dvorovenko
    Fri, 30 Oct 2020, 12:13 AM
    David Bugyi, that's possible, if that boundary grade is same for all courses and quizez, or you can specify, how to find boundary grade. This plugin is intended to do automaticay cleanup to minimize database size. It does not have user interace. If you want to remove attempts based on grade, the boundary grade can be different for different courses and quizez. If you just want to give ability to teacher to remove bad attempts, you need other sort of plugin, wit user interface to specify, with attempts to remove, but you can easyli do this in standart interface, simple by sorting attempts by grade and selecting them in order
  • Phineas Gomez
    Sat, 6 Mar 2021, 2:32 PM
    I think it would be a good update to be able to choose the deletion time for each of the courses, because in my case I have paid courses that I want to be deleted in a period of 1 year, but in the free courses I wanted to reduce it to just 1 month.

    Thanks!!
  • Vadim Dvorovenko
    Sat, 6 Mar 2021, 6:46 PM
    Phineas Gomez. CLI script has option to specify course id and other params. You can specify 1 year in settings, and create additional cron task running CLI script to cleanup for courses with 1 month period.
  • Phineas Gomez
    Sun, 7 Mar 2021, 2:01 AM
    Many thanks Vadim!


    I am using the following code but it doesn't seem to work:
    /usr/bin/php /home/xxxx/mysite.com/moodle/local/deleteoldquizattempts/cli/delete_attempts.php --days=10 --quizid=26


    However I receive this mail from cron, what can be the error?

    X-Powered-By: PHP/7.4.14
    Content-type: text/html; charset=UTF-8

    Delete old quiz and question attempts

    Options:
    --days= Delete attempts that are older than specified number of days
    --timestamp= Delete attempts that are created before specified UTC timestamp
    --date= Delete attempts that are created before specified date.
    Use "YYYY-MM-DD HH:MM:SS" format in UTC
    --courseid= Delete only attempts for quizzes in course with specified id.
    --quizid= Delete only attempts for quiz with specified id.
    --timelimit= Stop execution after specified number of seconds
    -v, --verbose Show progress
    -h, --help Print out this help

    Only one of --days, --timestamp and --date options should be specified.

    Examples:
    php local/deleteoldquizattempts/cli/delete_attempts.php --days=90 --verbose
    php local/deleteoldquizattempts/cli/delete_attempts.php --timestamp=1514764800 --timelimit=300
    php local/deleteoldquizattempts/cli/delete_attempts.php --date="2018-01-01 00:00:00"

  • Vadim Dvorovenko
    Thu, 11 Mar 2021, 1:49 AM
    i've checked, your command and it goes no errors for me.

    first, run from command line to be sure everything works
    /usr/bin/php /home/xxxx/mysite.com/moodle/local/deleteoldquizattempts/cli/delete_attempts.php --days=10 --quizid=26 --verbose

    check that you specified right quizeid by visiting mysite.com/moodle/mod/quiz/view.php?q=26 - quizid is not the same as coursemodule id. Sometimes it's better to look into DB id mdl_quiz table.

    Check your cron syntax, maybe some misprint, command must be the same, that you test in command line. Maybe your cron requires some escaping of params
    When oll is ok, you can add " >/dev/null" to the end of the command to supress output and mails from cron.
  • Phineas Gomez
    Thu, 11 Mar 2021, 8:52 PM
    Thanks Vadim.

    I have tried different configurations: the courseid, quizid option, different types of quizzes and courses ... and none of them work

    I can't use the cPanel terminal because my hosting does not give that option.

    sad
  • Dante Pereyra
    Mon, 29 Nov 2021, 10:20 PM
    Hey Vadim! This is a great idea, exactly what I need to cleanup our moodle database. Now, we have Moodle 2.5+ version and we're not able to upgrade to 2.7
    Do you think this plugin can work for this 2.5+ version?
  • Vadim Dvorovenko
    Sun, 12 Dec 2021, 1:41 AM
    Dante Pereyra, I was newer tested this plugin with 2.5, but you may try. Change 2014051200 in version.php to 2013051400 and try to install it
  • Daninet Bilbao
    Sat, 1 Jan 2022, 7:31 PM
    Dear Vadim. Your plugin just saved my life. (I mantain a single course with 4.800 users, hundreds of attempts everyday, so before I discovered your plugin I had to clean all this just by hand). Thanks A LOT!
    Just a question: is there an way to configure a shorter period than a month? (For example, automatic deletion every 15 days?). Sorry, I'm not an IT expert, I hope it is easy to configure.

    Thanks again
    Daniel
  • Vadim Dvorovenko
    Sun, 2 Jan 2022, 3:37 PM
    Daninet Bilbao, fixed in latest release
  • Daninet Bilbao
    Sun, 2 Jan 2022, 5:28 PM
    Installed! Thanks a lot!

    The (15 / 7 / 3 days) options are simply great. Thanks for your great work, Vadim.
  • Davide Rossi
    Sat, 3 Sept 2022, 5:12 PM
    Hello Vadim. Your plugin is really great and useful. With Moodle 4 it doesn't seem to work anymore. Correct?
  • Matej Konobelj
    Tue, 12 Dec 2023, 12:06 AM
    Has anybody tested on moodle 4.1?
Please login to post comments