Move files

This commit is contained in:
2025-04-04 15:25:13 -04:00
parent 979443da36
commit 432d6ca246
88 changed files with 43227 additions and 0 deletions

View File

@ -0,0 +1,95 @@
<?php
namespace App\Command;
use App\Entity\Reference;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'app:import-heidelberg',
description: 'Import Heidelberg Catechism',
)]
class ImportHeidelbergCommand extends Command
{
/**
* IO
*
* @var SymfonyStyle
*/
private SymfonyStyle $io;
/**
* EntityManager
*
* @var EntityManagerInterface
*/
private EntityManagerInterface $emi;
/**
* @param EntityManagerInterface $emi
*/
public function __construct(EntityManagerInterface $emi)
{
parent::__construct();
$this->emi = $emi;
}
protected function configure(): void
{
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io = new SymfonyStyle($input, $output);
$files = glob('references/Heidelberg Catechism/*.md');
natsort($files);
$this->io->progressStart(count($files));
foreach ($files as $file) {
$basename = basename($file);
//$io->info("Processing ".basename($file));
$this->processFile($file);
$this->io->progressAdvance();
}
$this->io->progressFinish();
return Command::SUCCESS;
}
private function processFile(string $file): Reference|bool
{
$md = trim(file_get_contents($file));
$ref = new Reference();
if (!$md) {
$this->io->warning("File is empty\n{$file}");
return false;
}
$match = [];
if (preg_match("/LD(\d+)\-HC(\d+)/", $file, $match)) {
$type = 'hc';
$label = "LD{$match[1]}-HC{$match[2]}";
$name = 'Heidelberg';
}
$ref->setNdx($match[2]);
$ref->setLabel($label);
$ref->setType($type);
$ref->setName($name);
$ref->setContent($md);
$this->emi->persist($ref);
$this->emi->flush();
return $ref;
}
}