1: <?php
2:
3: namespace malkusch\bav;
4:
5: /**
6: * Perform an update automatically.
7: *
8: * @author Markus Malkusch <markus@malkusch.de>
9: * @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
10: * @license GPL
11: * @api
12: */
13: class AutomaticUpdatePlan extends UpdatePlan
14: {
15:
16: /**
17: * @var string Name of the update lock file
18: */
19: const UPDATE_LOCK = "bav_update.lock";
20:
21: /**
22: * @var bool
23: */
24: private $notice = true;
25:
26: /**
27: * Set to false if you don't want to see an E_USER_NOTICE about an update.
28: *
29: * @param bool $notice
30: */
31: public function setNotice($notice)
32: {
33: $this->notice = $notice;
34: }
35:
36: /**
37: * Perform an update.
38: *
39: * If enabled (default) this method will send a E_USER_NOTICE about the update.
40: *
41: * @see setNotice()
42: */
43: public function perform(DataBackend $backend)
44: {
45: $isNotice = $this->notice;
46: $lock = new Lock(self::UPDATE_LOCK);
47: $lock->nonblockingExecuteOnce(
48: function () use ($backend, $isNotice) {
49: $backend->update();
50: if ($isNotice) {
51: trigger_error("bav's bank data was updated sucessfully.", E_USER_NOTICE);
52:
53: }
54: }
55: );
56: }
57: }
58: