PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
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 / Scheduler / Schedule / Monthly.php
matomo / app / core / Scheduler / Schedule Last commit date
Daily.php 1 month ago Hourly.php 2 years ago Monthly.php 2 years ago Schedule.php 1 year ago SpecificTime.php 2 years ago Weekly.php 1 year ago
Monthly.php
112 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\Scheduler\Schedule;
10
11 use Exception;
12 /**
13 * Monthly class is used to schedule tasks every month.
14 *
15 * @see \Piwik\Scheduler\Task
16 */
17 class Monthly extends \Piwik\Scheduler\Schedule\Schedule
18 {
19 /**
20 * List of available week number strings used in setDayOfWeekFromString.
21 */
22 private static $weekNumberStringToInt = array('first' => 0, 'second' => 1, 'third' => 2, 'fourth' => 3);
23 /**
24 * Day of the week for scheduled time.
25 *
26 * @var int
27 */
28 private $dayOfWeek = null;
29 /**
30 * Week number for scheduled time.
31 *
32 * @var int
33 */
34 private $week = null;
35 public function setDayOfWeekFromString($day)
36 {
37 @(list($weekNumberString, $dayNumberString) = explode(' ', $day));
38 // get day number
39 $day = \Piwik\Scheduler\Schedule\Weekly::getDayIntFromString($dayNumberString) % 7;
40 // get week number
41 $weekNumberString = strtolower($weekNumberString);
42 if (isset(self::$weekNumberStringToInt[$weekNumberString])) {
43 $week = self::$weekNumberStringToInt[$weekNumberString];
44 } else {
45 throw new Exception("Invalid week describer in Schedule\\Monthly::setDayOfWeekFromString: '{$weekNumberString}'. " . "Supported values are 'first', 'second', 'third', 'fourth'.");
46 }
47 $this->setDayOfWeek($day, $week);
48 }
49 /**
50 * @return int
51 */
52 public function getRescheduledTime()
53 {
54 $currentTime = $this->getTime();
55 // Adds one month
56 $rescheduledTime = mktime(date('H', $currentTime), date('i', $currentTime), date('s', $currentTime), date('n', $currentTime) + 1, 1, date('Y', $currentTime));
57 $nextMonthLength = date('t', $rescheduledTime);
58 // Sets scheduled day
59 $scheduledDay = date('j', $currentTime);
60 if ($this->day !== null) {
61 $scheduledDay = $this->day;
62 }
63 if ($this->dayOfWeek !== null && $this->week !== null) {
64 $newTime = $rescheduledTime + $this->week * 7 * 86400;
65 while (date("w", $newTime) != $this->dayOfWeek % 7) {
66 // modulus for sanity check
67 $newTime += 86400;
68 }
69 $scheduledDay = ($newTime - $rescheduledTime) / 86400 + 1;
70 }
71 // Caps scheduled day
72 if ($scheduledDay > $nextMonthLength) {
73 $scheduledDay = $nextMonthLength;
74 }
75 // Adjusts the scheduled day
76 $rescheduledTime += ($scheduledDay - 1) * 86400;
77 // Adjusts the scheduled hour
78 $rescheduledTime = $this->adjustHour($rescheduledTime);
79 $rescheduledTime = $this->adjustTimezone($rescheduledTime);
80 return $rescheduledTime;
81 }
82 /**
83 * @param int $_day the day to set, has to be >= 1 and < 32
84 * @throws Exception if parameter _day is invalid
85 */
86 public function setDay($_day)
87 {
88 if (!($_day >= 1 && $_day < 32)) {
89 throw new Exception("Invalid day parameter, must be >=1 and < 32");
90 }
91 $this->day = $_day;
92 }
93 /**
94 * Makes this scheduled time execute on a particular day of the week on each month.
95 *
96 * @param int $_day the day of the week to use, between 0-6 (inclusive). 0 -> Sunday
97 * @param int $_week the week to use, between 0-3 (inclusive)
98 * @throws Exception if either parameter is invalid
99 */
100 public function setDayOfWeek($_day, $_week)
101 {
102 if (!($_day >= 0 && $_day < 7)) {
103 throw new Exception("Invalid day of week parameter, must be >= 0 & < 7");
104 }
105 if (!($_week >= 0 && $_week < 4)) {
106 throw new Exception("Invalid week number, must be >= 1 & < 4");
107 }
108 $this->dayOfWeek = $_day;
109 $this->week = $_week;
110 }
111 }
112