summaryrefslogtreecommitdiffstats
path: root/apps/updatenotification
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-05-04 16:34:54 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2016-05-24 11:26:52 +0200
commitd2553a4f6e14181d7788e42d1c70285ebb40f736 (patch)
tree1e90b7a43f26a839c74b08d214557bb729e1486f /apps/updatenotification
parent752ec68e18fb1bd4abe8237dd858d42d11531926 (diff)
downloadnextcloud-server-d2553a4f6e14181d7788e42d1c70285ebb40f736.tar.gz
nextcloud-server-d2553a4f6e14181d7788e42d1c70285ebb40f736.zip
Dismiss the notifications when the update is already installed
Diffstat (limited to 'apps/updatenotification')
-rw-r--r--apps/updatenotification/appinfo/app.php3
-rw-r--r--apps/updatenotification/lib/Notification/Notifier.php48
2 files changed, 47 insertions, 4 deletions
diff --git a/apps/updatenotification/appinfo/app.php b/apps/updatenotification/appinfo/app.php
index 2457ec21018..de78da5da76 100644
--- a/apps/updatenotification/appinfo/app.php
+++ b/apps/updatenotification/appinfo/app.php
@@ -40,8 +40,9 @@ if(\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) {
}
$manager = \OC::$server->getNotificationManager();
- $manager->registerNotifier(function() {
+ $manager->registerNotifier(function() use ($manager) {
return new \OCA\UpdateNotification\Notification\Notifier(
+ $manager,
\OC::$server->getL10NFactory()
);
}, function() use ($l) {
diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php
index 94fe610dd25..62c4819fb1e 100644
--- a/apps/updatenotification/lib/Notification/Notifier.php
+++ b/apps/updatenotification/lib/Notification/Notifier.php
@@ -22,23 +22,33 @@
namespace OCA\UpdateNotification\Notification;
-use OCP\App\IAppManager;
use OCP\L10N\IFactory;
+use OCP\Notification\IManager;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
class Notifier implements INotifier {
+ /** @var IManager */
+ protected $notificationManager;
+
/** @var IFactory */
protected $l10NFactory;
+ /** @var string[] */
+ protected $appVersions;
+
/**
* Notifier constructor.
*
+ * @param IManager $notificationManager
* @param IFactory $l10NFactory
*/
- public function __construct(IFactory $l10NFactory) {
+ public function __construct(IManager $notificationManager, IFactory $l10NFactory) {
+ $this->notificationManager = $notificationManager;
$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);
if ($notification->getObjectType() === 'core') {
$appName = $l->t('ownCloud core');
+
+ $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions());
} else {
- $appInfo = \OC_App::getAppInfo($notification->getObjectType());
+ $appInfo = $this->getAppInfo($notification->getObjectType());
$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()]));
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);
+ }
}