diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:07:13 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:07:13 +0200 |
commit | d9f6275ebca035fec8331652c677981056793ccc (patch) | |
tree | 37a64baf4f0eba6b781040605965383d8aded2cc /application/updater/UpdaterUtils.php | |
parent | 38672ba0d1c722e5d6d33a58255ceb55e9410e46 (diff) | |
parent | d63ff87a009313141ae684ec447b902562ff6ee7 (diff) | |
download | Shaarli-stable.tar.gz Shaarli-stable.tar.zst Shaarli-stable.zip |
Merge branch 'v0.11' into stablestable
Diffstat (limited to 'application/updater/UpdaterUtils.php')
-rw-r--r-- | application/updater/UpdaterUtils.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/application/updater/UpdaterUtils.php b/application/updater/UpdaterUtils.php new file mode 100644 index 00000000..34d4f422 --- /dev/null +++ b/application/updater/UpdaterUtils.php | |||
@@ -0,0 +1,39 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Read the updates file, and return already done updates. | ||
5 | * | ||
6 | * @param string $updatesFilepath Updates file path. | ||
7 | * | ||
8 | * @return array Already done update methods. | ||
9 | */ | ||
10 | function read_updates_file($updatesFilepath) | ||
11 | { | ||
12 | if (! empty($updatesFilepath) && is_file($updatesFilepath)) { | ||
13 | $content = file_get_contents($updatesFilepath); | ||
14 | if (! empty($content)) { | ||
15 | return explode(';', $content); | ||
16 | } | ||
17 | } | ||
18 | return array(); | ||
19 | } | ||
20 | |||
21 | /** | ||
22 | * Write updates file. | ||
23 | * | ||
24 | * @param string $updatesFilepath Updates file path. | ||
25 | * @param array $updates Updates array to write. | ||
26 | * | ||
27 | * @throws Exception Couldn't write version number. | ||
28 | */ | ||
29 | function write_updates_file($updatesFilepath, $updates) | ||
30 | { | ||
31 | if (empty($updatesFilepath)) { | ||
32 | throw new Exception(t('Updates file path is not set, can\'t write updates.')); | ||
33 | } | ||
34 | |||
35 | $res = file_put_contents($updatesFilepath, implode(';', $updates)); | ||
36 | if ($res === false) { | ||
37 | throw new Exception(t('Unable to write updates in '. $updatesFilepath . '.')); | ||
38 | } | ||
39 | } | ||