-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.php
82 lines (73 loc) · 1.77 KB
/
sample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
*
* MAPP Example. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2020, Gregor Morrill, https://stevens-stevens.com
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace mapp\example\cron\task;
/**
* MAPP Example cron task.
*/
class sample extends \phpbb\cron\task\base
{
/**
* How often we run the cron (in seconds).
* @var int
*/
protected $cron_frequency = 60;
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\log\log */
protected $log;
/**
* Constructor
*
* @param \phpbb\config\config $config Config object
*/
public function __construct(\phpbb\config\config $config, \phpbb\log\log $log)
{
$this->config = $config;
$this->log = $log;
$this->log->add('admin', 2, '127.0.0.1', 'sample.construct');
}
/**
* Runs this cron task.
*
* @return void
*/
public function run()
{
$this->log->add('admin', 2, '127.0.0.1', 'sample.run');
// Run your cron actions here...
// Update the cron task run time here if it hasn't
// already been done by your cron actions.
$this->config->set('example_cron_last_run', time(), true);
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* For example, a cron task that prunes forums can only run when
* forum pruning is enabled.
*
* @return bool
*/
public function is_runnable()
{
$this->log->add('admin', 2, '127.0.0.1', 'sample.is_runnable');
return true;
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* @return bool
*/
public function should_run()
{
$this->log->add('admin', 2, '127.0.0.1', 'sample.should_run');
return $this->config['example_cron_last_run'] < (time() - $this->cron_frequency);
}
}