Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Automatic Course Archival: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
Line 41: Line 41:
|"enabled"
|"enabled"
|tinyint(1)
|tinyint(1)
|1
|<center>1</center>
|If automatic archiving/deleting should be enabled for this course.
|If automatic archiving/deleting should be enabled for this course.
|-
|-
|"archive_date_type"
|"archive_date_type"
|varchar(10)
|varchar(10)
|NULL
|<center>NULL</center>
|Can be 'relative', 'absolute', or NULL; If NULL, this course should not be automatically archived. If 'relative', the value stored in archive_date is the number of days after the end of the course. If 'absolute', the value stored in archive_date is a Unix timestamp.
|Can be 'relative', 'absolute', or NULL; If NULL, this course should not be automatically archived. If 'relative', the value stored in archive_date is the number of days after the end of the course. If 'absolute', the value stored in archive_date is a Unix timestamp.
|-
|-
|"archive_date"
|"archive_date"
|int(10)
|int(10)
|NULL
|<center>NULL</center>
|When the course should be archived. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the archive_date_type column.
|When the course should be archived. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the archive_date_type column.
|-
|-
|"delete_date_type"
|"delete_date_type"
|varchar(10)
|varchar(10)
|NULL
|<center>NULL</center>
|Can be 'relative', 'absolute', or NULL; If NULL, this course should not be automatically deleted. If 'relative', the value stored in delete_date is the number of days after the end of the course. If 'absolute', the value stored in delete_date is a Unix timestamp.
|Can be 'relative', 'absolute', or NULL; If NULL, this course should not be automatically deleted. If 'relative', the value stored in delete_date is the number of days after the end of the course. If 'absolute', the value stored in delete_date is a Unix timestamp.
|-
|-
|"delete_date"
|"delete_date"
|int(10)
|int(10)
|NULL
|<center>NULL</center>
|When the course should be deleted. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the delete_date_type column.
|When the course should be deleted. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the delete_date_type column.


Line 88: Line 88:
|"enabled"
|"enabled"
|int(1)
|int(1)
|1
|<center>1</center>
|If automatic archiving/deleting should be enabled by default for these courses.
|If automatic archiving/deleting should be enabled by default for these courses.
|-
|-
|"archive_date_type"
|"archive_date_type"
|varchar(10)
|varchar(10)
|NULL
|<center>NULL</center>
|Can be 'relative', 'absolute', or NULL; If NULL, courses should not be automatically archived by default. If 'relative', the value stored in archive_date is the number of days after the end of the course. If 'absolute', the value stored in archive_date is a Unix timestamp.
|Can be 'relative', 'absolute', or NULL; If NULL, courses should not be automatically archived by default. If 'relative', the value stored in archive_date is the number of days after the end of the course. If 'absolute', the value stored in archive_date is a Unix timestamp.
|-
|-
|"archive_date"
|"archive_date"
|int(10)
|int(10)
|NULL
|<center>NULL</center>
|When courses should be archived by default. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the archive_date_type column.
|When courses should be archived by default. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the archive_date_type column.
|-
|-
|"delete_date_type"
|"delete_date_type"
|varchar(10)
|varchar(10)
|NULL
|<center>NULL</center>
|Can be 'relative', 'absolute', or NULL; If NULL, courses should not be automatically deleted by default. If 'relative', the value stored in delete_date is the number of days after the end of the course. If 'absolute', the value stored in delete_date is a Unix timestamp.
|Can be 'relative', 'absolute', or NULL; If NULL, courses should not be automatically deleted by default. If 'relative', the value stored in delete_date is the number of days after the end of the course. If 'absolute', the value stored in delete_date is a Unix timestamp.
|-
|-
|"delete_date"
|"delete_date"
|int(10)
|int(10)
|NULL
|<center>NULL</center>
|When courses should be deleted by default. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the delete_date_type column.
|When courses should be deleted by default. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the delete_date_type column.



Revision as of 22:32, 30 April 2009

Executive Summary

In order to meet various data retention policies and regulations, it would be helpful if Moodle could automatically "archive" and/or delete courses after a certain amount of time.

The goal with these changes is to allow administrators maximum flexibility (being able to set archival options on a course-by-course basis), while maintaining a good amount of simplicity (being able to set default archival options on a category-by-category basis).

Glossary

To reduce confusion, some terms and definitions are presented below:

Term Definition
Archived Course A course that has been made read-only to all but course and site administrators.

Database Structures

archive_courses

This table keeps information about when specific courses should be archived. If a course appears in this table and enabled is set to 1, it means it should be archived or deleted automatically after the specified date is reached. If not, then no automatic archiving should occur.

Field Type Default Info
"id" int(10) autoincrementing
"courseid" int(10) unique; The course that should be archived or deleted.
"enabled" tinyint(1)
1
If automatic archiving/deleting should be enabled for this course.
"archive_date_type" varchar(10)
NULL
Can be 'relative', 'absolute', or NULL; If NULL, this course should not be automatically archived. If 'relative', the value stored in archive_date is the number of days after the end of the course. If 'absolute', the value stored in archive_date is a Unix timestamp.
"archive_date" int(10)
NULL
When the course should be archived. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the archive_date_type column.
"delete_date_type" varchar(10)
NULL
Can be 'relative', 'absolute', or NULL; If NULL, this course should not be automatically deleted. If 'relative', the value stored in delete_date is the number of days after the end of the course. If 'absolute', the value stored in delete_date is a Unix timestamp.
"delete_date" int(10)
NULL
When the course should be deleted. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the delete_date_type column.

archive_category_settings

This table keeps information about default settings for each category. This determines what settings a course should have when it's first created in a particular category. If a category doesn't have any settings, site-wide defaults are used instead.

"categoryid"
Field Type Default Info
"id" int(10) autoincrementing
int(10) unique; The category
"enabled" int(1)
1
If automatic archiving/deleting should be enabled by default for these courses.
"archive_date_type" varchar(10)
NULL
Can be 'relative', 'absolute', or NULL; If NULL, courses should not be automatically archived by default. If 'relative', the value stored in archive_date is the number of days after the end of the course. If 'absolute', the value stored in archive_date is a Unix timestamp.
"archive_date" int(10)
NULL
When courses should be archived by default. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the archive_date_type column.
"delete_date_type" varchar(10)
NULL
Can be 'relative', 'absolute', or NULL; If NULL, courses should not be automatically deleted by default. If 'relative', the value stored in delete_date is the number of days after the end of the course. If 'absolute', the value stored in delete_date is a Unix timestamp.
"delete_date" int(10)
NULL
When courses should be deleted by default. Can either be expressed as an absolute value (as a Unix timestamp), or a relative value (the number of days after the end of the course). This is set in the delete_date_type column.

Archival

The permissions system would be modified to perform an extra check when determining if a user had access to perform an action on a course. If a user tried to perform an action that could update or change a course after the date at which it was archived, and that user did not have the (newly created) permission to 'Update Archived Courses', they would be denied access.

Deletion

The cron job would be modified to check the archive_courses table and perform a final backup of and then delete any courses after they reached their delete_date.

Public API

Modules may use only functions from lib/archivelib.php which are marked as public.

ArchiveCourse::course_is_archived($courseid)

Returns boolean value: true if the courseid exists in the archive_courses table, that row is enabled, and the archive_date is in the past.

ArchiveCourse::get_course_info($courseid)

Returns associative array of archive/delete dates, whether the course is or will be archived, whether the course will be deleted, and whether the archiving is enabled for a particular course. Returns NULL if the course doesn't exist in the table, false on failure.

ArchiveCourse::get_course_archive_date($courseid)

Returns the archive date (as a Unix timestamp) for a particular course, NULL if the course doesn't exist in the table, false on failure. This method converts any relative archive dates to their absolute value.

ArchiveCourse::get_course_delete_date($courseid)

Returns the delete date (as a Unix timestamp) for a particular course, NULL if the course doesn't exist in the table, false on failure. This method converts any relative delete dates to their absolute value.

ArchiveCourse::set_archive_options($courseid, $options_array)

Sets archive options for a particular course (all options are not required -- if not present, defaults will be used). Returns true on success, false on failure. The $option_array should have the following format:

Array( 'archive_date_type'=>'[relative|absolute]', 'archive_date'=>int, 'delete_date_type'=>'[relative|absolute]', 'delete_date'=>int, 'enabled'=>[true|false] )

ArchiveCourse::unarchive_course($courseid)

Sets the enabled column to false for an archived course. Returns true if the course was successfully unarchived, or if the course wasn't archived to begin with, false on failure.


ArchiveCategory::get_defaults($categoryid)

Returns associative array of defaults, including archive/delete dates, whether courses will be archived, and whether courses will be deleted. Returns site-wide defaults if the category doesn't have any defaults of its own, false on failure.

ArchiveCategory::set_defaults($categoryid, $options_array)

Sets archive defaults for a particular category (all options are not required -- if not present, site-wide defaults will be used). Returns true on success, false on failure. The $option_array should have the following format:

Array( 'archive_date_type'=>'[relative|absolute]', 'archive_date'=>, 'delete_date_type'=>'[relative|absolute]', 'delete_date'=>, 'enabled'=>[true|false] )

ArchiveCategory::remove_defaults($categoryid)

Removes category defaults (site-wide defaults will be used instead for that category)


Capabilities and Permissions

  • archive/settings:managesite - manage site-wide default settings
  • archive/settings:managecategory - manage category-level default settings
  • archive/settings:managecourse - manage course-level settings
  • archive/courses:update - update courses even when they're archived -- intended for administrators.


Ideas for the Future

  • add a new archive/courses:view permission to determine if a user should be able to view archived courses