Skip to content
Snippets Groups Projects

Draft: Issue #3485600: Allow reporting pages that are missing to migrate

1 unresolved thread
1 unresolved thread
3 files
+ 177
0
Compare changes
  • Side-by-side
  • Inline
Files
3
<?php
namespace Drupal\wordpress_migrate_sql\Drush\Commands;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\File\FileUrlGeneratorInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\redirect\RedirectRepository;
use Drupal\wordpress_migrate_sql\MigrationStatus;
use Drupal\wordpress_migrate_sql\WordpressPost;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands;
use FontLib\Table\Type\name;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Mime\MimeTypeGuesserInterface;
final class WordpressMigrateSqlUrlCommands extends DrushCommands {
use StringTranslationTrait;
public function __construct(protected RedirectRepository $redirectRepository, protected FileUrlGeneratorInterface $fileUrlGenerator) {}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): self {
return new static(
$container->get('redirect.repository'),
$container->get('file_url_generator'),
);
}
/**
* Command description here.
*/
#[CLI\Command(name: 'wordpress_migrate_sql:missing-urls', aliases: ['wms:mu'])]
#[CLI\Argument(name: 'database_name', description: 'Database name.')]
#[CLI\Argument(name: 'result_file', description: 'Result file.')]
#[Cli\Option(name: 'post-types', description: 'Post types.')]
#[Cli\Option(name: 'wordpress-base-url', description: 'Wordpress base url.')]
#[CLI\Usage(name: 'wordpress_migrate_sql:missing-urls', description: 'Get list of missing urls')]
public function analyzeAttachments(
$database_name,
string $result_file = 'public://wordpress-migrate-sql-missing-urls.csv',
Please register or sign in to reply
array $options = [
'post-types' => 'post',
'wordpress-base-url' => '',
]) {
$database = Database::getConnection('default', $database_name);
$migration_status = new MigrationStatus($this->redirectRepository, $database, explode(',', $options['post-types']));
$missing_urls = $migration_status->getMissingUrls();
if (!empty($missing_urls)) {
$base_url = !empty($options['wordpress-base-url']) ? $options['wordpress-base-url'] . '/' : '';
$missing_urls_csv = implode(',', ['Post ID', 'Post type', 'Wordpress URL']);
$missing_urls_csv = $missing_urls_csv . PHP_EOL . implode(PHP_EOL, array_map(function (WordpressPost $post) use ($base_url) {
return implode(',', [
$post->getId(),
$post->getType(),
$base_url . $post->getUrl(),
]);
}, $missing_urls));
file_put_contents($result_file, $missing_urls_csv);
$this->logger()->success(sprintf('Missing %s urls. Full report: %s', count($missing_urls), $this->fileUrlGenerator->generateAbsoluteString($result_file)));
}
}
}
Loading