CronWorkspaceNegotiator.php in Multiversion 8
File
src/Workspace/CronWorkspaceNegotiator.php
View source
<?php
namespace Drupal\multiversion\Workspace;
use Drupal\Core\State\StateInterface;
use Drupal\multiversion\Entity\WorkspaceInterface;
use Symfony\Component\HttpFoundation\Request;
class CronWorkspaceNegotiator extends WorkspaceNegotiatorBase {
private $state;
public function __construct(StateInterface $state) {
$this->state = $state;
}
public function applies(Request $request) {
$route = $request->attributes
->get('_route');
return in_array($route, [
'system.cron',
'system.run_cron',
'<none>',
]);
}
public function getWorkspaceId(Request $request) {
$workspace_id = $this->state
->get('workspace.negotiator.cron.active_workspace_id');
return $workspace_id ?: $this->container
->getParameter('workspace.default');
}
public function persist(WorkspaceInterface $workspace) {
$this->state
->set('workspace.negotiator.cron.active_workspace_id', $workspace
->id());
return TRUE;
}
}