Skip to content

Commit

Permalink
Merge pull request #51 from kingstarter/master
Browse files Browse the repository at this point in the history
New default source repository type : Http directory listing archive
  • Loading branch information
codedge authored Apr 2, 2019
2 parents 84d08a9 + f42aa2a commit 3f2f920
Show file tree
Hide file tree
Showing 6 changed files with 348 additions and 25 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ of your software.
Just make sure you set the proper repository in your `config/self-updater.php`
file.

### Using Http archives
The package comes with an _Http_ source repository type to fetch
releases from an HTTP directory listing containing zip archives.

To run with HTTP archives, use following settings in your `.env` file:

| Config name | Value / Description |
| ----------- | ----------- |
| SELF_UPDATER_SOURCE | `http` |
| SELF_UPDATER_REPO_URL | Archive URL, e.g. `http://archive.webapp/` |
| SELF_UPDATER_PKG_FILENAME_FORMAT | Zip package filename format |
| SELF_UPDATER_DOWNLOAD_PATH | Download path on the webapp host server|

The archive URL should contain nothing more than a simple directory listing with corresponding zip-Archives.

`SELF_UPDATER_PKG_FILENAME_FORMAT` contains the filename format for all webapp update packages. I.e. when the update packages listed on the archive URL contain names like `webapp-v1.2.0.zip`, `webapp-v1.3.5.zip`, ... then the format should be `webapp-v_VERSION_`. The `_VERSION_` part is used as semantic versionioning variable for `MAJOR.MINOR.PATCH` versioning. The zip-extension is automatically added.

The target archive files must be zip archives and should contain all files on root level, not within an additional folder named like the archive itself.

## Extending and adding new source repository types
You want to pull your new versions from elsewhere? Feel free to create
your own source repository type somewhere but keep in mind for the new
Expand Down
7 changes: 7 additions & 0 deletions config/self-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
| A repository can be of different types, which can be specified here.
| Current options:
| - github
| - http
|
*/

Expand All @@ -43,6 +44,12 @@
'repository_url' => '',
'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'),
],
'http' => [
'type' => 'http',
'repository_url' => env('SELF_UPDATER_REPO_URL', ''),
'pkg_filename_format' => env('SELF_UPDATER_PKG_FILENAME_FORMAT', 'v_VERSION_'),
'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'),
],
],

/*
Expand Down
17 changes: 5 additions & 12 deletions src/Listeners/SendUpdateAvailableNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Codedge\Updater\Listeners;

use Illuminate\Log\Writer;
use Illuminate\Mail\Mailer;
use Illuminate\Support\Facades\Log;
use Codedge\Updater\Events\UpdateAvailable;

/**
Expand All @@ -14,11 +14,6 @@
*/
class SendUpdateAvailableNotification
{
/**
* @var \Monolog\Logger
*/
protected $logger;

/**
* @var Mailer
*/
Expand All @@ -27,12 +22,10 @@ class SendUpdateAvailableNotification
/**
* SendUpdateAvailableNotification constructor.
*
* @param Writer $logger
* @param Mailer $mailer
*/
public function __construct(Writer $logger, Mailer $mailer)
public function __construct(Mailer $mailer)
{
$this->logger = $logger->getMonolog();
$this->mailer = $mailer;
}

Expand All @@ -44,22 +37,22 @@ public function __construct(Writer $logger, Mailer $mailer)
public function handle(UpdateAvailable $event)
{
if (config('self-update.log_events')) {
$this->logger->addInfo('['.$event->getEventName().'] event: Notification triggered.');
Log::info('['.$event->getEventName().'] event: Notification triggered.');
}

$sendToAddress = config('self-update.mail_to.address');
$sendToName = config('self-update.mail_to.name');
$subject = config('self-update.mail_to.subject_update_available');

if (empty($sendToAddress)) {
$this->logger->addCritical(
Log::critical(
'['.$event->getEventName().'] event: '
.'Missing recipient email address. Please set SELF_UPDATER_MAILTO_ADDRESS in your .env file.'
);
}

if (empty($sendToName)) {
$this->logger->addWarning(
Log::warning(
'['.$event->getEventName().'] event: '
.'Missing recipient email name. Please set SELF_UPDATER_MAILTO_NAME in your .env file.'
);
Expand Down
19 changes: 6 additions & 13 deletions src/Listeners/SendUpdateSucceededNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Codedge\Updater\Listeners;

use Illuminate\Log\Writer;
use Illuminate\Mail\Mailer;
use Illuminate\Support\Facades\Log;
use Codedge\Updater\Events\UpdateSucceeded;

/**
Expand All @@ -14,11 +14,6 @@
*/
class SendUpdateSucceededNotification
{
/**
* @var \Monolog\Logger
*/
protected $logger;

/**
* @var Mailer
*/
Expand All @@ -27,12 +22,10 @@ class SendUpdateSucceededNotification
/**
* SendUpdateAvailableNotification constructor.
*
* @param Writer $logger
* @param Mailer $mailer
*/
public function __construct(Writer $logger, Mailer $mailer)
public function __construct(Mailer $mailer)
{
$this->logger = $logger->getMonolog();
$this->mailer = $mailer;
}

Expand All @@ -44,22 +37,22 @@ public function __construct(Writer $logger, Mailer $mailer)
public function handle(UpdateSucceeded $event)
{
if (config('self-update.log_events')) {
$this->logger->addInfo('['.$event->getEventName().'] event: Notification triggered.');
Log::info('['.$event->getEventName().'] event: Notification triggered.');
}

$sendToAddress = config('self-update.mail_to.address');
$sendToName = config('self-update.mail_to.name');
$subject = config('self-update.mail_to.subject_update_succeeded');

if (empty($sendToAddress)) {
$this->logger->addCritical(
Log::critical(
'['.$event->getEventName().'] event: '
.'Missing recipient email address. Please set SELF_UPDATER_MAILTO_ADDRESS in your .env file.'
);
}

if (empty($sendToName)) {
$this->logger->addWarning(
Log::warning(
'['.$event->getEventName().'] event: '
.'Missing recipient email name. Please set SELF_UPDATER_MAILTO_NAME in your .env file.'
);
Expand All @@ -68,7 +61,7 @@ public function handle(UpdateSucceeded $event)
$this->mailer->send(
'vendor.self-update.mails.update-available',
[
'newVersion' => $event->getVersionAvailable(),
'newVersion' => $event->getVersionUpdatedTo(),
],
function ($m) use ($subject, $sendToAddress, $sendToName) {
$m->subject($subject);
Expand Down
Loading

0 comments on commit 3f2f920

Please sign in to comment.