Skip to content

Commit b894898

Browse files
authored
Merge pull request #3410 from jeedom/feat/update-message-sync
Sync update notification message after each relevant action
2 parents 72b474a + e992ca5 commit b894898

4 files changed

Lines changed: 26 additions & 16 deletions

File tree

core/ajax/update.ajax.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
if (init('action') == 'checkAllUpdate') {
6666
unautorizedInDemo();
6767
update::checkAllUpdate();
68+
update::refreshUpdateMessage();
6869
ajax::success();
6970
}
7071

@@ -81,6 +82,7 @@
8182
}
8283
$update->doUpdate();
8384
if ($update->getType() != 'core') {
85+
update::refreshUpdateMessage();
8486
log::add('update', 'alert', __("Launch cron dependancy plugins", __FILE__));
8587
try {
8688
$cron = cron::byClassAndFunction('plugin', 'checkDeamon');
@@ -124,6 +126,7 @@
124126
throw new Exception(__('Aucune correspondance pour l\'ID :', __FILE__) . ' ' . init('id'));
125127
}
126128
$update->checkUpdate();
129+
update::refreshUpdateMessage();
127130
ajax::success();
128131
}
129132

core/class/jeedom.class.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,21 +1223,7 @@ public static function cronHourly() {
12231223
//Check for updates every 24h according to config
12241224
if (config::byKey('update::autocheck', 'core', 1) == 1 && (config::byKey('update::lastCheck') == '' || (strtotime('now') - strtotime(config::byKey('update::lastCheck'))) > (23 * 3600) || strtotime('now') < strtotime(config::byKey('update::lastCheck')))) {
12251225
update::checkAllUpdate();
1226-
$updates = update::byStatus('update');
1227-
if (count($updates) > 0) {
1228-
$toUpdate = '';
1229-
foreach ($updates as $update) {
1230-
if ($update->getConfiguration('doNotUpdate', 0) == 0) {
1231-
$toUpdate .= $update->getLogicalId() . ',';
1232-
}
1233-
}
1234-
if ($toUpdate != '') {
1235-
//set $_logicalId so update function can remove such messages. Bypassed by message::save to notify different updates instead of new occurence.
1236-
$msg = __('De nouvelles mises à jour sont disponibles', __FILE__) . ' : ' . trim($toUpdate, ',');
1237-
$action = '<a href="/index.php?v=d&p=update">' . __('Centre de mise à jour', __FILE__) . '</a>';
1238-
message::add('update', $msg, $action, 'newUpdate');
1239-
}
1240-
}
1226+
update::refreshUpdateMessage();
12411227
}
12421228
} catch (\Throwable $e) {
12431229
log::add('jeedom', 'error', log::exception($e));

core/class/update.class.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,27 @@ public static function updateAll($_filter = '') {
143143
}
144144
}
145145

146+
public static function refreshUpdateMessage() {
147+
$toUpdate = [];
148+
foreach (self::byStatus('update') as $update) {
149+
if ($update->getConfiguration('doNotUpdate', 0) == 0) {
150+
$toUpdate[] = $update->getLogicalId();
151+
}
152+
}
153+
if (!empty($toUpdate)) {
154+
$msg = __('De nouvelles mises à jour sont disponibles', __FILE__) . ' : ' . implode(', ', $toUpdate);
155+
$action = '<a href="/index.php?v=d&p=update">' . __('Centre de mise à jour', __FILE__) . '</a>';
156+
foreach (message::byPlugin(__CLASS__) as $updateMessage) {
157+
if ($updateMessage->getMessage() !== $msg) {
158+
$updateMessage->remove();
159+
}
160+
}
161+
message::add(__CLASS__, $msg, $action, 'newUpdate');
162+
} else {
163+
message::removeAll(__CLASS__);
164+
}
165+
}
166+
146167
public static function byId($_id) {
147168
$values = array(
148169
'id' => $_id,

install/update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@
348348
}
349349
echo "[PROGRESS][90]\n";
350350
try {
351-
message::removeAll('update', 'newUpdate');
352351
echo "Check update\n";
353352
update::checkAllUpdate();
353+
update::refreshUpdateMessage();
354354
echo "OK\n";
355355
} catch (Exception $ex) {
356356
echo "***ERROR*** " . $ex->getMessage() . "\n";

0 commit comments

Comments
 (0)