1 | <?php |
||
25 | class LastRefreshDatabase extends LastRefreshAbstract |
||
26 | { |
||
27 | use RememberTrait; |
||
28 | |||
29 | /** |
||
30 | * @var UsersTable |
||
31 | */ |
||
32 | protected $storage; |
||
33 | |||
34 | private $initialized = false; |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function __construct(CurrentUserInterface $CurrentUser, UsersTable $storage) |
||
40 | { |
||
41 | parent::__construct($CurrentUser, $storage); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritDoc} |
||
46 | */ |
||
47 | protected function _get(): ?int |
||
48 | { |
||
49 | return $this->remember('timestamp', function () { |
||
50 | // can't use ArrayIterator access because array_key_exists doesn't work |
||
51 | // on ArrayIterator … Yeah for PHP!1!! |
||
52 | $settings = $this->_CurrentUser->getSettings(); |
||
53 | if (!array_key_exists('last_refresh', $settings)) { |
||
54 | throw new \Exception('last_refresh not set'); |
||
55 | } elseif ($settings['last_refresh'] === null) { |
||
56 | // mar is not initialized |
||
57 | return null; |
||
58 | } |
||
59 | |||
60 | return $this->_CurrentUser->get('last_refresh_unix'); |
||
61 | }); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * {@inheritDoc} |
||
66 | */ |
||
67 | protected function _set(\DateTimeImmutable $timestamp): void |
||
68 | { |
||
69 | $this->persist($timestamp); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * {@inheritDoc} |
||
74 | */ |
||
75 | public function setMarker(): void |
||
79 | |||
80 | /** |
||
81 | * Persist to strorage |
||
82 | * |
||
83 | * @param DateTimeInterface $timestamp datetime string for last_refresh |
||
84 | * @return void |
||
85 | */ |
||
86 | protected function persist(DateTimeInterface $timestamp = null): void |
||
93 | } |
||
94 |