diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-01-18 10:01:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-18 10:01:06 +0100 |
commit | 3fb29fdda04ca86e04422d49b86cf646d53c4f9d (patch) | |
tree | adf8512f93f5559ba87d0c9931969ae4ebea7133 /application/updater/UpdaterUtils.php | |
parent | 796c4c57d085ae4589b53dfe8369ae9ba30ffdaf (diff) | |
parent | e26e2060f5470ce8bf4c5973284bae07b8af170a (diff) | |
download | Shaarli-3fb29fdda04ca86e04422d49b86cf646d53c4f9d.tar.gz Shaarli-3fb29fdda04ca86e04422d49b86cf646d53c4f9d.tar.zst Shaarli-3fb29fdda04ca86e04422d49b86cf646d53c4f9d.zip |
Store bookmarks as PHP objects and add a service layer to retriā¦ (#1307)
Store bookmarks as PHP objects and add a service layer to retrieve them
Diffstat (limited to 'application/updater/UpdaterUtils.php')
-rw-r--r-- | application/updater/UpdaterUtils.php | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/application/updater/UpdaterUtils.php b/application/updater/UpdaterUtils.php index 34d4f422..828a49fc 100644 --- a/application/updater/UpdaterUtils.php +++ b/application/updater/UpdaterUtils.php | |||
@@ -1,39 +1,44 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | /** | 3 | namespace Shaarli\Updater; |
4 | * Read the updates file, and return already done updates. | 4 | |
5 | * | 5 | class UpdaterUtils |
6 | * @param string $updatesFilepath Updates file path. | ||
7 | * | ||
8 | * @return array Already done update methods. | ||
9 | */ | ||
10 | function read_updates_file($updatesFilepath) | ||
11 | { | 6 | { |
12 | if (! empty($updatesFilepath) && is_file($updatesFilepath)) { | 7 | /** |
13 | $content = file_get_contents($updatesFilepath); | 8 | * Read the updates file, and return already done updates. |
14 | if (! empty($content)) { | 9 | * |
15 | return explode(';', $content); | 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 | } | ||
16 | } | 21 | } |
22 | return array(); | ||
17 | } | 23 | } |
18 | return array(); | ||
19 | } | ||
20 | 24 | ||
21 | /** | 25 | /** |
22 | * Write updates file. | 26 | * Write updates file. |
23 | * | 27 | * |
24 | * @param string $updatesFilepath Updates file path. | 28 | * @param string $updatesFilepath Updates file path. |
25 | * @param array $updates Updates array to write. | 29 | * @param array $updates Updates array to write. |
26 | * | 30 | * |
27 | * @throws Exception Couldn't write version number. | 31 | * @throws \Exception Couldn't write version number. |
28 | */ | 32 | */ |
29 | function write_updates_file($updatesFilepath, $updates) | 33 | public static function write_updates_file($updatesFilepath, $updates) |
30 | { | 34 | { |
31 | if (empty($updatesFilepath)) { | 35 | if (empty($updatesFilepath)) { |
32 | throw new Exception(t('Updates file path is not set, can\'t write updates.')); | 36 | throw new \Exception('Updates file path is not set, can\'t write updates.'); |
33 | } | 37 | } |
34 | 38 | ||
35 | $res = file_put_contents($updatesFilepath, implode(';', $updates)); | 39 | $res = file_put_contents($updatesFilepath, implode(';', $updates)); |
36 | if ($res === false) { | 40 | if ($res === false) { |
37 | throw new Exception(t('Unable to write updates in '. $updatesFilepath . '.')); | 41 | throw new \Exception('Unable to write updates in '. $updatesFilepath . '.'); |
42 | } | ||
38 | } | 43 | } |
39 | } | 44 | } |