]> git.mxchange.org Git - friendica.git/blob - bin/worker.php
Remove unneeded Config namespace usages
[friendica.git] / bin / worker.php
1 #!/usr/bin/env php
2 <?php
3 /**
4  * @file bin/worker.php
5  * Starts the background processing
6  */
7
8 use Dice\Dice;
9 use Friendica\App;
10 use Friendica\Core\Update;
11 use Friendica\Core\Worker;
12 use Friendica\DI;
13 use Psr\Log\LoggerInterface;
14
15 // Get options
16 $shortopts = 'sn';
17 $longopts = ['spawn', 'no_cron'];
18 $options = getopt($shortopts, $longopts);
19
20 // Ensure that worker.php is executed from the base path of the installation
21 if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
22         $directory = dirname($_SERVER["argv"][0]);
23
24         if (substr($directory, 0, 1) != '/') {
25                 $directory = $_SERVER["PWD"] . '/' . $directory;
26         }
27         $directory = realpath($directory . '/..');
28
29         chdir($directory);
30 }
31
32 require dirname(__DIR__) . '/vendor/autoload.php';
33
34 $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
35 $dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['worker']]);
36
37 DI::init($dice);
38 $a = DI::app();
39
40 // Check the database structure and possibly fixes it
41 Update::check($a->getBasePath(), true, DI::mode());
42
43 // Quit when in maintenance
44 if (!DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) {
45         return;
46 }
47
48 DI::baseUrl()->saveByURL(DI::config()->get('system', 'url'));
49
50 $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
51
52 if ($spawn) {
53         Worker::spawnWorker();
54         exit();
55 }
56
57 $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
58
59 Worker::processQueue($run_cron);
60
61 Worker::unclaimProcess();
62
63 Worker::endProcess();