Skip to content

Commit

Permalink
pkp#9678 WIP: Replacing task schedular with laravel schedular
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Jun 27, 2024
1 parent 667b73d commit 4a92d72
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 203 deletions.
140 changes: 0 additions & 140 deletions classes/cliTool/ScheduledTaskTool.php

This file was deleted.

36 changes: 36 additions & 0 deletions classes/core/PKPConsoleCommandServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace PKP\core;

use Illuminate\Console\OutputStyle;
use Illuminate\Console\View\Components\Factory;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;

class PKPConsoleCommandServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(Factory::class, function ($app) {
return new Factory(
self::getConsoleOutputStyle()
);
});
}

public static function getConsoleOutputStyle(): OutputStyle
{
return new OutputStyle(
...self::getConsoleIOInstances()
);
}

public static function getConsoleIOInstances(): array
{
return [
new ArgvInput([]),
new ConsoleOutput(),
];
}
}
32 changes: 32 additions & 0 deletions classes/core/PKPContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
namespace PKP\core;

use APP\core\Application;
use Illuminate\Support\Str;

use PKP\core\PKPConsoleCommandServiceProvider;

use PKP\core\PKPScheduleServiceProvider;

use APP\core\AppServiceProvider;
Expand Down Expand Up @@ -164,6 +168,7 @@ public function registerConfiguredProviders()
$this->register(new LocaleServiceProvider($this));
$this->register(new PKPRoutingProvider($this));
$this->register(new PKPScheduleServiceProvider($this));
$this->register(new PKPConsoleCommandServiceProvider($this));
}

/**
Expand Down Expand Up @@ -327,6 +332,11 @@ protected function loadConfiguration()
$items = [];
$_request = PKPApplication::get()->getRequest();

$items['app'] = [
'timezone' => Config::getVar('general', 'timezone', 'UTC'),
'env' => Config::getVar('general', 'app_env', 'production'),
];

// Database connection
$driver = 'mysql';

Expand Down Expand Up @@ -545,6 +555,28 @@ public function isDownForMaintenance()
{
return PKPApplication::isUnderMaintenance();
}

// public function isLocal(): bool
// {
// return true;
// }

/**
* Get or check the current application environment.
*
* @param string|array ...$environments
* @return string|bool
*/
public function environment(...$environments)
{
if (count($environments) > 0) {
$patterns = is_array($environments[0]) ? $environments[0] : $environments;

return Str::is($patterns, $this->get('config')['app']['env']);
}

return $this->get('config')['app']['env'];
}
}

if (!PKP_STRICT_MODE) {
Expand Down
9 changes: 6 additions & 3 deletions classes/core/PKPScheduleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

namespace PKP\core;

use APP\scheduler\Scheduler;
use PKP\config\Config;
use PKP\core\PKPContainer;
use PKP\scheduledTask\PKPSchedular;
use Illuminate\Support\ServiceProvider;
use Illuminate\Console\Scheduling\Schedule;

class PKPScheduleServiceProvider extends ServiceProvider
{
public function boot()
{
// After the resolving to \Illuminate\Console\Scheduling\Schedule::class
// need to register all the schedules into the scheduler
$this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
(new PKPSchedular($schedule))->registerSchedules();
$scheduler = $this->app->get(Scheduler::class); /** @var \APP\schedular\Scheduler $scheduler */
$scheduler->registerSchedules();
});
}

Expand All @@ -31,6 +34,6 @@ public function register()
)->useCache($cacheConfig['default']);
});

$this->app->alias(Schedule::class, 'schedule');
$this->app->singleton(Scheduler::class, fn ($app) => new Scheduler($app->get(Schedule::class)));
}
}
10 changes: 10 additions & 0 deletions classes/plugins/interfaces/HasTaskScheduler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace PKP\plugins\interfaces;

use APP\scheduler\Scheduler;

interface HasTaskScheduler
{
public function registerSchedules(?Scheduler $scheduler = null): void;
}
37 changes: 0 additions & 37 deletions classes/scheduledTask/PKPSchedular.php

This file was deleted.

Loading

0 comments on commit 4a92d72

Please sign in to comment.