Skip to content

Commit

Permalink
Add "check for updates" button to "about" page
Browse files Browse the repository at this point in the history
  • Loading branch information
JustBlackBird committed May 26, 2015
1 parent 930ea9a commit 2fc85b1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/mibew/configs/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,13 @@ update_run:
_access_check: Mibew\AccessControl\Check\PermissionsCheck
_access_permissions: [CAN_ADMINISTRATE]

update_check:
path: /update/check
defaults:
_controller: Mibew\Controller\UpdateController::checkUpdatesAction
_access_check: Mibew\AccessControl\Check\PermissionsCheck
_access_permissions: [CAN_ADMINISTRATE]

## Users (visitors avaiting page)
users:
path: /operator/users
Expand Down
40 changes: 40 additions & 0 deletions src/mibew/libs/classes/Mibew/Controller/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace Mibew\Controller;

use Mibew\Maintenance\UpdateChecker;
use Mibew\Maintenance\Updater;
use Mibew\Style\PageStyle;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -33,6 +34,11 @@ class UpdateController extends AbstractController
*/
protected $updater = null;

/**
* @var UpdateChecker|null
*/
protected $updateChecker = null;

/**
* Renders update intro page.
*
Expand Down Expand Up @@ -74,6 +80,26 @@ public function runUpdateAction(Request $request)
return $this->render('update_progress', $parameters);
}

/**
* Runs the Update checker.
*
* @param Request $request Incoming request.
* @return Response|string Rendered page contents or Symfony's response
* object.
*/
public function checkUpdatesAction(Request $request)
{
$checker = $this->getUpdateChecker();
$success = $checker->run();
if (!$success) {
foreach ($checker->getErrors() as $error) {
trigger_error('Update checking failed: ' . $error, E_USER_WARNING);
}
}

return $this->redirect($this->generateUrl('about'));
}

/**
* {@inheritdoc}
*/
Expand All @@ -99,4 +125,18 @@ protected function getUpdater()

return $this->updater;
}

/**
* Returns an instance of Update Checker.
*
* @return UpdateChecker
*/
protected function getUpdateChecker()
{
if (is_null($this->updateChecker)) {
$this->updateChecker = new UpdateChecker();
}

return $this->updateChecker;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

<br/><br/>

<h2>{{l10n "Available updates"}}</h2>
{{#if availableUpdates}}
<h2>{{l10n "Available updates"}}</h2>
{{#each availableUpdates}}
<h3>{{title}} ({{version}})</h3>
{{#if description}}
Expand All @@ -47,7 +47,10 @@

<br/>
{{/each}}
{{else}}
There is no available updates.<br/><br/>
{{/if}}
<a href="{{route "update_check"}}">{{l10n "Check for available updates"}}</a>
</div>

<div class="form-footer">
Expand Down

0 comments on commit 2fc85b1

Please sign in to comment.