Skip to content

Commit 0d0f45f

Browse files
author
Tim Helfensdörfer
authored
Merge pull request #48 from VisualAppeal/package-update
Updated packages
2 parents fd0a225 + dfa04e1 commit 0d0f45f

17 files changed

+246
-249
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ language: php
33
dist: trusty
44

55
php:
6-
- 7.1
7-
- 7.2
86
- 7.3
7+
- 7.4
98

109
before_script:
11-
- composer install
10+
- composer install --ignore-platform-reqs
1211

1312
script:
1413
- travis_retry composer self-update

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM php:7.4-apache
2+
3+
MAINTAINER VisualAppeal <[email protected]>
4+
5+
RUN apt-get update && apt-get install -y libzip-dev libcurl4-openssl-dev
6+
RUN docker-php-ext-install -j$(nproc) zip curl
7+
8+
ADD ./vendor /var/www/html/vendor
9+
ADD ./example /var/www/html/example
10+
ADD ./src /var/www/html/src
11+
12+
RUN chown -R www-data:www-data /var/www/html/example

README.md

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,22 @@ With this library your users can automatically update their instance of your app
55
## Installation
66

77
* Install the library via composer [visualappeal/php-auto-update](https://packagist.org/packages/visualappeal/php-auto-update)
8-
* Create a update file/method in your application with your update routine (see `example/client/update/index.php`)
8+
* Create an update file/method in your application with your update routine (see `example/client/update/index.php`)
99
* Create a `update.json` or `update.ini` on your server (where the client should get the updates, see `example/server/update.json` or `example/server/update.ini`)
1010

1111
**Important: Please notice that PHP needs write permissions to update the files on the webserver**
1212

1313
## Example
1414

15-
### Client
15+
You can start an example docker container via `docker-compose up` and see the example by visiting `http://127.0.0.1:8080/example/client/`
1616

17-
#### update.php/some method
17+
## Client
1818

19-
This file will install the update. For an example see `example/client/update/index.php`
19+
### Caching
2020

21-
#### Check for new versions
21+
The library supports the `desarrolla2/cache` component, and you should use it! Otherwise, the client will download the update ini/json file on every request.
2222

23-
You can always check for new versions, e.g. in the footer. This can look like this:
24-
25-
```php
26-
<?php
27-
28-
require(__DIR__ . '/../../../vendor/autoload.php');
29-
30-
use \VisualAppeal\AutoUpdate;
31-
32-
// Download the zip update files to `__DIR__ . '/temp'`
33-
// Copy the contents of the zip file to the current directory `__DIR__`
34-
// The update process should last 60 seconds max
35-
$update = new AutoUpdate(__DIR__ . '/temp', __DIR__, 60);
36-
$update->setCurrentVersion('0.1.0'); // Current version of your application. This value should be from a database or another file which will be updated with the installation of a new version
37-
$update->setUpdateUrl('http://php-auto-update.app/update/'); //Replace the url with your server update url
38-
39-
// The following two lines are optional
40-
$update->addLogHandler(new Monolog\Handler\StreamHandler(__DIR__ . '/update.log'));
41-
$update->setCache(new Desarrolla2\Cache\Adapter\File(__DIR__ . '/cache'), 3600);
42-
43-
//Check for a new update
44-
if ($update->checkUpdate() === false)
45-
die('Could not check for updates! See log file for details.');
46-
47-
// Check if new update is available
48-
if ($update->newVersionAvailable()) {
49-
echo 'New Version: ' . $update->getLatestVersion();
50-
// Simulate or install?
51-
$simulate = true;
52-
//Install new update
53-
$result = $update->update($simulate);
54-
if ($result === true) {
55-
echo 'Update simulation successful<br>';
56-
} else {
57-
echo 'Update simulation failed: ' . $result . '!<br>';
58-
}
59-
} else {
60-
// No new update
61-
echo 'Your application is up to date';
62-
}
63-
```
64-
65-
The library supports the `desarrolla2/cache` component and you should use it! Otherwise the client will download the update ini/json file on every request.
66-
67-
### Server
23+
## Server
6824

6925
Your server needs at least one file which will be downloaded from the client to check for updates. This can be a json or an ini file. See `example/server/` for examples. The ini section key respectively the json key is the version. This library uses semantic versioning to compare the versions. See [semver.org](http://semver.org/) for details. The ini/json value is the absolute url to the update zip file. Since the library supports incremental updates, the zip file only need to contain the changes since the last version. The zip files do not need to be placed on the same server, they can be uploaded to S3 or another cloud storage, too.
7026

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"ext-json": "*",
1414
"ext-curl": "*",
1515
"ext-zip": "*",
16-
"desarrolla2/cache": "2.1.*",
17-
"monolog/monolog": "1.23.*",
18-
"php": ">= 7.1.0",
19-
"composer/semver": "1.4.*"
16+
"php": "^7.3.0",
17+
"desarrolla2/cache": "^3.0.0",
18+
"monolog/monolog": "^2.1.0",
19+
"composer/semver": "^3.0.0"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "7.4.*"
22+
"phpunit/phpunit": "^9.1.0"
2323
},
2424
"autoload": {
2525
"psr-4": {

docker-compose.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
build: .
6+
ports:
7+
- 8080:80

example/client/index.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<!DOCTYPE html>
2-
<html>
2+
<html lang="en">
33
<head>
44
<meta charset="utf-8">
55
<title>PHP Auto Update</title>
66

7-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
7+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
88
</head>
99
<body>
10-
<div class="container">
10+
<div class="container mt-4">
1111
<p>This is the test index.</p>
1212

13-
<p><a class="btn btn-primary" href="update/index.php">Update now!</a></p>
13+
<p><a class="btn btn-primary" href="/example/client/update/index.php">Update now!</a></p>
1414

15-
<p>Contents of "somefile.php":</p>
16-
<pre><?php require(__DIR__ . '/somefile.php'); ?></pre>
15+
<p>Contents of <code>somefile.php</code>:</p>
16+
<pre><code><?php require(__DIR__ . '/somefile.php'); ?></code></pre>
1717
</div>
1818
</body>
1919
</html>

example/client/update/index.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66

77
$update = new AutoUpdate(__DIR__ . '/temp', __DIR__ . '/../', 60);
88
$update->setCurrentVersion('0.1.0');
9-
$update->setUpdateUrl('http://php-auto-update.app/server'); //Replace with your server update directory
9+
// Replace with your server update directory
10+
$update->setUpdateUrl('http://127.0.0.1/example/server');
1011

11-
// Optional:
12+
// Log handler and cache are optional
1213
$update->addLogHandler(new Monolog\Handler\StreamHandler(__DIR__ . '/update.log'));
13-
// $update->setCache(new Desarrolla2\Cache\Adapter\File(__DIR__ . '/cache'), 3600);
1414

15-
//Check for a new update
15+
$cache = new Desarrolla2\Cache\File(__DIR__ . '/cache');
16+
$update->setCache($cache, 3600);
17+
18+
// Check for a new update
1619
if ($update->checkUpdate() === false) {
1720
die('Could not check for updates! See log file for details.');
1821
}
1922

2023
if ($update->newVersionAvailable()) {
21-
//Install new update
24+
// Install new update
2225
echo 'New Version: ' . $update->getLatestVersion() . '<br>';
2326
echo 'Installing Updates: <br>';
2427
echo '<pre>';
@@ -57,6 +60,7 @@ function onAllUpdateFinishCallbacks($updatedVersions)
5760
// Set the first argument (simulate) to "false" to install the update
5861
// i.e. $update->update(false);
5962
$result = $update->update();
63+
6064
if ($result === true) {
6165
echo 'Update simulation successful<br>';
6266
} else {

example/server/update.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[0.1.0]
2-
url = http://php-auto-update.app/server/0.1.0.zip
2+
url = http://127.0.0.1:80/example/server/0.1.0.zip
33

44
[0.2.0]
5-
url = http://php-auto-update.app/server/0.2.0.zip
5+
url = http://127.0.0.1:80/example/server/0.2.0.zip
66

77
[0.2.1]
8-
url = http://php-auto-update.app/server/0.2.1.zip
8+
url = http://127.0.0.1:80/example/server/0.2.1.zip

example/server/update.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"0.1.0": "http://php-auto-update.app/server/0.1.0.zip",
3-
"0.2.0": "http://php-auto-update.app/server/0.2.0.zip",
4-
"0.2.1": "http://php-auto-update.app/server/0.2.1.zip"
2+
"0.1.0": "http://127.0.0.1:80/example/server/0.1.0.zip",
3+
"0.2.0": "http://127.0.0.1:80/example/server/0.2.0.zip",
4+
"0.2.1": "http://127.0.0.1:80/example/server/0.2.1.zip"
55
}

0 commit comments

Comments
 (0)