Piwik\Plugin\

Tasks

Base class for all Tasks declarations.

Tasks are usually meant as scheduled tasks that are executed regularly by Matomo (formerly Piwik) in the background. For instance once every hour or every day. This could be for instance checking for updates, sending email reports, etc. Please don't mix up tasks with console commands which can be executed on the CLI.

Methods

The class defines the following methods:

  • hourly() — Schedule the given tasks/method to run once every hour.
  • daily() — Schedule the given tasks/method to run once every day.
  • weekly() — Schedule the given tasks/method to run once every week.
  • monthly() — Schedule the given tasks/method to run once every month.
  • custom() — Schedules the given tasks/method to run depending at the given scheduled time.

hourly()

Schedule the given tasks/method to run once every hour.

Signature

  • It accepts the following parameter(s):
    • $methodName (string) — The name of the method that will be called when the task is being executed. To make it work you need to create a public method having the given method name in your Tasks class.
    • $methodParameter (null|string) — Can be null if the task does not need any parameter or a string. It is not possible to specify multiple parameters as an array etc. If you need to pass multiple parameters separate them via any characters such as '###'. For instance '$param1###$param2###$param3'
    • $priority (int) — Can be any constant such as self::LOW_PRIORITY
  • It returns a Schedule value.

daily()

Schedule the given tasks/method to run once every day.

See hourly()

Signature

  • It accepts the following parameter(s):

    • $methodName

    • $methodParameter

    • $priority

  • It does not return anything or a mixed result.

weekly()

Schedule the given tasks/method to run once every week.

See hourly()

Signature

  • It accepts the following parameter(s):

    • $methodName

    • $methodParameter

    • $priority

  • It does not return anything or a mixed result.

monthly()

Schedule the given tasks/method to run once every month.

See hourly()

Signature

  • It accepts the following parameter(s):

    • $methodName

    • $methodParameter

    • $priority

  • It does not return anything or a mixed result.

custom()

Schedules the given tasks/method to run depending at the given scheduled time. Unlike the convenient methods such as hourly() you need to specify the object on which the given method should be called. This can be either an instance of a class or a class name. For more information about these parameters see hourly()

Signature

  • It accepts the following parameter(s):

    • $objectOrClassName (string|object) —

    • $methodName (string) —

    • $methodParameter (null|string) —

    • $time (string|Schedule) —

    • $priority (int) —

  • It returns a Schedule value.

  • It throws one of the following exceptions:
    • Exception — If a wrong time format is given. Needs to be either a string such as 'daily', 'weekly', ... or an instance of {@link Piwik\Scheduler\Schedule\Schedule}