]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/DBSync.php
Remove join profile table
[friendica.git] / src / Module / Admin / DBSync.php
1 <?php
2
3 namespace Friendica\Module\Admin;
4
5 use Friendica\Core\Renderer;
6 use Friendica\Core\Update;
7 use Friendica\Database\DBA;
8 use Friendica\Database\DBStructure;
9 use Friendica\DI;
10 use Friendica\Module\BaseAdmin;
11
12 class DBSync extends BaseAdmin
13 {
14         public static function content(array $parameters = [])
15         {
16                 parent::content($parameters);
17
18                 $a = DI::app();
19
20                 $o = '';
21
22                 if ($a->argc > 3 && $a->argv[2] === 'mark') {
23                         // @TODO: Replace with parameter from router
24                         $update = intval($a->argv[3]);
25                         if ($update) {
26                                 DI::config()->set('database', 'update_' . $update, 'success');
27                                 $curr = DI::config()->get('system', 'build');
28                                 if (intval($curr) == $update) {
29                                         DI::config()->set('system', 'build', intval($curr) + 1);
30                                 }
31                                 info(DI::l10n()->t('Update has been marked successful') . EOL);
32                         }
33                         DI::baseUrl()->redirect('admin/dbsync');
34                 }
35
36                 if ($a->argc > 2) {
37                         if ($a->argv[2] === 'check') {
38                                 // @TODO Seems like a similar logic like Update::check()
39                                 $retval = DBStructure::update($a->getBasePath(), false, true);
40                                 if ($retval === '') {
41                                         $o .= DI::l10n()->t("Database structure update %s was successfully applied.", DB_UPDATE_VERSION) . "<br />";
42                                         DI::config()->set('database', 'last_successful_update', DB_UPDATE_VERSION);
43                                         DI::config()->set('database', 'last_successful_update_time', time());
44                                 } else {
45                                         $o .= DI::l10n()->t("Executing of database structure update %s failed with error: %s", DB_UPDATE_VERSION, $retval) . "<br />";
46                                 }
47                                 if ($a->argv[2] === 'check') {
48                                         return $o;
49                                 }
50                         } elseif (intval($a->argv[2])) {
51                                 require_once 'update.php';
52
53                                 // @TODO: Replace with parameter from router
54                                 $update = intval($a->argv[2]);
55
56                                 $func = 'update_' . $update;
57
58                                 if (function_exists($func)) {
59                                         $retval = $func();
60
61                                         if ($retval === Update::FAILED) {
62                                                 $o .= DI::l10n()->t("Executing %s failed with error: %s", $func, $retval);
63                                         } elseif ($retval === Update::SUCCESS) {
64                                                 $o .= DI::l10n()->t('Update %s was successfully applied.', $func);
65                                                 DI::config()->set('database', $func, 'success');
66                                         } else {
67                                                 $o .= DI::l10n()->t('Update %s did not return a status. Unknown if it succeeded.', $func);
68                                         }
69                                 } else {
70                                         $o .= DI::l10n()->t('There was no additional update function %s that needed to be called.', $func) . "<br />";
71                                         DI::config()->set('database', $func, 'success');
72                                 }
73
74                                 return $o;
75                         }
76                 }
77
78                 $failed = [];
79                 $configStmt = DBA::select('config', ['k', 'v'], ['cat' => 'database']);
80                 while ($config = DBA::fetch($configStmt)) {
81                         $upd = intval(substr($config['k'], 7));
82                         if ($upd >= 1139 && $config['v'] != 'success') {
83                                 $failed[] = $upd;
84                         }
85                 }
86
87                 if (!count($failed)) {
88                         $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/structure_check.tpl'), [
89                                 '$base' => DI::baseUrl()->get(true),
90                                 '$banner' => DI::l10n()->t('No failed updates.'),
91                                 '$check' => DI::l10n()->t('Check database structure'),
92                         ]);
93                 } else {
94                         $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/failed_updates.tpl'), [
95                                 '$base' => DI::baseUrl()->get(true),
96                                 '$banner' => DI::l10n()->t('Failed Updates'),
97                                 '$desc' => DI::l10n()->t('This does not include updates prior to 1139, which did not return a status.'),
98                                 '$mark' => DI::l10n()->t("Mark success \x28if update was manually applied\x29"),
99                                 '$apply' => DI::l10n()->t('Attempt to execute this update step automatically'),
100                                 '$failed' => $failed
101                         ]);
102                 }
103
104                 return $o;
105         }
106 }