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 91: Line 91:
|unique; The category
|unique; The category
|-
|-
|"enabled"
|"archive_enabled"
|int(1)
|int(1)
|<center>1</center>
|<center>1</center>
|If automatic archiving/deleting should be enabled by default for these courses.
|If automatic archiving should be enabled by default for these courses.
|-
|-
|"archive_date_type"
|"archive_date_point"
|varchar(10)
|varchar(10)
|<center>NULL</center>
|<center>"epoch"</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 'epoch', 'course_end', and in the future, some other values. Stores the point from which archive_date should be compared. E.g., if 'epoch', courses should be archived <i>archive_date</i> seconds after the Unix epoch. If 'course_end', courses should be archived <i>archive_date</i> seconds after the end of the course.
|-
|-
|"archive_date"
|"archive_date"
|int(10)
|int(10)
|<center>NULL</center>
|<center>0</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. Is expressed as the number of seconds after archive_date_point. (If archive_date_point is set to 'epoch', this is effectively a Unix timestamp.)
|-
|-
|"delete_date_type"
|"delete_enabled"
|int(1)
|<center>1</center>
|If automatic deleting should be enabled by default for these courses.
|-
|"delete_date_point"
|varchar(10)
|varchar(10)
|<center>NULL</center>
|<center>"epoch"</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 'epoch', 'course_end', and in the future, some other values. Stores the point from which delete_date should be compared. E.g., if 'epoch', courses should be deleted <i>delete_date</i> seconds after the Unix epoch. If 'course_end', courses should be deleted <i>delete_date</i> seconds after the end of the course.
|-
|-
|"delete_date"
|"delete_date"
|int(10)
|int(10)
|<center>NULL</center>
|<center>0</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. Is expressed as the number of seconds after delete_date_point. (If delete_date_point is set to 'epoch', this is effectively a Unix timestamp.)


|}
|}

Revision as of 19:08, 5 May 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.
"archive_enabled" tinyint(1)
1
If automatic archiving should be enabled for this course.
"archive_date_point" varchar(10)
"epoch"
Can be 'epoch', 'course_end', and in the future, some other values. Stores the point from which archive_date should be compared. E.g., if 'epoch', the course should be archived archive_date seconds after the Unix epoch. If 'course_end', the course should be archived archive_date seconds after the end of the course.
"archive_date" int(10)
0
When the course should be archived. Is expressed as the number of seconds after archive_date_point. (If archive_date_point is set to 'epoch', this is effectively a Unix timestamp.)
"delete_enabled" tinyint(1)
1
If automatic deleting should be enabled for this course.
"delete_date_point" varchar(10)
"epoch"
Can be 'epoch', 'course_end', and in the future, some other values. Stores the point from which delete_date should be compared. E.g., if 'epoch', the course should be deleted delete_date seconds after the Unix epoch. If 'course_end', the course should be deleted delete_date seconds after the end of the course.
"delete_date" int(10)
0
When the course should be deleted. Is expressed as the number of seconds after delete_date_point. (If delete_date_point is set to 'epoch', this is effectively a Unix timestamp.)

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.

Field Type Default Info
"id" int(10) autoincrementing
"categoryid" int(10) unique; The category
"archive_enabled" int(1)
1
If automatic archiving should be enabled by default for these courses.
"archive_date_point" varchar(10)
"epoch"
Can be 'epoch', 'course_end', and in the future, some other values. Stores the point from which archive_date should be compared. E.g., if 'epoch', courses should be archived archive_date seconds after the Unix epoch. If 'course_end', courses should be archived archive_date seconds after the end of the course.
"archive_date" int(10)
0
When courses should be archived. Is expressed as the number of seconds after archive_date_point. (If archive_date_point is set to 'epoch', this is effectively a Unix timestamp.)
"delete_enabled" int(1)
1
If automatic deleting should be enabled by default for these courses.
"delete_date_point" varchar(10)
"epoch"
Can be 'epoch', 'course_end', and in the future, some other values. Stores the point from which delete_date should be compared. E.g., if 'epoch', courses should be deleted delete_date seconds after the Unix epoch. If 'course_end', courses should be deleted delete_date seconds after the end of the course.
"delete_date" int(10)
0
When courses should be deleted. Is expressed as the number of seconds after delete_date_point. (If delete_date_point is set to 'epoch', this is effectively a Unix timestamp.)

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 have 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_enabled'=>[true|false] 

'archive_date_point'=>'[epoch|course_end|...]',
'archive_date'=>int,

       'delete_enabled'=>[true|false] 

'delete_date_type'=>'[epoch|course_end|...]',
'delete_date'=>int,
)


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_enabled'=>[true|false] 

'archive_date_point'=>'[epoch|course_end|...]',
'archive_date'=>int,

       'delete_enabled'=>[true|false] 

'delete_date_type'=>'[epoch|course_end|...]',
'delete_date'=>int,
)

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