Skip to content
Snippets Groups Projects
Commit a25e7e29 authored by Antonín Slejška's avatar Antonín Slejška
Browse files

Issue #3360452: Move the configuration entity to a separate module.

parent dbfaf618
No related branches found
No related tags found
1 merge request!1Issue #3360452: Move the configuration entity to a separate module.
Showing
with 218 additions and 48 deletions
...@@ -14,16 +14,10 @@ INTRODUCTION ...@@ -14,16 +14,10 @@ INTRODUCTION
------------ ------------
The module enables to delete specified temporary storages. The temporary The module enables to delete specified temporary storages. The temporary
storages can be specified in the Drupal administration storages can be specified in the Drupal administration (if the module tsk_admin
(admin/config/development/performance/tsk). The temporary storages can be on the is enabled: admin/config/development/performance/tsk).
same path deleted. There is also a command, which can be used to delete the
temporary storages:
drush temp-store-killer:all You can also kill a specified temporary storage with the command:
drush tska
But you can also specify the temporary storage to be deleted directly in the
command:
# Delete all private temporary storages of the collection email_tfa: # Delete all private temporary storages of the collection email_tfa:
drush temp-store-killer private email_tfa drush temp-store-killer private email_tfa
...@@ -31,6 +25,13 @@ command: ...@@ -31,6 +25,13 @@ command:
# "layout_builder.section_storage.overrides" with key "my_page.11.full.en": # "layout_builder.section_storage.overrides" with key "my_page.11.full.en":
drush tsk shared layout_builder.section_storage.overrides my_page.11.full.en drush tsk shared layout_builder.section_storage.overrides my_page.11.full.en
If the module tsk_admin is enabled, the temporary storages specified in the
configuration can be killed with the following command:
drush temp-store-killer:all
drush tska
More info: More info:
* For a full description of the module, visit * For a full description of the module, visit
...@@ -59,6 +60,9 @@ INSTALLATION ...@@ -59,6 +60,9 @@ INSTALLATION
CONFIGURATION CONFIGURATION
------------- -------------
The module tsk has no configuration. The module tsk_all brings the possibility
to configure the temporary storages, which should be killed.
You can create a configuration entity for every temporary storage (collection) You can create a configuration entity for every temporary storage (collection)
in the administration (admin/config/development/performance/tsk). There are the in the administration (admin/config/development/performance/tsk). There are the
following fields in the configuration entity form: following fields in the configuration entity form:
...@@ -70,8 +74,9 @@ following fields in the configuration entity form: ...@@ -70,8 +74,9 @@ following fields in the configuration entity form:
deleted.) deleted.)
* Key (The key of the stored data) * Key (The key of the stored data)
If you then klick the button 'Kill all', or run the 'drush kill-temp-store' If you then klick the button 'Kill all', or run the
command, all the specified temporary storages will be deleted. 'drush temp-store-killer:all' command, all the specified temporary storages will
be deleted.
TROUBLESHOOTING TROUBLESHOOTING
--------------- ---------------
......
services:
tsk_admin.commands:
class: \Drupal\tsk_admin\Commands\TskAdminCommands
arguments: ['@tsk_admin.service']
tags:
- { name: drush.command }
<?php
namespace Drupal\tsk_admin\Commands;
use Drush\Commands\DrushCommands;
use Drupal\tsk_admin\Services\TskAdminServiceInterface;
/**
* Drush integration for the module Temporary Storages Killer.
*/
class TskAdminCommands extends DrushCommands {
/**
* TskAdminService.
*
* @var \Drupal\tsk\Services\TskAdminServiceInterface
*/
protected $tskAdminService;
/**
* TskAdminCommands constructor.
*
* @param \Drupal\tsk_admin\Services\TskAdminServiceInterface $tsk_admin_service
* Temporary Storage Killer Admin service.
*/
public function __construct(TskAdminServiceInterface $tsk_admin_service) {
$this->tskAdminService = $tsk_admin_service;
}
/**
* Kills the specified temporary storages.
*
* @command temp-store-killer:all
* @aliases tska
* @usage drush temp-store-killer:all
* Kills the specified temporary storages.
*/
public function killAll() {
$this->tskAdminService->killAll();
}
}
<?php <?php
namespace Drupal\tsk\Controller; namespace Drupal\tsk_admin\Controller;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\tsk\Entity\TskEntity; use Drupal\tsk_admin\Entity\TskEntity;
use Drupal\tsk_admin\Services\TskAdminService;
use Drupal\tsk\Services\TskService; use Drupal\tsk\Services\TskService;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Defines TskController class. * Defines TskController class.
*/ */
class TskController extends ControllerBase { class TskAdminController extends ControllerBase {
/** /**
* Defines TskService. * Defines tskAdminService.
* *
* @var \Drupal\simple_sitemap\Simplesitemap * @var \Drupal\tsk_admin\Services\TskAdminService
*/
protected $tskAdminService;
/**
* Defines tskService.
*
* @var \Drupal\tsk\Services\TskService
*/ */
protected $tskService; protected $tskService;
/** /**
* TskController constructor. * TskController constructor.
* *
* @param \Drupal\tsk\Services\TskService $tsk_service * @param \Drupal\tsk_admin\Services\tskAdminService $tsk_admin_service
* Temporary Storage Killer admin service.
* @param \Drupal\tsk\Services\tskService $tsk_service
* Temporary Storage Killer service. * Temporary Storage Killer service.
*/ */
public function __construct(TskService $tsk_service) { public function __construct(tskAdminService $tsk_admin_service, tskService $tsk_service) {
$this->tskAdminService = $tsk_admin_service;
$this->tskService = $tsk_service; $this->tskService = $tsk_service;
} }
...@@ -39,6 +50,7 @@ class TskController extends ControllerBase { ...@@ -39,6 +50,7 @@ class TskController extends ControllerBase {
*/ */
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('tsk_admin.service'),
$container->get('tsk.service') $container->get('tsk.service')
); );
} }
...@@ -50,8 +62,8 @@ class TskController extends ControllerBase { ...@@ -50,8 +62,8 @@ class TskController extends ControllerBase {
* Temporary storage entity. * Temporary storage entity.
*/ */
public function kill(TskEntity $tsk_entity) { public function kill(TskEntity $tsk_entity) {
$this->tskService->kill($tsk_entity->collection, $tsk_entity->private, $tsk_entity->kill_all, $tsk_entity->key); $this->tskService->kill($tsk_entity->collection, $tsk_entity->type, $tsk_entity->kill_all, $tsk_entity->key);
$this->messenger()->addStatus(t('The temporary storage has been deleted.')); $this->messenger()->addStatus($this->t('The temporary storage has been deleted.'));
return $this->redirect('entity.tsk_entity'); return $this->redirect('entity.tsk_entity');
} }
...@@ -59,8 +71,8 @@ class TskController extends ControllerBase { ...@@ -59,8 +71,8 @@ class TskController extends ControllerBase {
* Delete all specified temporary storages. * Delete all specified temporary storages.
*/ */
public function killAll() { public function killAll() {
$this->tskService->killAll(); $this->tskAdminService->killAll();
$this->messenger()->addStatus(t('The temporary storages have been deleted.')); $this->messenger()->addStatus($this->t('The temporary storages have been deleted.'));
return $this->redirect('entity.tsk_entity'); return $this->redirect('entity.tsk_entity');
} }
......
<?php <?php
namespace Drupal\tsk\Entity; namespace Drupal\tsk_admin\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Config\Entity\ConfigEntityBase;
...@@ -10,14 +10,14 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; ...@@ -10,14 +10,14 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
* @ConfigEntityType( * @ConfigEntityType(
* id = "tsk_entity", * id = "tsk_entity",
* label = @Translation("Temporary Storage Killer Entity"), * label = @Translation("Temporary Storage Killer Entity"),
* module = "tsk", * module = "tsk_admin",
* config_prefix = "tsk", * config_prefix = "tsk",
* handlers = { * handlers = {
* "list_builder" = "Drupal\tsk\TskEntityListBuilder", * "list_builder" = "Drupal\tsk_admin\TskEntityListBuilder",
* "form" = { * "form" = {
* "add" = "Drupal\tsk\Form\TskEntityForm", * "add" = "Drupal\tsk_admin\Form\TskEntityForm",
* "edit" = "Drupal\tsk\Form\TskEntityForm", * "edit" = "Drupal\tsk_admin\Form\TskEntityForm",
* "delete" = "Drupal\tsk\Form\TskEntityDeleteForm", * "delete" = "Drupal\tsk_admin\Form\TskEntityDeleteForm",
* } * }
* }, * },
* admin_permission = "administer temporary storage killer", * admin_permission = "administer temporary storage killer",
...@@ -26,7 +26,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; ...@@ -26,7 +26,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
* }, * },
* config_export = { * config_export = {
* "id", * "id",
* "private", * "type",
* "collection", * "collection",
* "kill_all", * "kill_all",
* "key" * "key"
...@@ -48,11 +48,11 @@ class TskEntity extends ConfigEntityBase implements TskEntityInterface { ...@@ -48,11 +48,11 @@ class TskEntity extends ConfigEntityBase implements TskEntityInterface {
public $id = NULL; public $id = NULL;
/** /**
* Is the tempstore private (true) or shared (false)? * Type of the collection: private / shared.
* *
* @var bool * @var string
*/ */
public $private = FALSE; public $type = 'private';
/** /**
* The collection name to use for this key/value store. * The collection name to use for this key/value store.
......
<?php <?php
namespace Drupal\tsk\Entity; namespace Drupal\tsk_admin\Entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Config\Entity\ConfigEntityInterface;
......
<?php <?php
namespace Drupal\tsk\Form; namespace Drupal\tsk_admin\Form;
use Drupal\Core\Entity\EntityConfirmFormBase; use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\EntityStorageException;
......
<?php <?php
namespace Drupal\tsk\Form; namespace Drupal\tsk_admin\Form;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityForm;
...@@ -51,13 +51,17 @@ class TskEntityForm extends EntityForm { ...@@ -51,13 +51,17 @@ class TskEntityForm extends EntityForm {
$form = parent::form($form, $form_state); $form = parent::form($form, $form_state);
// Attach the custom library. // Attach the custom library.
$form['#attached']['library'][] = 'tsk/entityForm'; $form['#attached']['library'][] = 'tsk_admin/entityForm';
$form['private'] = [ $form['type'] = [
'#type' => 'checkbox', '#type' => 'select',
'#title' => $this->t('Private tempstore'), '#title' => $this->t('Tempstore type'),
'#default_value' => $tsk_entity->private, '#default_value' => $tsk_entity->type,
'#description' => $this->t('If checked, private tempstore will be used. Otherwise will be used shared tempstore.'), '#description' => $this->t('Type of the tempstore.'),
'#options' => [
'private' => $this->t('private'),
'shared' => $this->t('shared'),
],
]; ];
$form['collection'] = [ $form['collection'] = [
......
<?php
namespace Drupal\tsk_admin\Services;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\tsk\Services\TskServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides methods to delete temporary storages.
*
* @package Drupal\tsk
*/
class TskAdminService implements TskAdminServiceInterface {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Temporary Storage Killer service.
*
* @var \Drupal\tsk\Services\TskServiceInterface
*/
protected $tskService;
/**
* Constructs a TskService object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\tsk\Services\TskServiceInterface $tsk_service
* Temporary Storage Killer service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, TskServiceInterface $tsk_service) {
$this->entityTypeManager = $entity_type_manager;
$this->tskService = $tsk_service;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager'),
$container->get('tsk.service')
);
}
/**
* Deletes all temporary storages specified as TSK config entity.
*/
public function killAll(): void {
$tsk_entities = $this->entityTypeManager->getStorage('tsk_entity')->loadMultiple();
foreach ($tsk_entities as $tsk_entity) {
$this->tskService->kill($tsk_entity->collection, $tsk_entity->type, $tsk_entity->kill_all, $tsk_entity->key);
}
}
}
<?php
namespace Drupal\tsk_admin\Services;
/**
* Provides methods to delete temporary storages.
*
* @package Drupal\tsk
*/
interface TskAdminServiceInterface {
/**
* Deletes all temporary storages specified as TSK config entity.
*/
public function killAll(): void;
}
<?php <?php
namespace Drupal\tsk; namespace Drupal\tsk_admin;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
...@@ -18,7 +18,7 @@ class TskEntityListBuilder extends ConfigEntityListBuilder { ...@@ -18,7 +18,7 @@ class TskEntityListBuilder extends ConfigEntityListBuilder {
// Prepare the table header. // Prepare the table header.
$header = []; $header = [];
$header['id'] = $this->t('Id'); $header['id'] = $this->t('Id');
$header['private'] = $this->t('Private tempstore'); $header['type'] = $this->t('Tempstore type');
$header['collection'] = $this->t('Collection'); $header['collection'] = $this->t('Collection');
$header['kill_all'] = $this->t('Kill all'); $header['kill_all'] = $this->t('Kill all');
$header['key'] = $this->t('Key'); $header['key'] = $this->t('Key');
...@@ -34,7 +34,7 @@ class TskEntityListBuilder extends ConfigEntityListBuilder { ...@@ -34,7 +34,7 @@ class TskEntityListBuilder extends ConfigEntityListBuilder {
// Prepare the table row for the directory. // Prepare the table row for the directory.
$row = []; $row = [];
$row['id'] = $entity->id(); $row['id'] = $entity->id();
$row['private'] = $entity->private; $row['type'] = $entity->type;
$row['collection'] = $entity->collection; $row['collection'] = $entity->collection;
$row['kill_all'] = $entity->kill_all; $row['kill_all'] = $entity->kill_all;
$row['key'] = $entity->key; $row['key'] = $entity->key;
...@@ -97,7 +97,7 @@ class TskEntityListBuilder extends ConfigEntityListBuilder { ...@@ -97,7 +97,7 @@ class TskEntityListBuilder extends ConfigEntityListBuilder {
$build['kill_all_link'] = [ $build['kill_all_link'] = [
'#type' => 'link', '#type' => 'link',
'#url' => $url, '#url' => $url,
'#title' => t('Kill all'), '#title' => $this->t('Kill all'),
]; ];
return $build; return $build;
......
name: 'Temporary Storages Killer administration'
type: module
description: 'Provides a config entity and user interface for Temporary Storage Killer.'
core_version_requirement: ^9.2 || ^10
package: Other
configure: entity.tsk_entity
dependencies:
- tsk:tsk
entityForm: entityForm:
css: css:
base: base:
assets/css/tsk-entity-form.css: {} assets/css/tsk-admin-entity-form.css: {}
js: js:
assets/js/tsk-entity-form.js: {} assets/js/tsk-admin-entity-form.js: {}
dependencies: dependencies:
- core/jquery - core/jquery
- core/drupal - core/drupal
File moved
File moved
File moved
...@@ -29,12 +29,12 @@ entity.tsk_entity.delete: ...@@ -29,12 +29,12 @@ entity.tsk_entity.delete:
entity.tsk_entity.kill: entity.tsk_entity.kill:
path: '/admin/config/development/performance/tsk/{tsk_entity}/kill' path: '/admin/config/development/performance/tsk/{tsk_entity}/kill'
defaults: defaults:
_controller: '\Drupal\tsk\Controller\TskController::kill' _controller: '\Drupal\tsk_admin\Controller\TskAdminController::kill'
requirements: requirements:
_permission: 'administer tsk' _permission: 'administer tsk'
entity.tsk_entity.kill_all: entity.tsk_entity.kill_all:
path: '/admin/config/development/performance/tsk/kill-all' path: '/admin/config/development/performance/tsk/kill-all'
defaults: defaults:
_controller: '\Drupal\tsk\Controller\TskController::killAll' _controller: '\Drupal\tsk_admin\Controller\TskAdminController::killAll'
requirements: requirements:
_permission: 'administer tsk' _permission: 'administer tsk'
services:
tsk_admin.service:
class: Drupal\tsk_admin\Services\TskAdminService
arguments: ['@entity_type.manager', '@tsk.service']
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment