]>
Commit | Line | Data |
---|---|---|
bcf056c9 V |
1 | <?php |
2 | ||
cf92b4dd A |
3 | namespace Shaarli\Updater; |
4 | ||
5 | class UpdaterUtils | |
bcf056c9 | 6 | { |
cf92b4dd A |
7 | /** |
8 | * Read the updates file, and return already done updates. | |
9 | * | |
10 | * @param string $updatesFilepath Updates file path. | |
11 | * | |
12 | * @return array Already done update methods. | |
13 | */ | |
b99e00f7 | 14 | public static function readUpdatesFile($updatesFilepath) |
cf92b4dd A |
15 | { |
16 | if (! empty($updatesFilepath) && is_file($updatesFilepath)) { | |
17 | $content = file_get_contents($updatesFilepath); | |
18 | if (! empty($content)) { | |
19 | return explode(';', $content); | |
20 | } | |
bcf056c9 | 21 | } |
53054b2b | 22 | return []; |
bcf056c9 | 23 | } |
bcf056c9 | 24 | |
cf92b4dd A |
25 | /** |
26 | * Write updates file. | |
27 | * | |
28 | * @param string $updatesFilepath Updates file path. | |
29 | * @param array $updates Updates array to write. | |
30 | * | |
31 | * @throws \Exception Couldn't write version number. | |
32 | */ | |
b99e00f7 | 33 | public static function writeUpdatesFile($updatesFilepath, $updates) |
cf92b4dd A |
34 | { |
35 | if (empty($updatesFilepath)) { | |
36 | throw new \Exception('Updates file path is not set, can\'t write updates.'); | |
37 | } | |
bcf056c9 | 38 | |
cf92b4dd A |
39 | $res = file_put_contents($updatesFilepath, implode(';', $updates)); |
40 | if ($res === false) { | |
53054b2b | 41 | throw new \Exception('Unable to write updates in ' . $updatesFilepath . '.'); |
cf92b4dd | 42 | } |
bcf056c9 V |
43 | } |
44 | } |