-<?php\r
-\r
-namespace Friendica\Module\Admin;\r
-\r
-use Friendica\Core\Config;\r
-use Friendica\Core\L10n;\r
-use Friendica\Core\Renderer;\r
-use Friendica\Core\Update;\r
-use Friendica\Database\DBA;\r
-use Friendica\Database\DBStructure;\r
-use Friendica\Module\BaseAdminModule;\r
-\r
-class DBSync extends BaseAdminModule\r
-{\r
- public static function content()\r
- {\r
- parent::content();\r
-\r
- $a = self::getApp();\r
-\r
- $o = '';\r
-\r
- if ($a->argc > 3 && $a->argv[2] === 'mark') {\r
- // @TODO: Replace with parameter from router\r
- $update = intval($a->argv[3]);\r
- if ($update) {\r
- Config::set('database', 'update_' . $update, 'success');\r
- $curr = Config::get('system', 'build');\r
- if (intval($curr) == $update) {\r
- Config::set('system', 'build', intval($curr) + 1);\r
- }\r
- info(L10n::t('Update has been marked successful') . EOL);\r
- }\r
- $a->internalRedirect('admin/dbsync');\r
- }\r
-\r
- if ($a->argc > 2) {\r
- if ($a->argv[2] === 'check') {\r
- // @TODO Seems like a similar logic like Update::check()\r
- $retval = DBStructure::update($a->getBasePath(), false, true);\r
- if ($retval === '') {\r
- $o .= L10n::t("Database structure update %s was successfully applied.", DB_UPDATE_VERSION) . "<br />";\r
- Config::set('database', 'last_successful_update', DB_UPDATE_VERSION);\r
- Config::set('database', 'last_successful_update_time', time());\r
- } else {\r
- $o .= L10n::t("Executing of database structure update %s failed with error: %s", DB_UPDATE_VERSION, $retval) . "<br />";\r
- }\r
- if ($a->argv[2] === 'check') {\r
- return $o;\r
- }\r
- } elseif (intval($a->argv[2])) {\r
- require_once 'update.php';\r
-\r
- // @TODO: Replace with parameter from router\r
- $update = intval($a->argv[2]);\r
-\r
- $func = 'update_' . $update;\r
-\r
- if (function_exists($func)) {\r
- $retval = $func();\r
-\r
- if ($retval === Update::FAILED) {\r
- $o .= L10n::t("Executing %s failed with error: %s", $func, $retval);\r
- } elseif ($retval === Update::SUCCESS) {\r
- $o .= L10n::t('Update %s was successfully applied.', $func);\r
- Config::set('database', $func, 'success');\r
- } else {\r
- $o .= L10n::t('Update %s did not return a status. Unknown if it succeeded.', $func);\r
- }\r
- } else {\r
- $o .= L10n::t('There was no additional update function %s that needed to be called.', $func) . "<br />";\r
- Config::set('database', $func, 'success');\r
- }\r
-\r
- return $o;\r
- }\r
- }\r
-\r
- $failed = [];\r
- $configStmt = DBA::select('config', ['k', 'v'], ['cat' => 'database']);\r
- while ($config = DBA::fetch($configStmt)) {\r
- $upd = intval(substr($config['k'], 7));\r
- if ($upd >= 1139 && $config['v'] != 'success') {\r
- $failed[] = $upd;\r
- }\r
- }\r
-\r
- if (!count($failed)) {\r
- $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/structure_check.tpl'), [\r
- '$base' => $a->getBaseURL(true),\r
- '$banner' => L10n::t('No failed updates.'),\r
- '$check' => L10n::t('Check database structure'),\r
- ]);\r
- } else {\r
- $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/failed_updates.tpl'), [\r
- '$base' => $a->getBaseURL(true),\r
- '$banner' => L10n::t('Failed Updates'),\r
- '$desc' => L10n::t('This does not include updates prior to 1139, which did not return a status.'),\r
- '$mark' => L10n::t("Mark success \x28if update was manually applied\x29"),\r
- '$apply' => L10n::t('Attempt to execute this update step automatically'),\r
- '$failed' => $failed\r
- ]);\r
- }\r
-\r
- return $o;\r
- }\r
-}\r
+<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Admin;
+
+use Friendica\Core\Renderer;
+use Friendica\Core\Update;
+use Friendica\Database\DBA;
+use Friendica\Database\DBStructure;
+use Friendica\DI;
+use Friendica\Module\BaseAdmin;
+
+class DBSync extends BaseAdmin
+{
+ public static function content(array $parameters = [])
+ {
+ parent::content($parameters);
+
+ $a = DI::app();
+
+ $action = $parameters['action'] ?? '';
+ $update = $parameters['update'] ?? 0;
+
+ switch ($action) {
+ case 'mark':
+ if ($update) {
+ DI::config()->set('database', 'update_' . $update, 'success');
+ $curr = DI::config()->get('system', 'build');
+ if (intval($curr) == $update) {
+ DI::config()->set('system', 'build', intval($curr) + 1);
+ }
+
+ info(DI::l10n()->t('Update has been marked successful'));
+ }
+
+ break;
+ case 'check':
+ // @TODO Seems like a similar logic like Update::check()
+ $retval = DBStructure::update($a->getBasePath(), false, true);
+ if ($retval === '') {
+ $o = DI::l10n()->t("Database structure update %s was successfully applied.", DB_UPDATE_VERSION) . "<br />";
+ DI::config()->set('database', 'last_successful_update', DB_UPDATE_VERSION);
+ DI::config()->set('database', 'last_successful_update_time', time());
+ } else {
+ $o = DI::l10n()->t("Executing of database structure update %s failed with error: %s", DB_UPDATE_VERSION, $retval) . "<br />";
+ }
+
+ return $o;
+ case 'update':
+ require_once 'update.php';
+
+ // @TODO: Replace with parameter from router
+ if ($update) {
+ $func = 'update_' . $update;
+
+ if (function_exists($func)) {
+ $retval = $func();
+
+ if ($retval === Update::FAILED) {
+ $o = DI::l10n()->t("Executing %s failed with error: %s", $func, $retval);
+ } elseif ($retval === Update::SUCCESS) {
+ $o = DI::l10n()->t('Update %s was successfully applied.', $func);
+ DI::config()->set('database', $func, 'success');
+ } else {
+ $o = DI::l10n()->t('Update %s did not return a status. Unknown if it succeeded.', $func);
+ }
+ } else {
+ $o = DI::l10n()->t('There was no additional update function %s that needed to be called.', $func) . "<br />";
+ DI::config()->set('database', $func, 'success');
+ }
+
+ return $o;
+ }
+
+ break;
+ default:
+ $failed = [];
+ $configStmt = DBA::select('config', ['k', 'v'], ['cat' => 'database']);
+ while ($config = DBA::fetch($configStmt)) {
+ $upd = intval(substr($config['k'], 7));
+ if ($upd >= 1139 && $config['v'] != 'success') {
+ $failed[] = $upd;
+ }
+ }
+ DBA::close($configStmt);
+
+ if (!count($failed)) {
+ $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/structure_check.tpl'), [
+ '$base' => DI::baseUrl()->get(true),
+ '$banner' => DI::l10n()->t('No failed updates.'),
+ '$check' => DI::l10n()->t('Check database structure'),
+ ]);
+ } else {
+ $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/failed_updates.tpl'), [
+ '$base' => DI::baseUrl()->get(true),
+ '$banner' => DI::l10n()->t('Failed Updates'),
+ '$desc' => DI::l10n()->t('This does not include updates prior to 1139, which did not return a status.'),
+ '$mark' => DI::l10n()->t("Mark success \x28if update was manually applied\x29"),
+ '$apply' => DI::l10n()->t('Attempt to execute this update step automatically'),
+ '$failed' => $failed
+ ]);
+ }
+
+ return $o;
+ }
+
+ DI::baseUrl()->redirect('admin/dbsync');
+ return '';
+ }
+}