]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/updater/UpdaterUtils.php
Apply PHP Code Beautifier on source code for linter automatic fixes
[github/shaarli/Shaarli.git] / application / updater / UpdaterUtils.php
1 <?php
2
3 namespace Shaarli\Updater;
4
5 class UpdaterUtils
6 {
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 */
14 public static function read_updates_file($updatesFilepath)
15 {
16 if (! empty($updatesFilepath) && is_file($updatesFilepath)) {
17 $content = file_get_contents($updatesFilepath);
18 if (! empty($content)) {
19 return explode(';', $content);
20 }
21 }
22 return [];
23 }
24
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 */
33 public static function write_updates_file($updatesFilepath, $updates)
34 {
35 if (empty($updatesFilepath)) {
36 throw new \Exception('Updates file path is not set, can\'t write updates.');
37 }
38
39 $res = file_put_contents($updatesFilepath, implode(';', $updates));
40 if ($res === false) {
41 throw new \Exception('Unable to write updates in ' . $updatesFilepath . '.');
42 }
43 }
44 }