]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Summary.php
Merge pull request #7044 from MrPetovan/task/router
[friendica.git] / src / Module / Admin / Summary.php
1 <?php
2
3 namespace Friendica\Module\Admin;
4
5 use Friendica\Core\Addon;
6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Logger;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\Update;
11 use Friendica\Database\DBA;
12 use Friendica\Database\DBStructure;
13 use Friendica\Model\Register;
14 use Friendica\Module\BaseAdminModule;
15 use Friendica\Util\DateTimeFormat;
16 use Friendica\Util\Network;
17
18 class Summary extends BaseAdminModule
19 {
20         public static function content()
21         {
22                 parent::content();
23
24                 $a = self::getApp();
25
26                 // are there MyISAM tables in the DB? If so, trigger a warning message
27                 $warningtext = [];
28                 if (DBA::count('`information_schema`.`tables`', ['engine' => 'myisam', 'table_schema' => DBA::databaseName()])) {
29                         $warningtext[] = 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');
30                 }
31
32                 // Check if github.com/friendica/master/VERSION is higher then
33                 // the local version of Friendica. Check is opt-in, source may be master or devel branch
34                 if (Config::get('system', 'check_new_version_url', 'none') != 'none') {
35                         $gitversion = Config::get('system', 'git_friendica_version');
36                         if (version_compare(FRIENDICA_VERSION, $gitversion) < 0) {
37                                 $warningtext[] = 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);
38                         }
39                 }
40
41                 if (Config::get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) {
42                         DBStructure::update($a->getBasePath(), false, true);
43                 }
44
45                 if (Config::get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) {
46                         $warningtext[] = 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.');
47                 }
48
49                 if (Config::get('system', 'update') == Update::FAILED) {
50                         $warningtext[] = 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.)');
51                 }
52
53                 $last_worker_call = Config::get('system', 'last_worker_execution', false);
54                 if (!$last_worker_call) {
55                         $warningtext[] = L10n::t('The worker was never executed. Please check your database structure!');
56                 } elseif ((strtotime(DateTimeFormat::utcNow()) - strtotime($last_worker_call)) > 60 * 60) {
57                         $warningtext[] = L10n::t('The last worker execution was on %s UTC. This is older than one hour. Please check your crontab settings.', $last_worker_call);
58                 }
59
60                 // Legacy config file warning
61                 if (file_exists('.htconfig.php')) {
62                         $warningtext[] = 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.', $a->getBaseURL() . '/help/Config');
63                 }
64
65                 if (file_exists('config/local.ini.php')) {
66                         $warningtext[] = 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.', $a->getBaseURL() . '/help/Config');
67                 }
68
69                 // Check server vitality
70                 if (!self::checkSelfHostMeta()) {
71                         $well_known = $a->getBaseURL() . '/.well-known/host-meta';
72                         $warningtext[] = 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.',
73                                 $well_known, $well_known, $a->getBaseURL() . '/help/Install');
74                 }
75
76                 $accounts = [
77                         [L10n::t('Normal Account'), 0],
78                         [L10n::t('Automatic Follower Account'), 0],
79                         [L10n::t('Public Forum Account'), 0],
80                         [L10n::t('Automatic Friend Account'), 0],
81                         [L10n::t('Blog Account'), 0],
82                         [L10n::t('Private Forum Account'), 0]
83                 ];
84
85                 $users = 0;
86                 $pageFlagsCountStmt = DBA::p('SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`');
87                 while ($pageFlagsCount = DBA::fetch($pageFlagsCountStmt)) {
88                         $accounts[$pageFlagsCount['page-flags']][1] = $pageFlagsCount['count'];
89                         $users += $pageFlagsCount['count'];
90                 }
91                 DBA::close($pageFlagsCountStmt);
92
93                 Logger::log('accounts: ' . print_r($accounts, true), Logger::DATA);
94
95                 $pending = Register::getPendingCount();
96
97                 $queue = DBA::count('queue', []);
98
99                 $deferred = DBA::count('workerqueue', ['`executed` <= ? AND NOT `done` AND `next_try` > ?',
100                         DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
101
102                 $workerqueue = DBA::count('workerqueue', ['`executed` <= ? AND NOT `done` AND `next_try` < ?',
103                         DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
104
105                 // We can do better, but this is a quick queue status
106                 $queues = ['label' => L10n::t('Message queues'), 'queue' => $queue, 'deferred' => $deferred, 'workerq' => $workerqueue];
107
108                 $variables = DBA::toArray(DBA::p('SHOW variables LIKE "max_allowed_packet"'));
109                 $max_allowed_packet = $variables ? $variables[0]['Value'] : 0;
110
111                 $server_settings = [
112                         'label' => L10n::t('Server Settings'),
113                         'php' => [
114                                 'upload_max_filesize' => ini_get('upload_max_filesize'),
115                                 'post_max_size' => ini_get('post_max_size'),
116                                 'memory_limit' => ini_get('memory_limit')
117                         ],
118                         'mysql' => [
119                                 'max_allowed_packet' => $max_allowed_packet
120                         ]
121                 ];
122
123                 $t = Renderer::getMarkupTemplate('admin/summary.tpl');
124                 return Renderer::replaceMacros($t, [
125                         '$title' => L10n::t('Administration'),
126                         '$page' => L10n::t('Summary'),
127                         '$queues' => $queues,
128                         '$users' => [L10n::t('Registered users'), $users],
129                         '$accounts' => $accounts,
130                         '$pending' => [L10n::t('Pending registrations'), $pending],
131                         '$version' => [L10n::t('Version'), FRIENDICA_VERSION],
132                         '$platform' => FRIENDICA_PLATFORM,
133                         '$codename' => FRIENDICA_CODENAME,
134                         '$build' => Config::get('system', 'build'),
135                         '$addons' => [L10n::t('Active addons'), Addon::getEnabledList()],
136                         '$serversettings' => $server_settings,
137                         '$warningtext' => $warningtext
138                 ]);
139         }
140
141         private static function checkSelfHostMeta()
142         {
143                 // Fetch the host-meta to check if this really is a vital server
144                 return Network::curl(self::getApp()->getBaseURL() . '/.well-known/host-meta')->isSuccess();
145         }
146
147 }