3 namespace Friendica\Module\Admin;
\r
5 use Friendica\Core\Config;
\r
6 use Friendica\Core\L10n;
\r
7 use Friendica\Core\Renderer;
\r
8 use Friendica\Core\System;
\r
9 use Friendica\Core\Update;
\r
10 use Friendica\Database\DBA;
\r
11 use Friendica\Database\DBStructure;
\r
12 use Friendica\Module\BaseAdminModule;
\r
13 use Friendica\Util\Strings;
\r
15 class DBSync extends BaseAdminModule
\r
17 public static function content()
\r
21 $a = self::getApp();
\r
25 if ($a->argc > 3 && $a->argv[2] === 'mark') {
\r
26 // @TODO: Replace with parameter from router
\r
27 $update = intval($a->argv[3]);
\r
29 Config::set('database', 'update_' . $update, 'success');
\r
30 $curr = Config::get('system', 'build');
\r
31 if (intval($curr) == $update) {
\r
32 Config::set('system', 'build', intval($curr) + 1);
\r
34 info(L10n::t('Update has been marked successful') . EOL);
\r
36 $a->internalRedirect('admin/dbsync');
\r
40 if ($a->argv[2] === 'check') {
\r
41 $retval = DBStructure::update($a->getBasePath(), false, true);
\r
42 if ($retval === '') {
\r
43 $o .= L10n::t("Database structure update %s was successfully applied.", DB_UPDATE_VERSION) . "<br />";
\r
44 Config::set('database', 'last_successful_update', DB_UPDATE_VERSION);
\r
45 Config::set('database', 'last_successful_update_time', time());
\r
47 $o .= L10n::t("Executing of database structure update %s failed with error: %s", DB_UPDATE_VERSION, $retval) . "<br />";
\r
49 if ($a->argv[2] === 'check') {
\r
52 } elseif (intval($a->argv[2])) {
\r
53 require_once 'update.php';
\r
55 // @TODO: Replace with parameter from router
\r
56 $update = intval($a->argv[2]);
\r
58 $func = 'update_' . $update;
\r
60 if (function_exists($func)) {
\r
63 if ($retval === Update::FAILED) {
\r
64 $o .= L10n::t("Executing %s failed with error: %s", $func, $retval);
\r
65 } elseif ($retval === Update::SUCCESS) {
\r
66 $o .= L10n::t('Update %s was successfully applied.', $func);
\r
67 Config::set('database', $func, 'success');
\r
69 $o .= L10n::t('Update %s did not return a status. Unknown if it succeeded.', $func);
\r
72 $o .= L10n::t('There was no additional update function %s that needed to be called.', $func) . "<br />";
\r
73 Config::set('database', $func, 'success');
\r
81 $configStmt = DBA::select('config', ['k', 'v'], ['cat' => 'database']);
\r
82 while ($config = DBA::fetch($configStmt)) {
\r
83 $upd = intval(substr($config['k'], 7));
\r
84 if ($upd >= 1139 && $config['v'] != 'success') {
\r
89 if (!count($failed)) {
\r
90 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/structure_check.tpl'), [
\r
91 '$base' => System::baseUrl(true),
\r
92 '$banner' => L10n::t('No failed updates.'),
\r
93 '$check' => L10n::t('Check database structure'),
\r
96 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/failed_updates.tpl'), [
\r
97 '$base' => System::baseUrl(true),
\r
98 '$banner' => L10n::t('Failed Updates'),
\r
99 '$desc' => L10n::t('This does not include updates prior to 1139, which did not return a status.'),
\r
100 '$mark' => L10n::t("Mark success \x28if update was manually applied\x29"),
\r
101 '$apply' => L10n::t('Attempt to execute this update step automatically'),
\r
102 '$failed' => $failed
\r