aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/updater/UpdaterUtils.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2018-12-03 23:49:20 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-01-12 23:11:19 +0100
commitbcf056c9d92e5240e645c76a4cdc8ae159693f9a (patch)
tree3991d2e0703276474a3fa5b0f3cccc63b2e74f19 /application/updater/UpdaterUtils.php
parent92c6439dbc41d8a2873dfebbc44e30d75c0c473d (diff)
downloadShaarli-bcf056c9d92e5240e645c76a4cdc8ae159693f9a.tar.gz
Shaarli-bcf056c9d92e5240e645c76a4cdc8ae159693f9a.tar.zst
Shaarli-bcf056c9d92e5240e645c76a4cdc8ae159693f9a.zip
namespacing: \Shaarli\Updater
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'application/updater/UpdaterUtils.php')
-rw-r--r--application/updater/UpdaterUtils.php39
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 */
10function 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 */
29function 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}