Skip to content

Commit 710afce

Browse files
committed
feat: added config tab for online update (#2492)
1 parent 3088691 commit 710afce

File tree

12 files changed

+107
-13
lines changed

12 files changed

+107
-13
lines changed

phpmyfaq/admin/api/configuration-list.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use Abraham\TwitterOAuth\TwitterOAuth;
2020
use phpMyFAQ\Configuration;
21+
use phpMyFAQ\Enums\ReleaseType;
2122
use phpMyFAQ\Filter;
2223
use phpMyFAQ\Helper\AdministrationHelper;
2324
use phpMyFAQ\Helper\LanguageHelper;
@@ -270,14 +271,16 @@ function renderInputForm(mixed $key, string $type): void
270271
echo $adminHelper->renderMetaRobotsDropdown($faqConfig->get($key));
271272
break;
272273

273-
case 'main.releaseEnvironment':
274+
case 'upgrade.releaseEnvironment':
274275
printf(
275-
'<option value="development" %s>Development</option>',
276-
('development' == $faqConfig->get($key)) ? 'selected' : ''
276+
'<option value="%s" %s>Development</option>',
277+
ReleaseType::DEVELOPMENT->value,
278+
(ReleaseType::DEVELOPMENT->value == $faqConfig->get($key)) ? 'selected' : ''
277279
);
278280
printf(
279-
'<option value="production" %s>Production</option>',
280-
('production' == $faqConfig->get($key)) ? 'selected' : ''
281+
'<option value="%s" %s>Release</option>',
282+
ReleaseType::RELEASE->value,
283+
(ReleaseType::RELEASE->value == $faqConfig->get($key)) ? 'selected' : ''
281284
);
282285
break;
283286
}
@@ -312,7 +315,7 @@ function renderInputForm(mixed $key, string $type): void
312315
printf(
313316
'<input type="text" readonly name="edit[%s]" class="form-control-plaintext" value="%s"></div>',
314317
$key,
315-
str_replace('"', '&quot;', $faqConfig->get($key))
318+
str_replace('"', '&quot;', $faqConfig->get($key) ?? '')
316319
);
317320
break;
318321

phpmyfaq/admin/api/upgrade.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* Private phpMyFAQ Admin API: everything for the online update
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ
11+
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
12+
* @copyright 2023 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2023-07-02
16+
*/
17+
18+
use phpMyFAQ\Filter;
19+
use Symfony\Component\HttpFoundation\JsonResponse;
20+
use Symfony\Component\HttpFoundation\Request;
21+
22+
if (!defined('IS_VALID_PHPMYFAQ')) {
23+
http_response_code(400);
24+
exit();
25+
}
26+
27+
//
28+
// Create Request & Response
29+
//
30+
$response = new JsonResponse();
31+
$request = Request::createFromGlobals();
32+
33+
$ajaxAction = Filter::filterVar($request->query->get('ajaxaction'), FILTER_SANITIZE_SPECIAL_CHARS);

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

+7
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
API
8686
</a>
8787
</li>
88+
<li role="presentation" class="nav-item">
89+
<a href="#upgrade" aria-controls="upgrade" role="tab" data-bs-toggle="tab" class="nav-link">
90+
<i aria-hidden="true" class="fa fa-refresh"></i>
91+
{{ adminConfigurationUpgradeTab }}
92+
</a>
93+
</li>
8894
</ul>
8995

9096
<div class="tab-content p-2 pt-4 pmf-configuration-panel">
@@ -98,6 +104,7 @@
98104
<div role="tabpanel" class="tab-pane fade" id="mail"></div>
99105
<div role="tabpanel" class="tab-pane fade" id="ldap"></div>
100106
<div role="tabpanel" class="tab-pane fade" id="api"></div>
107+
<div role="tabpanel" class="tab-pane fade" id="upgrade"></div>
101108
</div>
102109
</div>
103110
</div>

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,17 @@
1515
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
1616
</div>
1717

18+
<div class="row">
19+
<div class="col-12">
1820

19-
Release-Environment: {{ releaseEnvironment }}
21+
<p>
22+
Last check for updates: <output>{{ dateLastChecked }}</output>
23+
<button type="button" class="btn btn-sm btn-primary">Check for new version</button>
24+
</p>
25+
26+
<p>
27+
Release-Environment: {{ releaseEnvironment }}
28+
</p>
29+
30+
</div>
31+
</div>

phpmyfaq/admin/configuration.php

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
'adminConfigurationSeoTab' => Translation::get('seoCenter'),
113113
'adminConfigurationSocialNetworkTab' => Translation::get('socialNetworksControlCenter'),
114114
'adminConfigurationMailTab' => Translation::get('mailControlCenter'),
115+
'adminConfigurationUpgradeTab' => Translation::get('upgradeControlCenter'),
115116
];
116117

117118
echo $template->render($templateVars);

phpmyfaq/admin/index.php

+4
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@
294294
case 'image':
295295
require 'api/image.php';
296296
break;
297+
// Upgrade
298+
case 'upgrade':
299+
require 'api/upgrade.php';
300+
break;
297301
}
298302
exit();
299303
}

phpmyfaq/admin/upgrade.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
if ($user->perm->hasPermission($user->getUserId(), 'editconfig')) {
3939
$templateVars = [
4040
'adminHeaderUpgrade' => Translation::get('ad_menu_upgrade'),
41-
'releaseEnvironment' => $faqConfig->get('main.releaseEnvironment')
41+
'releaseEnvironment' => ucfirst($faqConfig->get('upgrade.releaseEnvironment')),
42+
'dateLastChecked' => $faqConfig->get('upgrade.dateLastChecked')
4243
];
4344

4445
$upgrade = new Upgrade(new System(), $faqConfig);

phpmyfaq/setup/migrations.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,6 @@
184184
// @todo move attachments in filesystem and database
185185

186186
// Automatic updates
187-
$faqConfig->add('main.releaseEnvironment', 'development');
187+
$faqConfig->add('upgrade.releaseEnvironment', 'development');
188+
$faqConfig->add('upgrade.dateLastChecked', '');
188189
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Release environment enum
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ
11+
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
12+
* @copyright 2023 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2023-07-02
16+
*/
17+
18+
namespace phpMyFAQ\Enums;
19+
20+
enum ReleaseType: string
21+
{
22+
case RELEASE = 'release';
23+
case DEVELOPMENT = 'development';
24+
}

phpmyfaq/src/phpMyFAQ/Setup/Installer.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use phpMyFAQ\Database;
2929
use phpMyFAQ\Database\DatabaseDriver;
3030
use phpMyFAQ\Entity\InstanceEntity;
31+
use phpMyFAQ\Enums\ReleaseType;
3132
use phpMyFAQ\Filter;
3233
use phpMyFAQ\Instance;
3334
use phpMyFAQ\Instance\Database as InstanceDatabase;
@@ -352,7 +353,6 @@ class Installer extends Setup
352353
'main.enableAskQuestions' => 'false',
353354
'main.enableNotifications' => 'false',
354355
'main.contactInformationHTML' => 'false',
355-
'main.releaseEnvironment' => '__PHPMYFAQ_RELEASE__',
356356

357357
'records.numberOfRecordsPerPage' => '10',
358358
'records.numberOfShownNewsEntries' => '3',
@@ -464,6 +464,9 @@ class Installer extends Setup
464464

465465
'api.enableAccess' => 'true',
466466
'api.apiClientToken' => '',
467+
468+
'upgrade.releaseEnvironment' => '__PHPMYFAQ_RELEASE__',
469+
'upgrade.dateLastChecked' => ''
467470
];
468471

469472
/**
@@ -480,7 +483,8 @@ public function __construct(protected System $system)
480483
'main.currentApiVersion' => System::getApiVersion(),
481484
'main.phpMyFAQToken' => bin2hex(random_bytes(16)),
482485
'spam.enableCaptchaCode' => (extension_loaded('gd') ? 'true' : 'false'),
483-
'main.releaseEnvironment' => System::isDevelopmentVersion() ? 'development' : 'production'
486+
'upgrade.releaseEnvironment' =>
487+
System::isDevelopmentVersion() ? ReleaseType::DEVELOPMENT->value : ReleaseType::RELEASE->value
484488
];
485489

486490
$this->mainConfig = array_merge($this->mainConfig, $dynMainConfig);

phpmyfaq/translations/language_de.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,8 @@
13301330
$PMF_LANG['msgNewQuestionAdded'] = 'Es wurde eine neue Frage hinzugefügt. Sie können diese hier oder im Adminbereich überprüfen:';
13311331

13321332
// added v3.3.0-alpha - 2023-07-02 by Thorsten
1333-
$LANG_CONF['main.releaseEnvironment'] = ['select', 'Release-Umgebung'];
1333+
$LANG_CONF['upgrade.releaseEnvironment'] = ['select', 'Release-Umgebung'];
1334+
$LANG_CONF['upgrade.dateLastChecked'] = ['print', 'Letzte Überprüfung nach Updates'];
1335+
$PMF_LANG['upgradeControlCenter'] = 'Online Update';
13341336

13351337
return $PMF_LANG;

phpmyfaq/translations/language_en.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,8 @@
13491349
$PMF_LANG['msgNewQuestionAdded'] = 'A new question was added. You can check them here or in the admin section:';
13501350

13511351
// added v3.3.0-alpha - 2023-07-02 by Thorsten
1352-
$LANG_CONF['main.releaseEnvironment'] = ['select', 'Release Environment'];
1352+
$LANG_CONF['upgrade.releaseEnvironment'] = ['select', 'Release Environment'];
1353+
$LANG_CONF['upgrade.dateLastChecked'] = ['print', 'Last check for updates'];
1354+
$PMF_LANG['upgradeControlCenter'] = 'Online Update';
13531355

13541356
return $PMF_LANG;

0 commit comments

Comments
 (0)