Rename dbesc to DBA::escape
[friendica.git/.git] / src / Worker / CheckVersion.php
1 <?php
2
3 /**
4  * @file src/Worker/CheckVersion.php
5  *
6  * @brief save Friendica upstream version to the DB
7  **/
8 namespace Friendica\Worker;
9
10 use Friendica\Core\Config;
11 use Friendica\Util\Network;
12
13 /**
14  * @brief check the git repository VERSION file and save the version to the DB
15  *
16  * Checking the upstream version is optional (opt-in) and can be done to either
17  * the master or the develop branch in the repository.
18  */
19 class CheckVersion
20 {
21         public static function execute()
22         {
23                 logger('checkversion: start');
24
25                 $checkurl = Config::get('system', 'check_new_version_url', 'none');
26
27                 switch ($checkurl) {
28                         case 'master':
29                                 $checked_url = 'https://raw.githubusercontent.com/friendica/friendica/master/VERSION';
30                                 break;
31                         case 'develop':
32                                 $checked_url = 'https://raw.githubusercontent.com/friendica/friendica/develop/VERSION';
33                                 break;
34                         default:
35                                 // don't check
36                                 return;
37                 }
38                 logger("Checking VERSION from: ".$checked_url, LOGGER_DEBUG);
39
40                 // fetch the VERSION file
41                 $gitversion = DBA::escape(trim(Network::fetchUrl($checked_url)));
42                 logger("Upstream VERSION is: ".$gitversion, LOGGER_DEBUG);
43
44                 Config::set('system', 'git_friendica_version', $gitversion);
45
46                 logger('checkversion: end');
47
48                 return;
49         }
50 }