Batch.php in Organic groups 8
File
src/Plugin/OgDeleteOrphans/Batch.php
View source
<?php
declare (strict_types=1);
namespace Drupal\og\Plugin\OgDeleteOrphans;
use Drupal\Core\Form\FormStateInterface;
use Drupal\og\OgDeleteOrphansBase;
class Batch extends OgDeleteOrphansBase {
public function process() {
$queue = $this
->getQueue();
$item = $queue
->claimItem(0);
$data = $item->data;
$this
->deleteOrphan($data['type'], $data['id']);
$queue
->deleteItem($item);
}
public function configurationForm(array $form, FormStateInterface $form_state) {
$count = $this
->getQueue()
->numberOfItems();
return [
'#type' => 'fieldset',
'#title' => $this
->t('Batch options'),
'info' => [
'#markup' => '<p>' . $this
->t('There are :count orphans waiting to be deleted.', [
':count' => $count,
]) . '</p>',
],
'submit' => [
'#type' => 'submit',
'#value' => $this
->t('Start batch deletion'),
'#submit' => [
'\\Drupal\\og\\Plugin\\OgDeleteOrphans\\Batch::batchSubmit',
],
'#disabled' => !(bool) $count,
],
];
}
public static function batchSubmit($form, FormStateInterface $form_state) {
$batch = [];
$steps = \Drupal::queue('og_orphaned_group_content')
->numberOfItems();
for ($i = 0; $i < $steps; $i++) {
$batch['operations'][] = [
'\\Drupal\\og\\Plugin\\OgDeleteOrphans\\Batch::step',
[],
];
}
batch_set($batch);
}
public static function step($context) {
if (!empty($context['interrupted'])) {
return;
}
\Drupal::getContainer()
->get('plugin.manager.og.delete_orphans')
->createInstance('batch', [])
->process();
}
}
Classes
Name |
Description |
Batch |
Performs a batch deletion of orphans. |