Skip to content

Commit ba845c9

Browse files
committed
feat: added enable/disable online update, added date for last check (#2492)
1 parent 9d16d31 commit ba845c9

File tree

6 files changed

+54
-24
lines changed

6 files changed

+54
-24
lines changed

phpmyfaq/admin/assets/src/configuration/upgrade.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ export const handleCheckForUpdates = () => {
3636
throw new Error('Network response was not ok: ', { cause: { response } });
3737
})
3838
.then((response) => {
39-
if (response.version === 'current') {
40-
const element = addElement('p', { innerText: response.message });
41-
button.after(element);
42-
} else {
43-
const element = addElement('p', { innerText: response.message });
44-
button.after(element);
39+
const dateLastChecked = document.getElementById('dateLastChecked');
40+
if (dateLastChecked) {
41+
const date = new Date(response.dateLastChecked);
42+
dateLastChecked.innerText = `${date.getFullYear()}-${date.getMonth()}-${date.getDay()} ${date.getHours()}-${date.getUTCHours()}-${date.getUTCSeconds()}`;
43+
}
44+
const result = document.getElementById('result');
45+
if (result) {
46+
if (response.version === 'current') {
47+
result.replaceWith(addElement('p', { innerText: response.message }));
48+
} else {
49+
result.replaceWith(addElement('p', { innerText: response.message }));
50+
}
4551
}
4652
})
4753
.catch((error) => {

phpmyfaq/admin/assets/templates/configuration/upgrade.twig

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,27 @@
1919
<div class="col-12">
2020

2121
<p>
22-
Last check for updates: <output>{{ dateLastChecked }}</output>
23-
</p>
24-
<button type="button" class="btn btn-sm btn-primary mb-2" id="pmf-button-check-updates">Check for new version</button>
2522

26-
<p>
27-
Release-Environment: {{ releaseEnvironment }}
2823
</p>
2924

25+
<div class="card">
26+
<div class="card-body">
27+
<h5 class="card-title">Online Check for Updates</h5>
28+
<p class="card-text">
29+
Last check for updates:
30+
<output id="dateLastChecked">
31+
{{ dateLastChecked | date('Y-m-d H:i:s') }}
32+
</output>
33+
</p>
34+
<button type="button" class="btn btn-sm btn-primary mb-2" id="pmf-button-check-updates">
35+
Check for new version
36+
</button>
37+
<output id="result"></output>
38+
</div>
39+
<div class="card-footer">
40+
Release-Environment: {{ releaseEnvironment }}
41+
</div>
42+
</div>
43+
3044
</div>
3145
</div>

phpmyfaq/setup/migrations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
// @todo move attachments in filesystem and database
185185

186186
// Automatic updates
187+
$faqConfig->add('upgrade.onlineUpdateEnabled', true);
187188
$faqConfig->add('upgrade.releaseEnvironment', 'development');
188189
$faqConfig->add('upgrade.dateLastChecked', '');
189190

phpmyfaq/src/phpMyFAQ/Administration/Api/UpdateApi.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace phpMyFAQ\Administration\Api;
1919

20+
use DateTime;
21+
use DateTimeInterface;
2022
use phpMyFAQ\Administration\Api;
2123
use phpMyFAQ\Configuration;
2224
use phpMyFAQ\Core\Exception;
@@ -26,7 +28,6 @@
2628
use Symfony\Component\HttpFoundation\Response;
2729
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
2830
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
29-
use Symfony\Contracts\HttpClient\ResponseInterface;
3031

3132
class UpdateApi
3233
{
@@ -56,22 +57,28 @@ public function updates(): void
5657
public function updateCheck(): void
5758
{
5859
$response = new JsonResponse();
60+
$faqConfig = Configuration::getConfigurationInstance();
61+
$dateTime = new DateTime();
62+
$dateLastChecked = $dateTime->format(DateTimeInterface::ATOM);
5963
try {
6064
$api = new Api($this->configuration);
6165
$versions = $api->getVersions();
6266
$response->setStatusCode(Response::HTTP_OK);
67+
$faqConfig->set('upgrade.dateLastChecked', $dateLastChecked);
6368
if (version_compare($versions['installed'], $versions['current'], '<')) {
6469
$response->setData(
6570
[
6671
'version' => $versions['current'],
67-
'message' => Translation::get('currentVersion') . $versions['current']
72+
'message' => Translation::get('currentVersion') . $versions['current'],
73+
'dateLastChecked' => $dateLastChecked,
6874
]
6975
);
7076
} else {
7177
$response->setData(
7278
[
7379
'version' => 'current',
74-
'message' => Translation::get('versionIsUpToDate')
80+
'message' => Translation::get('versionIsUpToDate'),
81+
'dateLastChecked' => $dateLastChecked,
7582
]
7683
);
7784
}

phpmyfaq/translations/language_de.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,30 +1319,31 @@
13191319
$LANG_CONF['spam.mailAddressInExport'] = ['checkbox', 'E-Mail-Adresse im Export anzeigen'];
13201320
$PMF_LANG['msgNewQuestionAdded'] = 'Es wurde eine neue Frage hinzugefügt. Sie können diese hier oder im Adminbereich überprüfen:';
13211321

1322-
// added v3.3.0-alpha - 2023-07-02 by Thorsten
1322+
// added v4.0.0-alpha - 2023-07-02 by Thorsten
1323+
$LANG_CONF['upgrade.onlineUpdateEnabled'] = ['checkbox', 'Online Update aktiviert'];
13231324
$LANG_CONF['upgrade.releaseEnvironment'] = ['select', 'Release-Umgebung'];
13241325
$LANG_CONF['upgrade.dateLastChecked'] = ['print', 'Letzte Überprüfung nach Updates'];
13251326
$PMF_LANG['upgradeControlCenter'] = 'Online Update';
13261327

1327-
// added v3.3.0-alpha - 2023-07-19 by Jan
1328+
// added v4.0.0-alpha - 2023-07-19 by Jan
13281329
$PMF_LANG['msgAddBookmark'] = 'Lesezeichen hinzufügen';
13291330
$PMF_LANG['removeBookmark'] = 'Lesezeichen entfernen';
13301331
$PMF_LANG['msgBookmarkAdded'] = 'Lesezeichen erfolgreich hinzugefügt!';
13311332
$PMF_LANG['msgBookmarkRemoved'] = 'Lesezeichen erfolgreich entfernt!';
13321333

1333-
// added v3.3.0-alpha - 2023-07-11 by Jan
1334+
// added v4.0.0-alpha - 2023-07-11 by Jan
13341335
$PMF_LANG['versionIsUpToDate'] = '✅ Deine installierte Version ist aktuell.';
13351336
$PMF_LANG['currentVersion'] = 'Aktuelle Version: ';
13361337

1337-
// added v3.3.0-alpha - 2023-07-19 by Jan
1338+
// added v4.0.0-alpha - 2023-07-19 by Jan
13381339
$PMF_LANG['msgAddBookmark'] = 'Lesezeichen hinzufügen';
13391340
$PMF_LANG['removeBookmark'] = 'Lesezeichen entfernen';
13401341
$PMF_LANG['msgBookmarkAdded'] = 'Lesezeichen erfolgreich hinzugefügt!';
13411342
$PMF_LANG['msgBookmarkRemoved'] = 'Lesezeichen erfolgreich entfernt!';
13421343
$PMF_LANG['msgBookmarks'] = 'Lesezeichen';
13431344
$PMF_LANG['msgMyBookmarks'] = 'Meine Lesezeichen';
13441345

1345-
// added v3.3.0-alpha - 2023-09-20 by Jan
1346+
// added v4.0.0-alpha - 2023-09-20 by Jan
13461347
$PMF_LANG['msgNoHashAllowed'] = "Die Frage darf '#' nicht enthalten.";
13471348

13481349
return $PMF_LANG;

phpmyfaq/translations/language_en.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,30 +1338,31 @@
13381338
$LANG_CONF['spam.mailAddressInExport'] = ['checkbox', 'Show email address in exports'];
13391339
$PMF_LANG['msgNewQuestionAdded'] = 'A new question was added. You can check them here or in the admin section:';
13401340

1341-
// added v3.3.0-alpha - 2023-07-02 by Thorsten
1341+
// added v4.0.0-alpha - 2023-07-02 by Thorsten
1342+
$LANG_CONF['upgrade.onlineUpdateEnabled'] = ['checkbox', 'Online Update enabled'];
13421343
$LANG_CONF['upgrade.releaseEnvironment'] = ['select', 'Release Environment'];
13431344
$LANG_CONF['upgrade.dateLastChecked'] = ['print', 'Last check for updates'];
13441345
$PMF_LANG['upgradeControlCenter'] = 'Online Update';
13451346

1346-
// added v3.3.0-alpha - 2023-07-19 by Jan
1347+
// added v4.0.0-alpha - 2023-07-19 by Jan
13471348
$PMF_LANG['msgAddBookmark'] = 'Add bookmark';
13481349
$PMF_LANG['removeBookmark'] = 'Remove bookmark';
13491350
$PMF_LANG['msgBookmarkAdded'] = 'Bookmark successfully added!';
13501351
$PMF_LANG['msgBookmarkRemoved'] = 'Bookmark successfully removed!';
13511352

1352-
// added v3.3.0-alpha - 2023-07-11 by Jan
1353+
// added v4.0.0-alpha - 2023-07-11 by Jan
13531354
$PMF_LANG['versionIsUpToDate'] = '✅ Your installed version is up-to-date!';
13541355
$PMF_LANG['currentVersion'] = 'Current Version: ';
13551356

1356-
// added v3.3.0-alpha - 2023-07-19 by Jan
1357+
// added v4.0.0-alpha - 2023-07-19 by Jan
13571358
$PMF_LANG['msgAddBookmark'] = 'Add bookmark';
13581359
$PMF_LANG['removeBookmark'] = 'Remove bookmark';
13591360
$PMF_LANG['msgBookmarkAdded'] = 'Bookmark added successfully!';
13601361
$PMF_LANG['msgBookmarkRemoved'] = 'Bookmark removed successfully!';
13611362
$PMF_LANG['msgBookmarks'] = 'Bookmarks';
13621363
$PMF_LANG['msgMyBookmarks'] = 'My Bookmarks';
13631364

1364-
// added v3.3.0-alpha - 2023-09-20 by Jan
1365+
// added v4.0.0-alpha - 2023-09-20 by Jan
13651366
$PMF_LANG['msgNoHashAllowed'] = "It is not allowed to use '#'.";
13661367

13671368
return $PMF_LANG;

0 commit comments

Comments
 (0)