Add "check for updates" button to "about" page

This commit is contained in:
Dmitriy Simushev 2015-05-26 14:19:09 +00:00
parent 930ea9a6ac
commit 2fc85b1068
3 changed files with 51 additions and 1 deletions

View File

@ -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

View File

@ -19,6 +19,7 @@
namespace Mibew\Controller;
use Mibew\Maintenance\UpdateChecker;
use Mibew\Maintenance\Updater;
use Mibew\Style\PageStyle;
use Symfony\Component\HttpFoundation\Request;
@ -33,6 +34,11 @@ class UpdateController extends AbstractController
*/
protected $updater = null;
/**
* @var UpdateChecker|null
*/
protected $updateChecker = null;
/**
* Renders update intro page.
*
@ -74,6 +80,26 @@ class UpdateController extends AbstractController
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}
*/
@ -99,4 +125,18 @@ class UpdateController extends AbstractController
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;
}
}

View File

@ -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}}
@ -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">