]> git.mxchange.org Git - friendica.git/blob - src/Worker/Cron.php
Merge pull request #9343 from vinzv/9337-fix-pwa-manifest
[friendica.git] / src / Worker / Cron.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\Worker;
23
24 use Friendica\Core\Hook;
25 use Friendica\Core\Logger;
26 use Friendica\Core\Worker;
27 use Friendica\DI;
28 use Friendica\Model\Tag;
29
30 class Cron
31 {
32         public static function execute()
33         {
34                 $a = DI::app();
35
36                 $last = DI::config()->get('system', 'last_cron');
37
38                 $poll_interval = intval(DI::config()->get('system', 'cron_interval'));
39
40                 if ($last) {
41                         $next = $last + ($poll_interval * 60);
42                         if ($next > time()) {
43                                 Logger::notice('cron intervall not reached');
44                                 return;
45                         }
46                 }
47
48                 Logger::notice('start');
49
50                 // Ensure to have a .htaccess file.
51                 // this is a precaution for systems that update automatically
52                 $basepath = $a->getBasePath();
53                 if (!file_exists($basepath . '/.htaccess') && is_writable($basepath)) {
54                         copy($basepath . '/.htaccess-dist', $basepath . '/.htaccess');
55                 }
56
57                 // Fork the cron jobs in separate parts to avoid problems when one of them is crashing
58                 Hook::fork($a->queue['priority'], 'cron');
59
60                 // Poll contacts
61                 Worker::add(PRIORITY_MEDIUM, 'PollContacts');
62
63                 // Update contact information
64                 Worker::add(PRIORITY_LOW, 'UpdatePublicContacts');              
65
66                 // run the process to update server directories in the background
67                 Worker::add(PRIORITY_LOW, 'UpdateServerDirectories');
68
69                 // Expire and remove user entries
70                 Worker::add(PRIORITY_MEDIUM, 'ExpireAndRemoveUsers');
71
72                 // Call possible post update functions
73                 Worker::add(PRIORITY_LOW, 'PostUpdate');
74
75                 // Repair entries in the database
76                 Worker::add(PRIORITY_LOW, 'RepairDatabase');
77
78                 // Hourly cron calls
79                 if (DI::config()->get('system', 'last_cron_hourly', 0) + 3600 < time()) {
80
81                         // Update trending tags cache for the community page
82                         Tag::setLocalTrendingHashtags(24, 20);
83                         Tag::setGlobalTrendingHashtags(24, 20);
84
85                         // Search for new contacts in the directory
86                         if (DI::config()->get('system', 'synchronize_directory')) {
87                                 Worker::add(PRIORITY_LOW, 'PullDirectory');
88                         }
89
90                         // Delete all done workerqueue entries                  
91                         Worker::add(PRIORITY_LOW, 'CleanWorkerQueue');
92
93                         // Clear cache entries
94                         Worker::add(PRIORITY_LOW, 'ClearCache');
95
96                         DI::config()->set('system', 'last_cron_hourly', time());
97                 }
98
99                 // Daily cron calls
100                 if (DI::config()->get('system', 'last_cron_daily', 0) + 86400 < time()) {
101
102                         Worker::add(PRIORITY_LOW, 'UpdateContactBirthdays');
103
104                         Worker::add(PRIORITY_LOW, 'UpdatePhotoAlbums');
105
106                         // update nodeinfo data
107                         Worker::add(PRIORITY_LOW, 'NodeInfo');
108
109                         Worker::add(PRIORITY_LOW, 'UpdateGServers');
110
111                         Worker::add(PRIORITY_LOW, 'Expire');
112
113                         Worker::add(PRIORITY_MEDIUM, 'DBClean');
114
115                         Worker::add(PRIORITY_LOW, 'ExpireConversations');
116
117                         Worker::add(PRIORITY_LOW, 'CleanItemUri');
118
119                         // check upstream version?
120                         Worker::add(PRIORITY_LOW, 'CheckVersion');
121
122                         Worker::add(PRIORITY_LOW, 'CheckDeletedContacts');
123
124                         if (DI::config()->get('system', 'optimize_tables')) {
125                                 Worker::add(PRIORITY_LOW, 'OptimizeTables');
126                         }
127         
128                         DI::config()->set('system', 'last_cron_daily', time());
129                 }
130
131                 Logger::notice('end');
132
133                 DI::config()->set('system', 'last_cron', time());
134         }
135 }