class PrivateMessageCommands in Private Message 8.2
Creates Drush commands for the Private Message module.
In addition to this file, you need a drush.services.yml in root of your module, and a composer.json file that provides the name of the services file to use.
See these files for an example of injecting Drupal services:
- http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
- http://cgit.drupalcode.org/devel/tree/drush.services.yml
Hierarchy
- class \Drupal\private_message\Commands\PrivateMessageCommands extends \Drush\Commands\DrushCommands uses StringTranslationTrait
Expanded class hierarchy of PrivateMessageCommands
1 string reference to 'PrivateMessageCommands'
1 service uses PrivateMessageCommands
File
- src/
Commands/ PrivateMessageCommands.php, line 21
Namespace
Drupal\private_message\CommandsView source
class PrivateMessageCommands extends DrushCommands {
use StringTranslationTrait;
/**
* The private message service.
*
* @var \Drupal\private_message\Service\PrivateMessageService
*/
protected $privateMessageService;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a object.
*
* @param \Drupal\private_message\Service\PrivateMessageService $privateMessageService
* The private message service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
*/
public function __construct(PrivateMessageService $privateMessageService, EntityTypeManagerInterface $entityTypeManager) {
parent::__construct();
$this->privateMessageService = $privateMessageService;
$this->entityTypeManager = $entityTypeManager;
}
/**
* Prepares the Private Message module for uninstallation.
*
* @command private_message:prepare_uninstall
*
* @aliases pu
*/
public function prepareUninstall() {
if ($this
->io()
->confirm($this
->t('Proceeding will delete all private messages and private message threads in your system. They cannot be recovered. Do you wish to proceed?')
->render())) {
// Get the IDs of all threads in the system.
$thread_ids = $this->privateMessageService
->getThreadIds();
// Load the private message thread storage.
$thread_storage = $this->entityTypeManager
->getStorage('private_message_thread');
$message_storage = $this->entityTypeManager
->getStorage('private_message');
$output = $this
->output();
// Note that each thread ID is looped through, as there may be a massive
// number of threads in the system, meaning that loading them all could be
// a crazy memory hog and crash.
foreach ($thread_ids as $thread_id) {
// Load the thread.
$thread = $thread_storage
->load($thread_id);
$message_storage
->delete($thread
->getMessages());
// Delete the thread.
$thread_storage
->delete([
$thread,
]);
// Notify the user.
$output
->writeln($this
->t('Deleted thread: @id', [
'@id' => $thread_id,
])
->render());
}
// Inform the user the process is finished.
$output
->writeln($this
->t('All private message content deleted.')
->render());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PrivateMessageCommands:: |
protected | property | The entity type manager service. | |
PrivateMessageCommands:: |
protected | property | The private message service. | |
PrivateMessageCommands:: |
public | function | Prepares the Private Message module for uninstallation. | |
PrivateMessageCommands:: |
public | function | Constructs a object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |