Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
PositionTracker
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 getLastPosition
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 keepCurrentPosition
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getStorage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2020 (original work) Open Assessment Technologies SA
19 */
20
21declare(strict_types=1);
22
23namespace oat\tao\model\task\migration\service;
24
25use common_persistence_KeyValuePersistence;
26use oat\generis\persistence\PersistenceManager;
27use oat\oatbox\service\ConfigurableService;
28
29class PositionTracker extends ConfigurableService
30{
31    private const SUFFIX_KEY = '::_last_known';
32
33    public function getLastPosition(string $id): int
34    {
35        $start = $this->getStorage()->get($id . self::SUFFIX_KEY);
36        return $start ? (int)$start : 0;
37    }
38
39    public function keepCurrentPosition(string $id, int $position): void
40    {
41        $persistence = $this->getStorage();
42        $persistence->set($id . self::SUFFIX_KEY, $position);
43    }
44
45    private function getStorage(): common_persistence_KeyValuePersistence
46    {
47        return $this->getServiceLocator()->get(PersistenceManager::SERVICE_ID)->getPersistenceById('default_kv');
48    }
49}