Remove queue from Admin/Summary
[friendica.git/.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\Config\ConfigFileLoader;
16 use Friendica\Util\DateTimeFormat;
17 use Friendica\Util\Network;
18
19 class Summary extends BaseAdminModule
20 {
21         public static function content()
22         {
23                 parent::content();
24
25                 $a = self::getApp();
26
27                 // are there MyISAM tables in the DB? If so, trigger a warning message
28                 $warningtext = [];
29                 if (DBA::count(['information_schema' => 'tables'], ['engine' => 'myisam', 'table_schema' => DBA::databaseName()])) {
30                         $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');
31                 }
32
33                 // Check if github.com/friendica/master/VERSION is higher then
34                 // the local version of Friendica. Check is opt-in, source may be master or devel branch
35                 if (Config::get('system', 'check_new_version_url', 'none') != 'none') {
36                         $gitversion = Config::get('system', 'git_friendica_version');
37                         if (version_compare(FRIENDICA_VERSION, $gitversion) < 0) {
38                                 $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);
39                         }
40                 }
41
42                 if (Config::get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) {
43                         DBStructure::update($a->getBasePath(), false, true);
44                 }
45
46                 if (Config::get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) {
47                         $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.');
48                 }
49
50                 if (Config::get('system', 'update') == Update::FAILED) {
51                         $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.)');
52                 }
53
54                 $last_worker_call = Config::get('system', 'last_worker_execution', false);
55                 if (!$last_worker_call) {
56                         $warningtext[] = L10n::t('The worker was never executed. Please check your database structure!');
57                 } elseif ((strtotime(DateTimeFormat::utcNow()) - strtotime($last_worker_call)) > 60 * 60) {
58                         $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);
59                 }
60
61                 // Legacy config file warning
62                 if (file_exists('.htconfig.php')) {
63                         $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');
64                 }
65
66                 if (file_exists('config/local.ini.php')) {
67                         $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');
68                 }
69
70                 // Check server vitality
71                 if (!self::checkSelfHostMeta()) {
72                         $well_known = $a->getBaseURL() . '/.well-known/host-meta';
73                         $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.',
74                                 $well_known, $well_known, $a->getBaseURL() . '/help/Install');
75                 }
76
77                 // Check logfile permission
78                 if (Config::get('system', 'debugging')) {
79                         $stream = Config::get('system', 'logfile');
80
81                         if (is_file($stream) &&
82                             !is_writeable($stream)) {
83                                 $warningtext[] = L10n::t('The logfile \'%s\' is not writable. No logging possible', $stream);
84                         }
85
86                         $stream = Config::get('system', 'dlogfile');
87
88                         if (is_file($stream) &&
89                             !is_writeable($stream)) {
90                                 $warningtext[] = L10n::t('The logfile \'%s\' is not writable. No logging possible', $stream);
91                         }
92                 }
93
94                 // check legacy basepath settings
95                 $configLoader = new ConfigFileLoader($a->getBasePath(), $a->getMode());
96                 $configCache = new Config\Cache\ConfigCache();
97                 $configLoader->setupCache($configCache);
98                 $confBasepath = $configCache->get('system', 'basepath');
99                 $currBasepath = $a->getConfig()->get('system', 'basepath');
100                 if ($confBasepath !== $currBasepath || !is_dir($currBasepath)) {
101                         if (is_dir($confBasepath) && Config::set('system', 'basepath', $confBasepath)) {
102                                 $a->getLogger()->info('Friendica\'s system.basepath was updated successfully.', [
103                                         'from' => $currBasepath,
104                                         'to'   => $confBasepath,
105                                 ]);
106                                 $warningtext[] = L10n::t('Friendica\'s system.basepath was updated from \'%s\' to \'%s\'. Please remove the system.basepath from your db to avoid differences.',
107                                         $currBasepath,
108                                         $confBasepath);
109                         } elseif (!is_dir($currBasepath)) {
110                                 $a->getLogger()->alert('Friendica\'s system.basepath is wrong.', [
111                                         'from' => $currBasepath,
112                                         'to'   => $confBasepath,
113                                 ]);
114                                 $warningtext[] = L10n::t('Friendica\'s current system.basepath \'%s\' is wrong and the config file \'%s\' isn\'t used.',
115                                         $currBasepath,
116                                         $confBasepath);
117                         } else {
118                                 $a->getLogger()->alert('Friendica\'s system.basepath is wrong.', [
119                                         'from' => $currBasepath,
120                                         'to'   => $confBasepath,
121                                 ]);
122                                 $warningtext[] = L10n::t('Friendica\'s current system.basepath \'%s\' is not equal to the config file \'%s\'. Please fix your configuration.',
123                                         $currBasepath,
124                                         $confBasepath);
125                         }
126                 }
127
128                 $accounts = [
129                         [L10n::t('Normal Account'), 0],
130                         [L10n::t('Automatic Follower Account'), 0],
131                         [L10n::t('Public Forum Account'), 0],
132                         [L10n::t('Automatic Friend Account'), 0],
133                         [L10n::t('Blog Account'), 0],
134                         [L10n::t('Private Forum Account'), 0]
135                 ];
136
137                 $users = 0;
138                 $pageFlagsCountStmt = DBA::p('SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`');
139                 while ($pageFlagsCount = DBA::fetch($pageFlagsCountStmt)) {
140                         $accounts[$pageFlagsCount['page-flags']][1] = $pageFlagsCount['count'];
141                         $users += $pageFlagsCount['count'];
142                 }
143                 DBA::close($pageFlagsCountStmt);
144
145                 Logger::log('accounts: ' . print_r($accounts, true), Logger::DATA);
146
147                 $pending = Register::getPendingCount();
148
149                 $deferred = DBA::count('workerqueue', ['`executed` <= ? AND NOT `done` AND `next_try` > ?',
150                         DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
151
152                 $workerqueue = DBA::count('workerqueue', ['`executed` <= ? AND NOT `done` AND `next_try` < ?',
153                         DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
154
155                 // We can do better, but this is a quick queue status
156                 $queues = ['label' => L10n::t('Message queues'), 'deferred' => $deferred, 'workerq' => $workerqueue];
157
158                 $variables = DBA::toArray(DBA::p('SHOW variables LIKE "max_allowed_packet"'));
159                 $max_allowed_packet = $variables ? $variables[0]['Value'] : 0;
160
161                 $server_settings = [
162                         'label' => L10n::t('Server Settings'),
163                         'php' => [
164                                 'upload_max_filesize' => ini_get('upload_max_filesize'),
165                                 'post_max_size' => ini_get('post_max_size'),
166                                 'memory_limit' => ini_get('memory_limit')
167                         ],
168                         'mysql' => [
169                                 'max_allowed_packet' => $max_allowed_packet
170                         ]
171                 ];
172
173                 $t = Renderer::getMarkupTemplate('admin/summary.tpl');
174                 return Renderer::replaceMacros($t, [
175                         '$title' => L10n::t('Administration'),
176                         '$page' => L10n::t('Summary'),
177                         '$queues' => $queues,
178                         '$users' => [L10n::t('Registered users'), $users],
179                         '$accounts' => $accounts,
180                         '$pending' => [L10n::t('Pending registrations'), $pending],
181                         '$version' => [L10n::t('Version'), FRIENDICA_VERSION],
182                         '$platform' => FRIENDICA_PLATFORM,
183                         '$codename' => FRIENDICA_CODENAME,
184                         '$build' => Config::get('system', 'build'),
185                         '$addons' => [L10n::t('Active addons'), Addon::getEnabledList()],
186                         '$serversettings' => $server_settings,
187                         '$warningtext' => $warningtext
188                 ]);
189         }
190
191         private static function checkSelfHostMeta()
192         {
193                 // Fetch the host-meta to check if this really is a vital server
194                 return Network::curl(self::getApp()->getBaseURL() . '/.well-known/host-meta')->isSuccess();
195         }
196
197 }