Dismiss the notifications when the update is already installed
This commit is contained in:
parent
752ec68e18
commit
d2553a4f6e
|
@ -40,8 +40,9 @@ if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$manager = \OC::$server->getNotificationManager();
|
$manager = \OC::$server->getNotificationManager();
|
||||||
$manager->registerNotifier(function() {
|
$manager->registerNotifier(function() use ($manager) {
|
||||||
return new \OCA\UpdateNotification\Notification\Notifier(
|
return new \OCA\UpdateNotification\Notification\Notifier(
|
||||||
|
$manager,
|
||||||
\OC::$server->getL10NFactory()
|
\OC::$server->getL10NFactory()
|
||||||
);
|
);
|
||||||
}, function() use ($l) {
|
}, function() use ($l) {
|
||||||
|
|
|
@ -22,23 +22,33 @@
|
||||||
namespace OCA\UpdateNotification\Notification;
|
namespace OCA\UpdateNotification\Notification;
|
||||||
|
|
||||||
|
|
||||||
use OCP\App\IAppManager;
|
|
||||||
use OCP\L10N\IFactory;
|
use OCP\L10N\IFactory;
|
||||||
|
use OCP\Notification\IManager;
|
||||||
use OCP\Notification\INotification;
|
use OCP\Notification\INotification;
|
||||||
use OCP\Notification\INotifier;
|
use OCP\Notification\INotifier;
|
||||||
|
|
||||||
class Notifier implements INotifier {
|
class Notifier implements INotifier {
|
||||||
|
|
||||||
|
/** @var IManager */
|
||||||
|
protected $notificationManager;
|
||||||
|
|
||||||
/** @var IFactory */
|
/** @var IFactory */
|
||||||
protected $l10NFactory;
|
protected $l10NFactory;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
protected $appVersions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifier constructor.
|
* Notifier constructor.
|
||||||
*
|
*
|
||||||
|
* @param IManager $notificationManager
|
||||||
* @param IFactory $l10NFactory
|
* @param IFactory $l10NFactory
|
||||||
*/
|
*/
|
||||||
public function __construct(IFactory $l10NFactory) {
|
public function __construct(IManager $notificationManager, IFactory $l10NFactory) {
|
||||||
|
$this->notificationManager = $notificationManager;
|
||||||
$this->l10NFactory = $l10NFactory;
|
$this->l10NFactory = $l10NFactory;
|
||||||
|
$this->appVersions = $this->getAppVersions();
|
||||||
|
\OC::$server->getLogger()->error(json_encode($this->appVersions));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,12 +66,44 @@ class Notifier implements INotifier {
|
||||||
$l = $this->l10NFactory->get('updatenotification', $languageCode);
|
$l = $this->l10NFactory->get('updatenotification', $languageCode);
|
||||||
if ($notification->getObjectType() === 'core') {
|
if ($notification->getObjectType() === 'core') {
|
||||||
$appName = $l->t('ownCloud core');
|
$appName = $l->t('ownCloud core');
|
||||||
|
|
||||||
|
$this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions());
|
||||||
} else {
|
} else {
|
||||||
$appInfo = \OC_App::getAppInfo($notification->getObjectType());
|
$appInfo = $this->getAppInfo($notification->getObjectType());
|
||||||
$appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name'];
|
$appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name'];
|
||||||
|
|
||||||
|
if (isset($this->appVersions[$notification->getObjectType()])) {
|
||||||
|
$this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()]));
|
$notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()]));
|
||||||
return $notification;
|
return $notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the notification and prevent rendering, when the update is installed
|
||||||
|
*
|
||||||
|
* @param INotification $notification
|
||||||
|
* @param string $installedVersion
|
||||||
|
* @throws \InvalidArgumentException When the update is already installed
|
||||||
|
*/
|
||||||
|
protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) {
|
||||||
|
if (version_compare($notification->getObjectId(), $installedVersion, '<=')) {
|
||||||
|
$this->notificationManager->markProcessed($notification);
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getCoreVersions() {
|
||||||
|
return implode('.', \OCP\Util::getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getAppVersions() {
|
||||||
|
return \OC_App::getAppVersions();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getAppInfo($appId) {
|
||||||
|
return \OC_App::getAppInfo($appId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue