Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

A scheduled task.

Copyright: 2013 onwards Martin Dougiamas http://dougiamas.com
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 271 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

tag_cron_task:: (6 methods):
  get_name()
  execute()
  compute_correlations()
  cleanup()
  process_computed_correlation()
  bulk_delete_instances()


Class: tag_cron_task  - X-Ref

Simple task to run the tag cron.

get_name()   X-Ref
Get a descriptive name for this task (shown to admins).

return: string

execute()   X-Ref
Do the job.
Throw exceptions on errors (the job will be retried).


compute_correlations($mincorrelation = 2)   X-Ref
Calculates and stores the correlated tags of all tags.

The correlations are stored in the 'tag_correlation' table.

Two tags are correlated if they appear together a lot. Ex.: Users tagged with "computers"
will probably also be tagged with "algorithms".

The rationale for the 'tag_correlation' table is performance. It works as a cache
for a potentially heavy load query done at the 'tag_instance' table. So, the
'tag_correlation' table stores redundant information derived from the 'tag_instance' table.

param: int $mincorrelation Only tags with more than $mincorrelation correlations will be identified.

cleanup()   X-Ref
Clean up the tag tables, making sure all tagged object still exists.

This method is called from cron.

This should normally not be necessary, but in case related tags are not deleted
when the tagged record is removed, this should be done once in a while, perhaps
on an occasional cron run.  On a site with lots of tags, this could become an
expensive function to call.

process_computed_correlation(stdClass $tagcorrelation)   X-Ref
This function processes a tag correlation and makes changes in the database as required.

The tag correlation object needs have both a tagid property and a correlatedtags property that is an array.

param: stdClass $tagcorrelation
return: int/bool The id of the tag correlation that was just processed or false.

bulk_delete_instances($instances)   X-Ref
This function will delete numerous tag instances efficiently.
This removes tag instances only. It doesn't check to see if it is the last use of a tag.

param: array $instances An array of tag instance objects with the addition of the tagname and tagrawname