]> git.mxchange.org Git - friendica.git/commitdiff
Move code from worker.php into App::processWorker()
authorArt4 <art4@wlabs.de>
Thu, 26 Dec 2024 19:04:27 +0000 (19:04 +0000)
committerArt4 <art4@wlabs.de>
Thu, 26 Dec 2024 19:04:27 +0000 (19:04 +0000)
bin/worker.php
src/App.php

index 684a5d80764833efc785169cebd798f711103077..b88c30aeb5a1020a21e59a2d71be67353a21fddf 100755 (executable)
@@ -15,12 +15,6 @@ if (php_sapi_name() !== 'cli') {
 }
 
 use Dice\Dice;
-use Friendica\App\Mode;
-use Friendica\Core\Logger\Capability\LogChannel;
-use Friendica\Core\Update;
-use Friendica\Core\Worker;
-use Friendica\DI;
-use Psr\Log\LoggerInterface;
 
 // Get options
 $options = getopt('sn', ['spawn', 'no_cron']);
@@ -32,37 +26,6 @@ require dirname(__DIR__) . '/vendor/autoload.php';
 
 $dice = (new Dice())->addRules(require(dirname(__DIR__) . '/static/dependencies.config.php'));
 
-/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */
-$addonLoader = $dice->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class);
-$dice = $dice->addRules($addonLoader->getActiveAddonConfig('dependencies'));
-$dice = $dice->addRule(LoggerInterface::class, ['constructParams' => [LogChannel::WORKER]]);
+$app = \Friendica\App::fromDice($dice);
 
-DI::init($dice);
-\Friendica\Core\Logger\Handler\ErrorHandler::register($dice->create(\Psr\Log\LoggerInterface::class));
-
-DI::mode()->setExecutor(Mode::WORKER);
-
-// Check the database structure and possibly fixes it
-Update::check(DI::basePath(), true);
-
-// Quit when in maintenance
-if (!DI::mode()->has(Mode::MAINTENANCEDISABLED)) {
-       return;
-}
-
-$spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
-
-if ($spawn) {
-       Worker::spawnWorker();
-       exit();
-}
-
-$run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
-
-$process = DI::process()->create(getmypid(), basename(__FILE__));
-
-Worker::processQueue($run_cron, $process);
-
-Worker::unclaimProcess($process);
-
-DI::process()->delete($process);
+$app->processWorker($options ?: []);
index 0345eb3adfc46cb01bba6c0dedc7c1ec202b99fe..fc42ca2b1a2a514de15ccd94d561035b38420d68 100644 (file)
@@ -47,8 +47,6 @@ use Friendica\Util\Profiler;
 use Psr\Http\Message\ServerRequestInterface;
 use Psr\Log\LoggerInterface;
 
-
-
 /**
  * Our main application structure for the life of this page.
  *
@@ -436,6 +434,45 @@ class App
                }
        }
 
+       public function processWorker(array $options): void
+       {
+               /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */
+               $addonLoader = $this->container->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class);
+               $this->container = $this->container->addRules($addonLoader->getActiveAddonConfig('dependencies'));
+
+               $this->container = $this->container->addRule(LoggerInterface::class, ['constructParams' => [LogChannel::WORKER]]);
+
+               DI::init($this->container);
+               \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(\Psr\Log\LoggerInterface::class));
+
+               DI::mode()->setExecutor(Mode::WORKER);
+
+               // Check the database structure and possibly fixes it
+               Update::check(DI::basePath(), true);
+
+               // Quit when in maintenance
+               if (!DI::mode()->has(Mode::MAINTENANCEDISABLED)) {
+                       return;
+               }
+
+               $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
+
+               if ($spawn) {
+                       Worker::spawnWorker();
+                       exit();
+               }
+
+               $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
+
+               $process = DI::process()->create(getmypid(), basename(__FILE__));
+
+               Worker::processQueue($run_cron, $process);
+
+               Worker::unclaimProcess($process);
+
+               DI::process()->delete($process);
+       }
+
        private function setupContainerForAddons(): void
        {
                /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */