Skip to content

Commit

Permalink
Add Drush command to build the snapshot table.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordandukart committed Dec 13, 2024
1 parent 9b34d20 commit 3010a6e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions drush.9-11.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ services:
- '@module_installer'
- '@theme_handler'
- '@string_translation'
- '@content_sync.snaphoshot'
tags:
- { name: drush.command }
28 changes: 27 additions & 1 deletion src/Drush/Commands/ContentSyncCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Drupal\content_sync\Drush\Commands;

use Consolidation\AnnotatedCommand\Attributes\HookSelector;
use Drupal\Component\DependencyInjection\ContainerInterface;
use Drupal\content_sync\Form\ContentExportForm;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Drupal\content_sync\ContentSyncManagerInterface;
Expand All @@ -21,6 +23,7 @@
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands;
use Drush\Exceptions\UserAbortException;
use Symfony\Component\Console\Helper\Table;
Expand Down Expand Up @@ -68,6 +71,13 @@ class ContentSyncCommands extends DrushCommands {

protected $moduleHandler;

/**
* The snapshot service.
*
* @var \Drupal\content_sync\Form\ContentExportForm
*/
protected ContentExportForm $snapshot;

/**
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
Expand Down Expand Up @@ -141,8 +151,10 @@ protected function getExportLogger() {
* The themeHandler.
* @param \Drupal\Core\StringTranslation\TranslationInterface $stringTranslation
* The stringTranslation.
* @param \Drupal\content_sync\Form\ContentExportForm $snapshot
* The snapshot service.
*/
public function __construct(StorageInterface $contentStorage, StorageInterface $contentStorageSync, ContentSyncManagerInterface $contentSyncManager, EntityTypeManagerInterface $entity_type_manager, ContentExporterInterface $content_exporter, ModuleHandlerInterface $moduleHandler, EventDispatcherInterface $eventDispatcher, LockBackendInterface $lock, TypedConfigManagerInterface $configTyped, ModuleInstallerInterface $moduleInstaller, ThemeHandlerInterface $themeHandler, TranslationInterface $stringTranslation) {
public function __construct(StorageInterface $contentStorage, StorageInterface $contentStorageSync, ContentSyncManagerInterface $contentSyncManager, EntityTypeManagerInterface $entity_type_manager, ContentExporterInterface $content_exporter, ModuleHandlerInterface $moduleHandler, EventDispatcherInterface $eventDispatcher, LockBackendInterface $lock, TypedConfigManagerInterface $configTyped, ModuleInstallerInterface $moduleInstaller, ThemeHandlerInterface $themeHandler, TranslationInterface $stringTranslation, ContentExportForm $snapshot) {
parent::__construct();
$this->contentStorage = $contentStorage;
$this->contentStorageSync = $contentStorageSync;
Expand All @@ -156,6 +168,7 @@ public function __construct(StorageInterface $contentStorage, StorageInterface $
$this->moduleInstaller = $moduleInstaller;
$this->themeHandler = $themeHandler;
$this->stringTranslation = $stringTranslation;
$this->snapshot = $snapshot;
}

/**
Expand All @@ -175,6 +188,7 @@ public static function create(ContainerInterface $container) {
$container->get('module_installer'),
$container->get('theme_handler'),
$container->get('string_translation'),
$container->get('content_sync.snaphoshot')
);
}

Expand Down Expand Up @@ -501,4 +515,16 @@ public static function processFilesOption($options) {
if (!in_array($include_files, ['folder', 'base64'])) $include_files = 'none';
return $include_files;
}

/**
* Helper that rebuilds the snapshot table.
*/
#[CLI\Command(name: 'content-sync:snapshot', aliases: ['cs:s'])]
#[HookSelector(name: 'islandora-drush-utils-user-wrap')]
public function buildSnapshot() : void {
$this->logger()->notice('Building snapshot...');
$this->snapshot->snapshot();
drush_backend_batch_process();
}

}

0 comments on commit 3010a6e

Please sign in to comment.