]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Summary.php
Fix issue 8551: Last item is now displayed again
[friendica.git] / src / Module / Admin / Summary.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Admin;
23
24 use Friendica\Core\Addon;
25 use Friendica\Core\Config\Cache;
26 use Friendica\Core\Logger;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Update;
29 use Friendica\Database\DBA;
30 use Friendica\Database\DBStructure;
31 use Friendica\DI;
32 use Friendica\Model\Register;
33 use Friendica\Module\BaseAdmin;
34 use Friendica\Network\HTTPException\InternalServerErrorException;
35 use Friendica\Util\ConfigFileLoader;
36 use Friendica\Util\DateTimeFormat;
37 use Friendica\Util\Network;
38
39 class Summary extends BaseAdmin
40 {
41         public static function content(array $parameters = [])
42         {
43                 parent::content($parameters);
44
45                 $a = DI::app();
46
47                 // are there MyISAM tables in the DB? If so, trigger a warning message
48                 $warningtext = [];
49                 if (DBA::count(['information_schema' => 'tables'], ['engine' => 'myisam', 'table_schema' => DBA::databaseName()])) {
50                         $warningtext[] = DI::l10n()->t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php bin/console.php dbstructure toinnodb</tt> of your Friendica installation for an automatic conversion.<br />', 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
51                 }
52
53                 // are there InnoDB tables in Antelope in the DB? If so, trigger a warning message
54                 if (DBA::count(['information_schema' => 'tables'], ['ENGINE' => 'InnoDB', 'ROW_FORMAT' => ['COMPACT', 'REDUNDANT'], 'table_schema' => DBA::databaseName()])) {
55                         $warningtext[] = DI::l10n()->t('Your DB still runs with InnoDB tables in the Antelope file format. You should change the file format to Barracuda. Friendica is using features that are not provided by the Antelope format. See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php bin/console.php dbstructure toinnodb</tt> of your Friendica installation for an automatic conversion.<br />', 'https://dev.mysql.com/doc/refman/5.7/en/innodb-file-format.html');
56                 }
57
58                 // Check if github.com/friendica/master/VERSION is higher then
59                 // the local version of Friendica. Check is opt-in, source may be master or devel branch
60                 if (DI::config()->get('system', 'check_new_version_url', 'none') != 'none') {
61                         $gitversion = DI::config()->get('system', 'git_friendica_version');
62                         if (version_compare(FRIENDICA_VERSION, $gitversion) < 0) {
63                                 $warningtext[] = DI::l10n()->t('There is a new version of Friendica available for download. Your current version is %1$s, upstream version is %2$s', FRIENDICA_VERSION, $gitversion);
64                         }
65                 }
66
67                 if (DI::config()->get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) {
68                         DBStructure::update($a->getBasePath(), false, true);
69                 }
70
71                 if (DI::config()->get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) {
72                         $warningtext[] = DI::l10n()->t('The database update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear.');
73                 }
74
75                 if (DI::config()->get('system', 'update') == Update::FAILED) {
76                         $warningtext[] = DI::l10n()->t('The last update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear. (Some of the errors are possibly inside the logfile.)');
77                 }
78
79                 $last_worker_call = DI::config()->get('system', 'last_worker_execution', false);
80                 if (!$last_worker_call) {
81                         $warningtext[] = DI::l10n()->t('The worker was never executed. Please check your database structure!');
82                 } elseif ((strtotime(DateTimeFormat::utcNow()) - strtotime($last_worker_call)) > 60 * 60) {
83                         $warningtext[] = DI::l10n()->t('The last worker execution was on %s UTC. This is older than one hour. Please check your crontab settings.', $last_worker_call);
84                 }
85
86                 // Legacy config file warning
87                 if (file_exists('.htconfig.php')) {
88                         $warningtext[] = DI::l10n()->t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from <code>.htconfig.php</code>. See <a href="%s">the Config help page</a> for help with the transition.', DI::baseUrl()->get() . '/help/Config');
89                 }
90
91                 if (file_exists('config/local.ini.php')) {
92                         $warningtext[] = DI::l10n()->t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from <code>config/local.ini.php</code>. See <a href="%s">the Config help page</a> for help with the transition.', DI::baseUrl()->get() . '/help/Config');
93                 }
94
95                 // Check server vitality
96                 if (!self::checkSelfHostMeta()) {
97                         $well_known = DI::baseUrl()->get() . '/.well-known/host-meta';
98                         $warningtext[] = DI::l10n()->t('<a href="%s">%s</a> is not reachable on your system. This is a severe configuration issue that prevents server to server communication. See <a href="%s">the installation page</a> for help.',
99                                 $well_known, $well_known, DI::baseUrl()->get() . '/help/Install');
100                 }
101
102                 // Check logfile permission
103                 if (DI::config()->get('system', 'debugging')) {
104                         $file = DI::config()->get('system', 'logfile');
105
106                         $fileSystem = DI::fs();
107
108                         try {
109                                 $stream = $fileSystem->createStream($file);
110
111                                 if (!isset($stream)) {
112                                         throw new InternalServerErrorException('Stream is null.');
113                                 }
114
115                         } catch (\Throwable $exception) {
116                                 $warningtext[] = DI::l10n()->t('The logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
117                         }
118
119                         $file = DI::config()->get('system', 'dlogfile');
120
121                         try {
122                                 if (!empty($file)) {
123                                         $stream = $fileSystem->createStream($file);
124
125                                         if (!isset($stream)) {
126                                                 throw new InternalServerErrorException('Stream is null.');
127                                         }
128                                 }
129
130                         } catch (\Throwable $exception) {
131                                 $warningtext[] = DI::l10n()->t('The debug logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
132                         }
133                 }
134
135                 // check legacy basepath settings
136                 $configLoader = new ConfigFileLoader($a->getBasePath());
137                 $configCache = new Cache();
138                 $configLoader->setupCache($configCache);
139                 $confBasepath = $configCache->get('system', 'basepath');
140                 $currBasepath = DI::config()->get('system', 'basepath');
141                 if ($confBasepath !== $currBasepath || !is_dir($currBasepath)) {
142                         if (is_dir($confBasepath) && DI::config()->set('system', 'basepath', $confBasepath)) {
143                                 DI::logger()->info('Friendica\'s system.basepath was updated successfully.', [
144                                         'from' => $currBasepath,
145                                         'to'   => $confBasepath,
146                                 ]);
147                                 $warningtext[] = DI::l10n()->t('Friendica\'s system.basepath was updated from \'%s\' to \'%s\'. Please remove the system.basepath from your db to avoid differences.',
148                                         $currBasepath,
149                                         $confBasepath);
150                         } elseif (!is_dir($currBasepath)) {
151                                 DI::logger()->alert('Friendica\'s system.basepath is wrong.', [
152                                         'from' => $currBasepath,
153                                         'to'   => $confBasepath,
154                                 ]);
155                                 $warningtext[] = DI::l10n()->t('Friendica\'s current system.basepath \'%s\' is wrong and the config file \'%s\' isn\'t used.',
156                                         $currBasepath,
157                                         $confBasepath);
158                         } else {
159                                 DI::logger()->alert('Friendica\'s system.basepath is wrong.', [
160                                         'from' => $currBasepath,
161                                         'to'   => $confBasepath,
162                                 ]);
163                                 $warningtext[] = DI::l10n()->t('Friendica\'s current system.basepath \'%s\' is not equal to the config file \'%s\'. Please fix your configuration.',
164                                         $currBasepath,
165                                         $confBasepath);
166                         }
167                 }
168
169                 $accounts = [
170                         [DI::l10n()->t('Normal Account'), 0],
171                         [DI::l10n()->t('Automatic Follower Account'), 0],
172                         [DI::l10n()->t('Public Forum Account'), 0],
173                         [DI::l10n()->t('Automatic Friend Account'), 0],
174                         [DI::l10n()->t('Blog Account'), 0],
175                         [DI::l10n()->t('Private Forum Account'), 0]
176                 ];
177
178                 $users = 0;
179                 $pageFlagsCountStmt = DBA::p('SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`');
180                 while ($pageFlagsCount = DBA::fetch($pageFlagsCountStmt)) {
181                         $accounts[$pageFlagsCount['page-flags']][1] = $pageFlagsCount['count'];
182                         $users += $pageFlagsCount['count'];
183                 }
184                 DBA::close($pageFlagsCountStmt);
185
186                 Logger::log('accounts: ' . print_r($accounts, true), Logger::DATA);
187
188                 $pending = Register::getPendingCount();
189
190                 $deferred = DBA::count('workerqueue', ['NOT `done` AND `retrial` > ?', 0]);
191
192                 $workerqueue = DBA::count('workerqueue', ['NOT `done` AND `retrial` = ?', 0]);
193
194                 // We can do better, but this is a quick queue status
195                 $queues = ['label' => DI::l10n()->t('Message queues'), 'deferred' => $deferred, 'workerq' => $workerqueue];
196
197                 $variables = DBA::toArray(DBA::p('SHOW variables LIKE "max_allowed_packet"'));
198                 $max_allowed_packet = $variables ? $variables[0]['Value'] : 0;
199
200                 $server_settings = [
201                         'label' => DI::l10n()->t('Server Settings'),
202                         'php' => [
203                                 'upload_max_filesize' => ini_get('upload_max_filesize'),
204                                 'post_max_size' => ini_get('post_max_size'),
205                                 'memory_limit' => ini_get('memory_limit')
206                         ],
207                         'mysql' => [
208                                 'max_allowed_packet' => $max_allowed_packet
209                         ]
210                 ];
211
212                 $t = Renderer::getMarkupTemplate('admin/summary.tpl');
213                 return Renderer::replaceMacros($t, [
214                         '$title' => DI::l10n()->t('Administration'),
215                         '$page' => DI::l10n()->t('Summary'),
216                         '$queues' => $queues,
217                         '$users' => [DI::l10n()->t('Registered users'), $users],
218                         '$accounts' => $accounts,
219                         '$pending' => [DI::l10n()->t('Pending registrations'), $pending],
220                         '$version' => [DI::l10n()->t('Version'), FRIENDICA_VERSION],
221                         '$platform' => FRIENDICA_PLATFORM,
222                         '$codename' => FRIENDICA_CODENAME,
223                         '$build' => DI::config()->get('system', 'build'),
224                         '$addons' => [DI::l10n()->t('Active addons'), Addon::getEnabledList()],
225                         '$serversettings' => $server_settings,
226                         '$warningtext' => $warningtext
227                 ]);
228         }
229
230         private static function checkSelfHostMeta()
231         {
232                 // Fetch the host-meta to check if this really is a vital server
233                 return Network::curl(DI::baseUrl()->get() . '/.well-known/host-meta')->isSuccess();
234         }
235
236 }