PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Plugin / Tasks.php
matomo / app / core / Plugin Last commit date
ConsoleCommand 2 years ago Dimension 2 years ago API.php 2 years ago AggregatedMetric.php 2 years ago ArchivedMetric.php 2 years ago Archiver.php 2 years ago Categories.php 2 years ago ComponentFactory.php 2 years ago ComputedMetric.php 2 years ago ConsoleCommand.php 2 years ago Controller.php 2 years ago ControllerAdmin.php 2 years ago Dependency.php 2 years ago LogTablesProvider.php 2 years ago Manager.php 2 years ago Menu.php 2 years ago MetadataLoader.php 2 years ago Metric.php 2 years ago PluginException.php 2 years ago ProcessedMetric.php 2 years ago ReleaseChannels.php 2 years ago Report.php 2 years ago ReportsProvider.php 2 years ago RequestProcessors.php 2 years ago Segment.php 2 years ago SettingsProvider.php 2 years ago Tasks.php 2 years ago ThemeStyles.php 2 years ago ViewDataTable.php 2 years ago Visualization.php 2 years ago WidgetsProvider.php 2 years ago
Tasks.php
141 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\Plugin;
11
12 use Piwik\Development;
13 use Piwik\Scheduler\Schedule\Schedule;
14 use Piwik\Scheduler\Task;
15 /**
16 * Base class for all Tasks declarations.
17 * Tasks are usually meant as scheduled tasks that are executed regularly by Piwik in the background. For instance
18 * once every hour or every day. This could be for instance checking for updates, sending email reports, etc.
19 * Please don't mix up tasks with console commands which can be executed on the CLI.
20 */
21 class Tasks
22 {
23 /**
24 * @var Task[]
25 */
26 private $tasks = array();
27 const LOWEST_PRIORITY = Task::LOWEST_PRIORITY;
28 const LOW_PRIORITY = Task::LOW_PRIORITY;
29 const NORMAL_PRIORITY = Task::NORMAL_PRIORITY;
30 const HIGH_PRIORITY = Task::HIGH_PRIORITY;
31 const HIGHEST_PRIORITY = Task::HIGHEST_PRIORITY;
32 /**
33 * This method is called to collect all schedule tasks. Register all your tasks here that should be executed
34 * regularly such as daily or monthly.
35 */
36 public function schedule()
37 {
38 // eg $this->daily('myMethodName')
39 }
40 /**
41 * @return Task[] $tasks
42 */
43 public function getScheduledTasks()
44 {
45 return $this->tasks;
46 }
47 /**
48 * Schedule the given tasks/method to run once every hour.
49 *
50 * @param string $methodName The name of the method that will be called when the task is being
51 * executed. To make it work you need to create a public method having the
52 * given method name in your Tasks class.
53 * @param null|string $methodParameter Can be null if the task does not need any parameter or a string. It is not
54 * possible to specify multiple parameters as an array etc. If you need to
55 * pass multiple parameters separate them via any characters such as '###'.
56 * For instance '$param1###$param2###$param3'
57 * @param int $priority Can be any constant such as self::LOW_PRIORITY
58 *
59 * @return Schedule
60 * @api
61 */
62 protected function hourly($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
63 {
64 return $this->custom($this, $methodName, $methodParameter, 'hourly', $priority);
65 }
66 /**
67 * Schedule the given tasks/method to run once every day.
68 *
69 * See {@link hourly()}
70 * @api
71 */
72 protected function daily($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
73 {
74 return $this->custom($this, $methodName, $methodParameter, 'daily', $priority);
75 }
76 /**
77 * Schedule the given tasks/method to run once every week.
78 *
79 * See {@link hourly()}
80 * @api
81 */
82 protected function weekly($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
83 {
84 return $this->custom($this, $methodName, $methodParameter, 'weekly', $priority);
85 }
86 /**
87 * Schedule the given tasks/method to run once every month.
88 *
89 * See {@link hourly()}
90 * @api
91 */
92 protected function monthly($methodName, $methodParameter = null, $priority = self::NORMAL_PRIORITY)
93 {
94 return $this->custom($this, $methodName, $methodParameter, 'monthly', $priority);
95 }
96 /**
97 * Schedules the given tasks/method to run depending at the given scheduled time. Unlike the convenient methods
98 * such as {@link hourly()} you need to specify the object on which the given method should be called. This can be
99 * either an instance of a class or a class name. For more information about these parameters see {@link hourly()}
100 *
101 * @param string|object $objectOrClassName
102 * @param string $methodName
103 * @param null|string $methodParameter
104 * @param string|Schedule $time
105 * @param int $priority
106 *
107 * @return \Piwik\Scheduler\Schedule\Schedule
108 *
109 * @throws \Exception If a wrong time format is given. Needs to be either a string such as 'daily', 'weekly', ...
110 * or an instance of {@link Piwik\Scheduler\Schedule\Schedule}
111 *
112 * @api
113 */
114 protected function custom($objectOrClassName, $methodName, $methodParameter, $time, $priority = self::NORMAL_PRIORITY)
115 {
116 $this->checkIsValidTask($objectOrClassName, $methodName);
117 if (is_string($time)) {
118 $time = Schedule::factory($time);
119 }
120 if (!$time instanceof Schedule) {
121 throw new \Exception('$time should be an instance of Schedule');
122 }
123 $this->scheduleTask(new Task($objectOrClassName, $methodName, $methodParameter, $time, $priority));
124 return $time;
125 }
126 /**
127 * In case you need very high flexibility and none of the other convenient methods such as {@link hourly()} or
128 * {@link custom()} suit you, you can use this method to add a custom scheduled task.
129 *
130 * @param Task $task
131 */
132 protected function scheduleTask(Task $task)
133 {
134 $this->tasks[] = $task;
135 }
136 private function checkIsValidTask($objectOrClassName, $methodName)
137 {
138 Development::checkMethodIsCallable($objectOrClassName, $methodName, 'The registered task is not valid as the method');
139 }
140 }
141