import-legacy #110
|
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## [1.7.6] - 2026-05-08
|
||||
### Added
|
||||
- Añadido comando ImportLegacy para importar una base de datos de OG 1.1 a OG 3.0, hace llamadas al resto de comandos Migrate ya creados. Acepta un fichero dump.sql o los parametros de conexión a la base de datos OG 1.1
|
||||
|
||||
## [1.7.5] - 2026-05-06
|
||||
### Fixed
|
||||
- Corregida la ejecución de tareas programadas y la gestión de zona horaria UTC
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260507135000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Change partition size and memoryUsage columns to BIGINT';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE `partition` MODIFY size BIGINT NOT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE `partition` MODIFY size INT NOT NULL');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,261 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command\Migration;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Model\OrganizationalUnitTypes;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'opengnsys:import-legacy',
|
||||
description: 'Import data from OpenGnsys 1.1 database dump into ogcore',
|
||||
)]
|
||||
class ImportLegacyDbCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $entityManager,
|
||||
private UserPasswordHasherInterface $passwordHasher
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addOption('file', 'f', InputOption::VALUE_OPTIONAL, 'Path to the .sql dump file')
|
||||
->addOption('legacy-host', null, InputOption::VALUE_OPTIONAL, 'Legacy database host')
|
||||
->addOption('legacy-user', null, InputOption::VALUE_OPTIONAL, 'Legacy database user')
|
||||
->addOption('legacy-password', null, InputOption::VALUE_OPTIONAL, 'Legacy database password')
|
||||
->addOption('legacy-db', null, InputOption::VALUE_OPTIONAL, 'Legacy database name')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$file = $input->getOption('file');
|
||||
$legacyHost = $input->getOption('legacy-host');
|
||||
$legacyUser = $input->getOption('legacy-user');
|
||||
$legacyPass = $input->getOption('legacy-password');
|
||||
$legacyDb = $input->getOption('legacy-db');
|
||||
|
||||
if (!$file && (!$legacyHost || !$legacyUser || !$legacyDb)) {
|
||||
$io->error("You must provide either a .sql file via --file OR legacy database credentials (--legacy-host, --legacy-user, --legacy-db)");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if ($file && !file_exists($file)) {
|
||||
$io->error("The file provided does not exist: $file");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$connection = $this->entityManager->getConnection();
|
||||
$params = $connection->getParams();
|
||||
|
||||
$host = $params['host'] ?? '127.0.0.1';
|
||||
$dbuser = $params['user'] ?? 'root';
|
||||
$dbpass = $params['password'] ?? '';
|
||||
$dbname = $params['dbname'] ?? '';
|
||||
|
||||
try {
|
||||
// Get existing tables using DBAL
|
||||
$existingTables = $connection->fetchFirstColumn("SHOW TABLES");
|
||||
|
||||
$io->section("Phase 1: Injecting legacy SQL data into current database");
|
||||
$passwordArg = $dbpass ? "-p$dbpass" : "";
|
||||
|
||||
if ($file) {
|
||||
$command = "mysql -h $host -u $dbuser $passwordArg $dbname < " . escapeshellarg($file);
|
||||
} else {
|
||||
$legacyPassArg = $legacyPass ? "-p$legacyPass" : "";
|
||||
// We only dump the strictly necessary tables to avoid giant dumps and potential collisions
|
||||
$tablesToDump = [
|
||||
'centros', 'aulas', 'grupos', 'gruposordenadores',
|
||||
'nombresos',
|
||||
'tiposoftwares', 'softwares', 'perfilessoft', 'perfilessoft_softwares',
|
||||
'ordenadores',
|
||||
'tipohardwares', 'hardwares', 'perfileshard', 'perfileshard_hardwares',
|
||||
'ordenadores_particiones',
|
||||
'usuarios', 'administradores_centros'
|
||||
];
|
||||
$tablesArg = implode(' ', $tablesToDump);
|
||||
|
||||
$io->text("Fetching tables from remote database $legacyHost...");
|
||||
$command = "mysqldump -h $legacyHost -u $legacyUser $legacyPassArg $legacyDb $tablesArg | mysql -h $host -u $dbuser $passwordArg $dbname";
|
||||
}
|
||||
|
||||
exec($command . ' 2>&1', $outputLines, $resultCode);
|
||||
|
||||
if ($resultCode !== 0) {
|
||||
$io->error("Failed to import SQL dump.\n" . implode("\n", $outputLines));
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// Get new tables
|
||||
$currentTables = $connection->fetchFirstColumn("SHOW TABLES");
|
||||
$injectedTables = array_diff($currentTables, $existingTables);
|
||||
|
||||
if (empty($injectedTables)) {
|
||||
$io->warning("No new tables were detected after import. Make sure the dump is valid.");
|
||||
} else {
|
||||
$io->text("Detected " . count($injectedTables) . " injected tables.");
|
||||
}
|
||||
|
||||
// Define commands and their mandatory table dependencies
|
||||
$commands = [
|
||||
'opengnsys:migration:organizational-unit' => [
|
||||
'desc' => 'Migrating Organizational Units',
|
||||
'tables' => ['centros', 'aulas']
|
||||
],
|
||||
'opengnsys:migration:os' => [
|
||||
'desc' => 'Migrating Operative Systems',
|
||||
'tables' => ['nombresos']
|
||||
],
|
||||
'opengnsys:migration:software-profile' => [
|
||||
'desc' => 'Migrating Software and Profiles',
|
||||
'tables' => ['tiposoftwares', 'softwares', 'perfilessoft', 'perfilessoft_softwares']
|
||||
],
|
||||
'opengnsys:migration:clients' => [
|
||||
'desc' => 'Migrating Clients',
|
||||
'tables' => ['ordenadores']
|
||||
],
|
||||
'opengnsys:migration:hardware-profile' => [
|
||||
'desc' => 'Migrating Hardware and Profiles',
|
||||
'tables' => ['tipohardwares', 'hardwares', 'perfileshard']
|
||||
],
|
||||
'opengnsys:migration:partition' => [
|
||||
'desc' => 'Migrating Partitions',
|
||||
'tables' => ['ordenadores_particiones']
|
||||
],
|
||||
];
|
||||
|
||||
// Execute Orchestration with guaranteed cleanup
|
||||
try {
|
||||
$io->section("Phase 2: Executing Migration Commands");
|
||||
$app = $this->getApplication();
|
||||
|
||||
foreach ($commands as $cmdName => $info) {
|
||||
$io->text("-> " . $info['desc']);
|
||||
|
||||
// Check dependencies
|
||||
$missingTables = array_diff($info['tables'], $currentTables);
|
||||
if (!empty($missingTables)) {
|
||||
$io->warning("Skipped. Missing required tables: " . implode(', ', $missingTables));
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$commandLine = "php bin/console $cmdName 2>&1";
|
||||
passthru($commandLine, $returnCode);
|
||||
|
||||
if ($returnCode !== 0) {
|
||||
$io->error("Command $cmdName failed with code $returnCode.");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$io->error("Exception during $cmdName: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate Users manually since there is no official command for it
|
||||
$this->importUsers($connection, $io);
|
||||
|
||||
} finally {
|
||||
// Cleanup ALWAYS runs
|
||||
$io->section("Phase 3: Cleaning up injected tables");
|
||||
if (!empty($injectedTables)) {
|
||||
$connection->executeStatement("SET FOREIGN_KEY_CHECKS=0");
|
||||
foreach ($injectedTables as $table) {
|
||||
$connection->executeStatement("DROP TABLE IF EXISTS `$table`");
|
||||
}
|
||||
$connection->executeStatement("SET FOREIGN_KEY_CHECKS=1");
|
||||
$io->success("Dropped " . count($injectedTables) . " temporary tables.");
|
||||
}
|
||||
}
|
||||
|
||||
$io->success('Migration orchestrator finished successfully!');
|
||||
return Command::SUCCESS;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$io->error("Error: " . $e->getMessage());
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
private function importUsers(\Doctrine\DBAL\Connection $connection, SymfonyStyle $io): void
|
||||
{
|
||||
$io->text("-> Migrating Users and Permissions...");
|
||||
|
||||
try {
|
||||
// Check if tables exist
|
||||
$connection->executeQuery("SELECT 1 FROM usuarios LIMIT 1");
|
||||
} catch (\Exception $e) {
|
||||
$io->warning("Legacy table 'usuarios' not found. Skipping users migration.");
|
||||
return;
|
||||
}
|
||||
|
||||
$users = $connection->fetchAllAssociative("SELECT * FROM usuarios");
|
||||
$usersMap = [];
|
||||
|
||||
$userRepo = $this->entityManager->getRepository(User::class);
|
||||
|
||||
foreach ($users as $row) {
|
||||
// Check if user already exists
|
||||
$existingUser = $userRepo->findOneBy(['username' => $row['usuario']]);
|
||||
if ($existingUser) {
|
||||
$usersMap[$row['idusuario']] = $existingUser;
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user->setUsername($row['usuario']);
|
||||
// $user->setEmail($row['email'] ?? null); // User entity doesn't have email yet
|
||||
$user->setRoles(['ROLE_ADMIN']);
|
||||
// Standard generic password
|
||||
$user->setPassword($this->passwordHasher->hashPassword($user, '12345678'));
|
||||
|
||||
$this->entityManager->persist($user);
|
||||
$usersMap[$row['idusuario']] = $user;
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
|
||||
try {
|
||||
$connection->executeQuery("SELECT 1 FROM administradores_centros LIMIT 1");
|
||||
|
||||
// Assign access to Centros based on legacy `administradores_centros`
|
||||
$adminCentros = $connection->fetchAllAssociative("
|
||||
SELECT ac.idusuario, c.nombrecentro
|
||||
FROM administradores_centros ac
|
||||
JOIN centros c ON ac.idcentro = c.idcentro
|
||||
");
|
||||
|
||||
$ouRepo = $this->entityManager->getRepository(OrganizationalUnit::class);
|
||||
|
||||
foreach ($adminCentros as $row) {
|
||||
$idUser = $row['idusuario'];
|
||||
$centerName = $row['nombrecentro'];
|
||||
|
||||
if (isset($usersMap[$idUser])) {
|
||||
$ou = $ouRepo->findOneBy(['name' => $centerName, 'type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]);
|
||||
if ($ou) {
|
||||
$usersMap[$idUser]->addAllowedOrganizationalUnit($ou);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
} catch (\Exception $e) {
|
||||
// Table doesn't exist, ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ class MigrateClientsCommand extends Command
|
|||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
/** @var EntityManagerInterface $oldDatabaseEntityManager */
|
||||
$oldDatabaseEntityManager = $this->doctrine->getManager('og_1');
|
||||
$oldDatabaseEntityManager = $this->entityManager;
|
||||
|
||||
$clientRepository = $this->entityManager->getRepository(Client::class);
|
||||
$organizationalUnitRepository = $this->entityManager->getRepository(OrganizationalUnit::class);
|
||||
|
|
@ -43,52 +43,88 @@ class MigrateClientsCommand extends Command
|
|||
$rsmClients->addScalarResult('ip', 'ip');
|
||||
$rsmClients->addScalarResult('netiface', 'netiface');
|
||||
$rsmClients->addScalarResult('netdriver', 'netdriver');
|
||||
$rsmClients->addScalarResult('idperfilhard', 'ordenadores.idperfilhard');
|
||||
$rsmClients->addScalarResult('grupoid', 'ordenadores.grupoid');
|
||||
$rsmClients->addScalarResult('idaula', 'ordenadores.idaula');
|
||||
$rsmClients->addScalarResult('idperfilhard', 'idperfilhard');
|
||||
$rsmClients->addScalarResult('grupoid', 'grupoid');
|
||||
$rsmClients->addScalarResult('idaula', 'idaula');
|
||||
|
||||
$clientsQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idordenador, nombreordenador, numserie, ip, mac, netiface, netdriver, ordenadores.idaula, ordenadores.grupoid, ordenadores.idperfilhard FROM ordenadores LEFT JOIN aulas ON ordenadores.idaula = aulas.idaula LEFT JOIN perfileshard ON ordenadores.idperfilhard = perfileshard.idperfilhard', $rsmClients);
|
||||
$clientsQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idordenador, nombreordenador, numserie, ip, mac, netiface, netdriver, idaula, grupoid, idperfilhard FROM ordenadores', $rsmClients);
|
||||
$clients = $clientsQuery->getResult();
|
||||
|
||||
/** Ordenadores **/
|
||||
$output->writeln("CLIENTES TOTAL: ". count($clients));
|
||||
$count = 0;
|
||||
foreach ($clients as $client){
|
||||
$clientEntity = $clientRepository->findOneBy(['migrationId' => $client['idordenador']]);
|
||||
if(!$clientEntity){
|
||||
$clientEntity = new Client();
|
||||
$clientEntity->setMigrationId($client['idordenador']);
|
||||
$clientEntity->setName($client['nombreordenador']);
|
||||
$clientEntity->setSerialNumber($client['numserie']);
|
||||
$clientEntity->setNetiface($client['netiface']);
|
||||
$clientEntity->setNetdriver($client['netdriver']);
|
||||
$clientEntity->setMac($client['mac']);
|
||||
$clientEntity->setIp($client['ip']);
|
||||
$clientEntity->setMaintenance(false);
|
||||
$clientEntity->setPosition(['x' => 0, 'y' => 0]);
|
||||
try {
|
||||
$clientEntity = $clientRepository->findOneBy(['migrationId' => $client['idordenador']]);
|
||||
if(!$clientEntity){
|
||||
// Proactive check to avoid EntityManager closure on duplicate key
|
||||
if ($client['ip'] && $clientRepository->findOneBy(['ip' => $client['ip']])) {
|
||||
$output->writeln("<error>Skipping client " . $client['nombreordenador'] . " due to duplicate IP: " . $client['ip'] . "</error>");
|
||||
continue;
|
||||
}
|
||||
if ($client['mac'] && $clientRepository->findOneBy(['mac' => $client['mac']])) {
|
||||
$output->writeln("<error>Skipping client " . $client['nombreordenador'] . " due to duplicate MAC: " . $client['mac'] . "</error>");
|
||||
continue;
|
||||
}
|
||||
|
||||
$clientEntity = new Client();
|
||||
$clientEntity->setMigrationId($client['idordenador']);
|
||||
$clientEntity->setName($client['nombreordenador']);
|
||||
$clientEntity->setSerialNumber($client['numserie']);
|
||||
$clientEntity->setNetiface($client['netiface']);
|
||||
$clientEntity->setNetdriver($client['netdriver']);
|
||||
|
||||
// Format MAC: ensure colons and uppercase
|
||||
$mac = str_replace([':', '-', '.'], '', $client['mac']);
|
||||
if (strlen($mac) === 12) {
|
||||
$mac = strtoupper(implode(':', str_split($mac, 2)));
|
||||
}
|
||||
$clientEntity->setMac($mac);
|
||||
|
||||
$clientEntity->setIp($client['ip']);
|
||||
$clientEntity->setMaintenance(false);
|
||||
$clientEntity->setPosition(['x' => 0, 'y' => 0]);
|
||||
}
|
||||
|
||||
$parentMigrationId = (empty($client['grupoid']) || $client['grupoid'] == 0)
|
||||
? OrganizationalUnitTypes::CLASSROOM . '-' . $client['idaula']
|
||||
: OrganizationalUnitTypes::CLIENTS_GROUP . '-' . $client['grupoid'];
|
||||
|
||||
$organizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $parentMigrationId]);
|
||||
|
||||
if (!$organizationalUnit){
|
||||
$output->writeln("ORGANIZATIONAL UNIT NOT FOUND FOR CLIENT: ". $client['nombreordenador'] . " (ID: ". $parentMigrationId .")");
|
||||
}
|
||||
|
||||
if ($organizationalUnit){
|
||||
$clientEntity->setOrganizationalUnit($organizationalUnit);
|
||||
}
|
||||
|
||||
// Note: We don't link the 1.1 hardware profile entity here because the 2.0
|
||||
// HardwareProfile entity is exclusive to the client (OneToOne).
|
||||
// The population of hardware items will be done in the next command
|
||||
// based on the client's legacy idperfilhard.
|
||||
|
||||
$this->entityManager->persist($clientEntity);
|
||||
|
||||
$count++;
|
||||
if ($count % 100 === 0) {
|
||||
$output->writeln("... Processed $count clients ...");
|
||||
$this->entityManager->flush();
|
||||
$this->entityManager->clear(Client::class);
|
||||
$this->entityManager->clear(HardwareProfile::class);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("<error>CRITICAL ERROR migrating client " . ($client['nombreordenador'] ?? 'ID:'.$client['idordenador']) . ": " . $e->getMessage() . "</error>");
|
||||
// Reset EntityManager if a database error occurred
|
||||
if (!$this->entityManager->isOpen()) {
|
||||
$output->writeln("<error>EntityManager closed. Stopping migration.</error>");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
$migrationId = match ($client['ordenadores.grupoid']) {
|
||||
0 => OrganizationalUnitTypes::CLASSROOM . '-' . $client['ordenadores.idaula'],
|
||||
default => OrganizationalUnitTypes::CLIENTS_GROUP . '-' . $client['ordenadores.grupoid'],
|
||||
};
|
||||
$organizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $migrationId]);
|
||||
|
||||
if (!$organizationalUnit){
|
||||
$output->writeln("ORGANIZATIONAL UNIT NOT FOUND: ". $migrationId);
|
||||
}
|
||||
|
||||
if ($organizationalUnit){
|
||||
$clientEntity->setOrganizationalUnit($organizationalUnit);
|
||||
}
|
||||
|
||||
$hardwareProfile = $hardwareProfileRepository->findOneBy(['migrationId' => $client['ordenadores.idperfilhard']]);
|
||||
if ($hardwareProfile){
|
||||
$clientEntity->setHardwareProfile($hardwareProfile);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($clientEntity);
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
$output->writeln("CLIENTES MIGRADOS CORRECTAMENTE: $count");
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Command\Migration;
|
||||
|
||||
use App\Entity\Client;
|
||||
use App\Entity\Hardware;
|
||||
use App\Entity\HardwareProfile;
|
||||
use App\Entity\HardwareType;
|
||||
|
|
@ -29,8 +30,9 @@ class MigrateHardwareAndHardwareProfileCommand extends Command
|
|||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
/** @var EntityManagerInterface $oldDatabaseEntityManager */
|
||||
$oldDatabaseEntityManager = $this->doctrine->getManager('og_1');
|
||||
try {
|
||||
/** @var EntityManagerInterface $oldDatabaseEntityManager */
|
||||
$oldDatabaseEntityManager = $this->entityManager;
|
||||
|
||||
$organizationalUnitRepository = $this->entityManager->getRepository(OrganizationalUnit::class);
|
||||
$hardwareProfileRepository = $this->entityManager->getRepository(HardwareProfile::class);
|
||||
|
|
@ -96,65 +98,77 @@ class MigrateHardwareAndHardwareProfileCommand extends Command
|
|||
$this->entityManager->persist($hardwareEntity);
|
||||
}
|
||||
|
||||
/** Obtener los perfiles hardware de la base de datos antigua **/
|
||||
$rsmHardwareProfiles = new ResultSetMapping();
|
||||
$rsmHardwareProfiles->addScalarResult('idperfilhard', 'idperfilhard');
|
||||
$rsmHardwareProfiles->addScalarResult('descripcion', 'descripcion');
|
||||
$rsmHardwareProfiles->addScalarResult('comentarios', 'perfilhard.comentarios');
|
||||
$rsmHardwareProfiles->addScalarResult('grupoid', 'perfilhard.grupoid');
|
||||
$rsmHardwareProfiles->addScalarResult('idcentro', 'perfilhard.idcentro');
|
||||
/**
|
||||
* In OpenGnsys 2.0, HardwareProfile is linked OneToOne with Client and is mandatory.
|
||||
* We already created empty HardwareProfiles for each client in MigrateClientsCommand.
|
||||
* Now we populate them with the hardware items from the legacy profiles.
|
||||
**/
|
||||
|
||||
$hardwareProfilesQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idperfilhard, descripcion, grupos.comentarios, perfileshard.grupoid, perfileshard.idcentro FROM perfileshard LEFT JOIN grupos ON perfileshard.grupoid = grupos.idgrupo', $rsmHardwareProfiles);
|
||||
$hardwareProfiles = $hardwareProfilesQuery->getResult();
|
||||
|
||||
/** Perfiles hardware **/
|
||||
$output->writeln("PERFILES HARDWARE TOTAL: ". count($hardwareProfiles));
|
||||
foreach ($hardwareProfiles as $hardwareProfile){
|
||||
$hardwareProfileEntity = null;
|
||||
$hardwareProfileEntity = $hardwareProfileRepository->findOneBy(['migrationId' => $hardwareProfile['idperfilhard']]);
|
||||
if(!$hardwareProfileEntity){
|
||||
$hardwareProfileEntity = new HardwareProfile();
|
||||
$hardwareProfileEntity->setMigrationId($hardwareProfile['idperfilhard']);
|
||||
$hardwareProfileEntity->setDescription($hardwareProfile['descripcion']);
|
||||
$hardwareProfileEntity->setComments($hardwareProfile['perfilhard.comentarios']);
|
||||
}
|
||||
|
||||
$migrationId = match ($hardwareProfile['perfilhard.grupoid']) {
|
||||
0 => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT . '-' . $hardwareProfile['perfilhard.idcentro'],
|
||||
default => OrganizationalUnitTypes::CLASSROOMS_GROUP . '-' . $hardwareProfile['perfilhard.grupoid'],
|
||||
};
|
||||
|
||||
$organizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $migrationId]);
|
||||
|
||||
if ($organizationalUnit){
|
||||
$hardwareProfileEntity->setOrganizationalUnit($organizationalUnit);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($hardwareProfileEntity);
|
||||
}
|
||||
|
||||
/** Obtener los hardware, y asignarselos a los perfiles hardware **/
|
||||
// 1. Get legacy profile-to-hardware relations
|
||||
$rsmHardwareProfilesRelation = new ResultSetMapping();
|
||||
$rsmHardwareProfilesRelation->addScalarResult('idperfilhard', 'idperfilhard');
|
||||
$rsmHardwareProfilesRelation->addScalarResult('idhardware', 'idhardware');
|
||||
|
||||
$hardwareProfilesQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idperfilhard, idhardware FROM perfileshard_hardwares', $rsmHardwareProfilesRelation);
|
||||
$hardwareProfileRelations = $hardwareProfilesQuery->getResult();
|
||||
$hardwareProfileRelationsQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idperfilhard, idhardware FROM perfileshard_hardwares', $rsmHardwareProfilesRelation);
|
||||
$hardwareProfileRelations = $hardwareProfileRelationsQuery->getResult();
|
||||
|
||||
$output->writeln("PERFILES HARDWARE RELACIONES TOTAL: ". count($hardwareProfileRelations));
|
||||
foreach ($hardwareProfileRelations as $hardwareProfileRelation){
|
||||
$hardwareProfileEntity = $hardwareProfileRepository->findOneBy(['migrationId' => $hardwareProfileRelation['idperfilhard']]);
|
||||
$hardwareEntity = $hardwareRepository->findOneBy(['migrationId' => $hardwareProfileRelation['idhardware']]);
|
||||
$profileItemsMap = [];
|
||||
foreach ($hardwareProfileRelations as $rel) {
|
||||
$profileItemsMap[$rel['idperfilhard']][] = $rel['idhardware'];
|
||||
}
|
||||
|
||||
if ($hardwareProfileEntity && $hardwareEntity){
|
||||
$hardwareProfileEntity->addHardwareCollection($hardwareEntity);
|
||||
$this->entityManager->persist($hardwareProfileEntity);
|
||||
// 2. Get all legacy clients and their profile IDs
|
||||
$rsmClientProfiles = new ResultSetMapping();
|
||||
$rsmClientProfiles->addScalarResult('idordenador', 'idordenador');
|
||||
$rsmClientProfiles->addScalarResult('idperfilhard', 'idperfilhard');
|
||||
|
||||
$clientProfilesQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idordenador, idperfilhard FROM ordenadores', $rsmClientProfiles);
|
||||
$clientProfiles = $clientProfilesQuery->getResult();
|
||||
|
||||
$output->writeln("POPULATING HARDWARE PROFILES FOR ". count($clientProfiles) . " CLIENTS");
|
||||
|
||||
$count = 0;
|
||||
foreach ($clientProfiles as $cp) {
|
||||
$clientId = $cp['idordenador'];
|
||||
$legacyProfileId = (int)$cp['idperfilhard'];
|
||||
|
||||
// Only create/populate if there's a valid legacy profile
|
||||
if ($legacyProfileId > 0 && isset($profileItemsMap[$legacyProfileId])) {
|
||||
$clientEntity = $this->entityManager->getRepository(Client::class)->findOneBy(['migrationId' => $clientId]);
|
||||
|
||||
if ($clientEntity) {
|
||||
$hardwareProfileEntity = $clientEntity->getHardwareProfile();
|
||||
|
||||
if (!$hardwareProfileEntity) {
|
||||
$hardwareProfileEntity = new HardwareProfile();
|
||||
$hardwareProfileEntity->setClient($clientEntity);
|
||||
$hardwareProfileEntity->setMigrationId('client-' . $clientId);
|
||||
$hardwareProfileEntity->setDescription("Hardware Profile for " . $clientEntity->getName());
|
||||
}
|
||||
|
||||
foreach ($profileItemsMap[$legacyProfileId] as $hardwareId) {
|
||||
$hardwareEntity = $hardwareRepository->findOneBy(['migrationId' => $hardwareId]);
|
||||
if ($hardwareEntity) {
|
||||
$hardwareProfileEntity->addHardwareCollection($hardwareEntity);
|
||||
}
|
||||
}
|
||||
$this->entityManager->persist($hardwareProfileEntity);
|
||||
}
|
||||
}
|
||||
|
||||
$count++;
|
||||
if ($count % 100 === 0) {
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
return Command::SUCCESS;
|
||||
return Command::SUCCESS;
|
||||
} catch (\Throwable $e) {
|
||||
$output->writeln("<error>FATAL ERROR IN HARDWARE COMMAND: " . $e->getMessage() . "</error>");
|
||||
$output->writeln($e->getTraceAsString());
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class MigrateImagesCommand extends Command
|
|||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
/** @var EntityManagerInterface $oldDatabaseEntityManager */
|
||||
$oldDatabaseEntityManager = $this->doctrine->getManager('og_1');
|
||||
$oldDatabaseEntityManager = $this->entityManager;
|
||||
|
||||
$imagesRepository = $this->entityManager->getRepository(Image::class);
|
||||
$clientRepository = $this->entityManager->getRepository(Client::class);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class MigrateOperativeSystemCommand extends Command
|
|||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
/** @var EntityManagerInterface $oldDatabaseEntityManager */
|
||||
$oldDatabaseEntityManager = $this->doctrine->getManager('og_1');
|
||||
$oldDatabaseEntityManager = $this->entityManager;
|
||||
|
||||
$osRepository = $this->entityManager->getRepository(OperativeSystem::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,172 +24,235 @@ class MigrateOrganizationalUnitCommand extends Command
|
|||
parent::__construct();
|
||||
}
|
||||
|
||||
private array $seenNames = [];
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
/** @var EntityManagerInterface $oldDatabaseEntityManager */
|
||||
$oldDatabaseEntityManager = $this->doctrine->getManager('og_1');
|
||||
$oldDatabaseEntityManager = $this->entityManager;
|
||||
|
||||
/** Obtener los centros de la base de datos antigua **/
|
||||
$rsmCenters = new ResultSetMapping();
|
||||
$rsmCenters->addScalarResult('idcentro', 'idcentro');
|
||||
$rsmCenters->addScalarResult('nombrecentro', 'nombrecentro');
|
||||
$rsmCenters->addScalarResult('comentarios', 'comentarios');
|
||||
try {
|
||||
/** @var EntityManagerInterface $oldDatabaseEntityManager */
|
||||
$oldDatabaseEntityManager = $this->entityManager;
|
||||
|
||||
$centersQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idcentro, nombrecentro, comentarios FROM centros', $rsmCenters);
|
||||
$centers = $centersQuery->getResult();
|
||||
$organizationalUnitRepository = $this->entityManager->getRepository(OrganizationalUnit::class);
|
||||
|
||||
/** Obtener los grupos de aulas de la base de datos antigua **/
|
||||
$rsmGroups = new ResultSetMapping();
|
||||
$rsmGroups->addScalarResult('idgrupo', 'idgrupo');
|
||||
$rsmGroups->addScalarResult('nombregrupo', 'nombregrupo');
|
||||
$rsmGroups->addScalarResult('comentarios', 'grupos.comentarios');
|
||||
$rsmGroups->addScalarResult('idcentro', 'grupos.idcentro');
|
||||
/** Centros **/
|
||||
$rsmCenters = new ResultSetMapping();
|
||||
$rsmCenters->addScalarResult('idcentro', 'idcentro');
|
||||
$rsmCenters->addScalarResult('nombrecentro', 'nombrecentro');
|
||||
$rsmCenters->addScalarResult('comentarios', 'comentarios');
|
||||
|
||||
$groupsQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idgrupo, nombregrupo, grupos.comentarios, grupos.idcentro FROM grupos LEFT JOIN centros ON grupos.idcentro = centros.idcentro', $rsmGroups);
|
||||
$groups = $groupsQuery->getResult();
|
||||
$centersQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idcentro, nombrecentro, comentarios FROM centros', $rsmCenters);
|
||||
$centers = $centersQuery->getResult();
|
||||
|
||||
/** Obtener las aulas de la base de datos antigua **/
|
||||
$rsmClassrooms = new ResultSetMapping();
|
||||
$rsmClassrooms->addScalarResult('idaula', 'idaula');
|
||||
$rsmClassrooms->addScalarResult('nombreaula', 'nombreaula');
|
||||
$rsmClassrooms->addScalarResult('comentarios', 'aulas.comentarios');
|
||||
$rsmClassrooms->addScalarResult('grupoid', 'aulas.grupoid');
|
||||
$rsmClassrooms->addScalarResult('idcentro', 'aulas.idcentro');
|
||||
$rsmClassrooms->addScalarResult('proxy', 'proxy');
|
||||
$rsmClassrooms->addScalarResult('dns', 'dns');
|
||||
$rsmClassrooms->addScalarResult('netmask', 'netmask');
|
||||
$rsmClassrooms->addScalarResult('router', 'router');
|
||||
$rsmClassrooms->addScalarResult('ntp', 'ntp');
|
||||
$rsmClassrooms->addScalarResult('timep2p', 'timep2p');
|
||||
$rsmClassrooms->addScalarResult('modp2p', 'modp2p');
|
||||
$rsmClassrooms->addScalarResult('ipmul', 'ipmul');
|
||||
$rsmClassrooms->addScalarResult('pormul', 'pormul');
|
||||
$rsmClassrooms->addScalarResult('modomul', 'modomul');
|
||||
$rsmClassrooms->addScalarResult('velmul', 'velmul');
|
||||
$rsmClassrooms->addScalarResult('pizarra', 'pizarra');
|
||||
$rsmClassrooms->addScalarResult('cagnon', 'cagnon');
|
||||
$rsmClassrooms->addScalarResult('ubicacion', 'ubicacion');
|
||||
|
||||
$roomsQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idaula, nombreaula, aulas.comentarios, aulas.grupoid, aulas.idcentro, proxy, dns, netmask, router, ntp, timep2p, modp2p, modomul, ipmul, velmul, pormul, pizarra, cagnon, ubicacion FROM aulas LEFT JOIN grupos ON aulas.grupoid = grupos.idgrupo', $rsmClassrooms);
|
||||
$rooms = $roomsQuery->getResult();
|
||||
|
||||
/** Obtener los grupos de ordenadores de la base de datos antigua **/
|
||||
$rsmClientGroups = new ResultSetMapping();
|
||||
$rsmClientGroups->addScalarResult('idgrupo', 'idgrupo');
|
||||
$rsmClientGroups->addScalarResult('nombregrupoordenador', 'nombregrupoordenador');
|
||||
$rsmClientGroups->addScalarResult('comentarios', 'gruposordenadores.comentarios');
|
||||
$rsmClientGroups->addScalarResult('idaula', 'gruposordenadores.idaula');
|
||||
$clientGroupsQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idgrupo, nombregrupoordenador, gruposordenadores.comentarios, gruposordenadores.idaula FROM gruposordenadores LEFT JOIN aulas ON gruposordenadores.idaula = aulas.idaula', $rsmClientGroups);
|
||||
$clientGroups = $clientGroupsQuery->getResult();
|
||||
|
||||
$organizationalUnitRepository = $this->entityManager->getRepository(OrganizationalUnit::class);
|
||||
|
||||
/** Centros **/
|
||||
$output->writeln("CENTROS TOTAL: ". count($centers));
|
||||
foreach ($centers as $center){
|
||||
$centerOrganizationalUnit = null;
|
||||
$centerOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT.'-'.$center['idcentro'], 'type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]);
|
||||
if(!$centerOrganizationalUnit){
|
||||
$centerOrganizationalUnit = new OrganizationalUnit();
|
||||
$centerOrganizationalUnit->setMigrationId(OrganizationalUnitTypes::ORGANIZATIONAL_UNIT.'-'.$center['idcentro']);
|
||||
$centerOrganizationalUnit->setName($center['nombrecentro']);
|
||||
$centerOrganizationalUnit->setComments($center['comentarios']);
|
||||
$output->writeln("CENTROS TOTAL: ". count($centers));
|
||||
foreach ($centers as $center){
|
||||
$migrationId = OrganizationalUnitTypes::ORGANIZATIONAL_UNIT.'-'.$center['idcentro'];
|
||||
$centerOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $migrationId]);
|
||||
|
||||
if(!$centerOrganizationalUnit){
|
||||
$centerOrganizationalUnit = new OrganizationalUnit();
|
||||
$centerOrganizationalUnit->setMigrationId($migrationId);
|
||||
}
|
||||
$centerOrganizationalUnit->setType(OrganizationalUnitTypes::ORGANIZATIONAL_UNIT);
|
||||
|
||||
$name = $center['nombrecentro'];
|
||||
$key = 'root';
|
||||
$originalName = $name;
|
||||
$counter = 1;
|
||||
while (isset($this->seenNames[$key][$name])) {
|
||||
$name = $originalName . ' (' . $counter . ')';
|
||||
$counter++;
|
||||
}
|
||||
|
||||
// Also check database but exclude the current entity if it already exists
|
||||
$existingOU = $organizationalUnitRepository->findOneBy(['name' => $name, 'parent' => null]);
|
||||
if ($existingOU && $existingOU->getMigrationId() !== $migrationId) {
|
||||
while ($organizationalUnitRepository->findOneBy(['name' => $name, 'parent' => null])) {
|
||||
$name = $originalName . ' (' . $counter . ')';
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
$this->seenNames[$key][$name] = true;
|
||||
|
||||
$centerOrganizationalUnit->setName($name);
|
||||
$centerOrganizationalUnit->setComments($center['comentarios']);
|
||||
$this->entityManager->persist($centerOrganizationalUnit);
|
||||
}
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
$this->entityManager->flush();
|
||||
|
||||
/** Grupos de aulas **/
|
||||
$output->writeln("GRUPOS DE AULAS TOTAL: ". count($groups));
|
||||
foreach ($groups as $group){
|
||||
$groupPcOrganizationalUnit = null;
|
||||
$groupPcOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => OrganizationalUnitTypes::CLASSROOMS_GROUP.'-'.$group['idgrupo'], 'type' => OrganizationalUnitTypes::CLASSROOMS_GROUP]);
|
||||
if(!$groupPcOrganizationalUnit){
|
||||
$groupPcOrganizationalUnit = new OrganizationalUnit();
|
||||
$groupPcOrganizationalUnit->setMigrationId(OrganizationalUnitTypes::CLASSROOMS_GROUP.'-'.$group['idgrupo']);
|
||||
$groupPcOrganizationalUnit->setName($group['nombregrupo']);
|
||||
$groupPcOrganizationalUnit->setComments($group['grupos.comentarios']);
|
||||
/** Grupos de aulas **/
|
||||
$rsmGroups = new ResultSetMapping();
|
||||
$rsmGroups->addScalarResult('idgrupo', 'idgrupo');
|
||||
$rsmGroups->addScalarResult('nombregrupo', 'nombregrupo');
|
||||
$rsmGroups->addScalarResult('comentarios', 'comentarios');
|
||||
$rsmGroups->addScalarResult('idcentro', 'idcentro');
|
||||
|
||||
$groupsQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idgrupo, nombregrupo, comentarios, idcentro FROM grupos', $rsmGroups);
|
||||
$groups = $groupsQuery->getResult();
|
||||
|
||||
$output->writeln("GRUPOS DE AULAS TOTAL: ". count($groups));
|
||||
foreach ($groups as $group){
|
||||
$migrationId = OrganizationalUnitTypes::CLASSROOMS_GROUP.'-'.$group['idgrupo'];
|
||||
$groupPcOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $migrationId]);
|
||||
|
||||
if(!$groupPcOrganizationalUnit){
|
||||
$groupPcOrganizationalUnit = new OrganizationalUnit();
|
||||
$groupPcOrganizationalUnit->setMigrationId($migrationId);
|
||||
}
|
||||
$groupPcOrganizationalUnit->setType(OrganizationalUnitTypes::CLASSROOMS_GROUP);
|
||||
|
||||
$center = $organizationalUnitRepository->findOneBy(['migrationId' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT.'-'.$group['grupos.idcentro']]);
|
||||
$center = $organizationalUnitRepository->findOneBy(['migrationId' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT.'-'.$group['idcentro']]);
|
||||
if ($center){
|
||||
$groupPcOrganizationalUnit->setParent($center);
|
||||
}
|
||||
|
||||
$name = $group['nombregrupo'];
|
||||
$key = $center ? $center->getMigrationId() : 'root';
|
||||
$originalName = $name;
|
||||
$counter = 1;
|
||||
while (isset($this->seenNames[$key][$name])) {
|
||||
$name = $originalName . ' (' . $counter . ')';
|
||||
$counter++;
|
||||
}
|
||||
|
||||
$existingOU = $organizationalUnitRepository->findOneBy(['name' => $name, 'parent' => $center]);
|
||||
if ($existingOU && $existingOU->getMigrationId() !== $migrationId) {
|
||||
while ($organizationalUnitRepository->findOneBy(['name' => $name, 'parent' => $center])) {
|
||||
$name = $originalName . ' (' . $counter . ')';
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
$this->seenNames[$key][$name] = true;
|
||||
|
||||
$groupPcOrganizationalUnit->setName($name);
|
||||
$groupPcOrganizationalUnit->setComments($group['comentarios']);
|
||||
|
||||
$this->entityManager->persist($groupPcOrganizationalUnit);
|
||||
}
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
$this->entityManager->flush();
|
||||
|
||||
/** Aulas **/
|
||||
$output->writeln("AULAS TOTAL: ". count($rooms));
|
||||
foreach ($rooms as $room){
|
||||
$roomOrganizationalUnit = null;
|
||||
$roomOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => OrganizationalUnitTypes::CLASSROOM.'-'.$room['idaula'], 'type' => OrganizationalUnitTypes::CLASSROOM]);
|
||||
if(!$roomOrganizationalUnit){
|
||||
$roomOrganizationalUnit = new OrganizationalUnit();
|
||||
$roomOrganizationalUnit->setMigrationId(OrganizationalUnitTypes::CLASSROOM.'-'.$room['idaula']);
|
||||
$roomOrganizationalUnit->setName($room['nombreaula']);
|
||||
$roomOrganizationalUnit->setComments($room['aulas.comentarios']);
|
||||
/** Aulas **/
|
||||
$rsmRooms = new ResultSetMapping();
|
||||
$rsmRooms->addScalarResult('idaula', 'idaula');
|
||||
$rsmRooms->addScalarResult('nombreaula', 'nombreaula');
|
||||
$rsmRooms->addScalarResult('comentarios', 'comentarios');
|
||||
$rsmRooms->addScalarResult('pizarra', 'pizarra');
|
||||
$rsmRooms->addScalarResult('cagnon', 'cagnon');
|
||||
$rsmRooms->addScalarResult('ubicacion', 'ubicacion');
|
||||
$rsmRooms->addScalarResult('idcentro', 'idcentro');
|
||||
$rsmRooms->addScalarResult('grupoid', 'grupoid');
|
||||
|
||||
$roomsQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idaula, nombreaula, comentarios, pizarra, cagnon, ubicacion, idcentro, grupoid FROM aulas', $rsmRooms);
|
||||
$rooms = $roomsQuery->getResult();
|
||||
|
||||
$output->writeln("AULAS TOTAL: ". count($rooms));
|
||||
foreach ($rooms as $room){
|
||||
$migrationId = OrganizationalUnitTypes::CLASSROOM.'-'.$room['idaula'];
|
||||
$roomOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $migrationId]);
|
||||
|
||||
if(!$roomOrganizationalUnit){
|
||||
$roomOrganizationalUnit = new OrganizationalUnit();
|
||||
$roomOrganizationalUnit->setMigrationId($migrationId);
|
||||
}
|
||||
$roomOrganizationalUnit->setType(OrganizationalUnitTypes::CLASSROOM);
|
||||
|
||||
// Hierarchy: If grupoid is 0 or null, parent is center. Otherwise, parent is classrooms-group.
|
||||
$parentMigrationId = (empty($room['grupoid']) || $room['grupoid'] == 0)
|
||||
? OrganizationalUnitTypes::ORGANIZATIONAL_UNIT.'-'.$room['idcentro']
|
||||
: OrganizationalUnitTypes::CLASSROOMS_GROUP.'-'.$room['grupoid'];
|
||||
|
||||
$parentOU = $organizationalUnitRepository->findOneBy(['migrationId' => $parentMigrationId]);
|
||||
|
||||
if ($parentOU){
|
||||
$roomOrganizationalUnit->setParent($parentOU);
|
||||
}
|
||||
|
||||
$name = $room['nombreaula'];
|
||||
$key = $parentOU ? $parentOU->getMigrationId() : 'root';
|
||||
$originalName = $name;
|
||||
$counter = 1;
|
||||
while (isset($this->seenNames[$key][$name])) {
|
||||
$name = $originalName . ' (' . $counter . ')';
|
||||
$counter++;
|
||||
}
|
||||
|
||||
$existingOU = $organizationalUnitRepository->findOneBy(['name' => $name, 'parent' => $parentOU]);
|
||||
if ($existingOU && $existingOU->getMigrationId() !== $migrationId) {
|
||||
while ($organizationalUnitRepository->findOneBy(['name' => $name, 'parent' => $parentOU])) {
|
||||
$name = $originalName . ' (' . $counter . ')';
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
$this->seenNames[$key][$name] = true;
|
||||
|
||||
$roomOrganizationalUnit->setName($name);
|
||||
$roomOrganizationalUnit->setComments($room['comentarios']);
|
||||
$roomOrganizationalUnit->setBoard($room['pizarra']);
|
||||
$roomOrganizationalUnit->setProjector($room['cagnon']);
|
||||
$roomOrganizationalUnit->setLocation($room['ubicacion']);
|
||||
$roomOrganizationalUnit->setType(OrganizationalUnitTypes::CLASSROOM);
|
||||
|
||||
$migrationId = $room['aulas.grupoid'] === 0 ? OrganizationalUnitTypes::ORGANIZATIONAL_UNIT.'-'.$room['aulas.idcentro'] : OrganizationalUnitTypes::CLASSROOMS_GROUP.'-'.$room['aulas.grupoid'];
|
||||
$organizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $migrationId]);
|
||||
|
||||
if ($organizationalUnit){
|
||||
$roomOrganizationalUnit->setParent($organizationalUnit);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($roomOrganizationalUnit);
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
|
||||
$networkSettings = $roomOrganizationalUnit->getNetworkSettings();
|
||||
if(!$networkSettings){
|
||||
$networkSettings = new NetworkSettings();
|
||||
$roomOrganizationalUnit->setNetworkSettings($networkSettings);
|
||||
$this->entityManager->persist($networkSettings);
|
||||
}
|
||||
$networkSettings->setProxy($room['proxy']);
|
||||
$networkSettings->setDns($room['dns']);
|
||||
$networkSettings->setNetmask($room['netmask']);
|
||||
$networkSettings->setRouter($room['router']);
|
||||
$networkSettings->setNtp($room['ntp']);
|
||||
$networkSettings->setP2pTime($room['timep2p']);
|
||||
$networkSettings->setP2pMode($room['modp2p']);
|
||||
$networkSettings->setMcastIp($room['ipmul']);
|
||||
$networkSettings->setMcastSpeed($room['velmul']);
|
||||
$networkSettings->setMcastPort($room['pormul']);
|
||||
$networkSettings->setMcastMode($room['modomul']);
|
||||
}
|
||||
/** Grupos de ordenadores **/
|
||||
$rsmClientGroups = new ResultSetMapping();
|
||||
$rsmClientGroups->addScalarResult('idgrupo', 'idgrupo');
|
||||
$rsmClientGroups->addScalarResult('nombregrupoordenador', 'nombregrupoordenador');
|
||||
$rsmClientGroups->addScalarResult('comentarios', 'comentarios');
|
||||
$rsmClientGroups->addScalarResult('idaula', 'idaula');
|
||||
|
||||
$this->entityManager->flush();
|
||||
$clientGroupsQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idgrupo, nombregrupoordenador, comentarios, idaula FROM gruposordenadores', $rsmClientGroups);
|
||||
$clientGroups = $clientGroupsQuery->getResult();
|
||||
|
||||
/** Grupo Ordenador **/
|
||||
$output->writeln("GRUPOS ORDENADORES ". count($clientGroups));
|
||||
foreach ($clientGroups as $clientGroup){
|
||||
$groupPcOrganizationalUnit = null;
|
||||
$groupPcOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => OrganizationalUnitTypes::CLIENTS_GROUP.'-'.$clientGroup['idgrupo'], 'type' => OrganizationalUnitTypes::CLIENTS_GROUP]);
|
||||
if(!$groupPcOrganizationalUnit){
|
||||
$groupPcOrganizationalUnit = new OrganizationalUnit();
|
||||
$groupPcOrganizationalUnit->setMigrationId(OrganizationalUnitTypes::CLIENTS_GROUP.'-'.$clientGroup['idgrupo']);
|
||||
$groupPcOrganizationalUnit->setName($clientGroup['nombregrupoordenador']);
|
||||
$groupPcOrganizationalUnit->setComments($clientGroup['gruposordenadores.comentarios']);
|
||||
$output->writeln("GRUPOS ORDENADORES ". count($clientGroups));
|
||||
foreach ($clientGroups as $clientGroup){
|
||||
$migrationId = OrganizationalUnitTypes::CLIENTS_GROUP.'-'.$clientGroup['idgrupo'];
|
||||
$groupPcOrganizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $migrationId]);
|
||||
|
||||
if(!$groupPcOrganizationalUnit){
|
||||
$groupPcOrganizationalUnit = new OrganizationalUnit();
|
||||
$groupPcOrganizationalUnit->setMigrationId($migrationId);
|
||||
}
|
||||
$groupPcOrganizationalUnit->setType(OrganizationalUnitTypes::CLIENTS_GROUP);
|
||||
|
||||
$room = $organizationalUnitRepository->findOneBy(['migrationId' => OrganizationalUnitTypes::CLASSROOM.'-'.$clientGroup['gruposordenadores.idaula']]);
|
||||
|
||||
$room = $organizationalUnitRepository->findOneBy(['migrationId' => OrganizationalUnitTypes::CLASSROOM.'-'.$clientGroup['idaula']]);
|
||||
if ($room){
|
||||
$groupPcOrganizationalUnit->setParent($room);
|
||||
}
|
||||
|
||||
$name = $clientGroup['nombregrupoordenador'];
|
||||
$key = $room ? $room->getMigrationId() : 'root';
|
||||
$originalName = $name;
|
||||
$counter = 1;
|
||||
while (isset($this->seenNames[$key][$name])) {
|
||||
$name = $originalName . ' (' . $counter . ')';
|
||||
$counter++;
|
||||
}
|
||||
|
||||
$existingOU = $organizationalUnitRepository->findOneBy(['name' => $name, 'parent' => $room]);
|
||||
if ($existingOU && $existingOU->getMigrationId() !== $migrationId) {
|
||||
while ($organizationalUnitRepository->findOneBy(['name' => $name, 'parent' => $room])) {
|
||||
$name = $originalName . ' (' . $counter . ')';
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
$this->seenNames[$key][$name] = true;
|
||||
|
||||
$groupPcOrganizationalUnit->setName($name);
|
||||
$groupPcOrganizationalUnit->setComments($clientGroup['comentarios']);
|
||||
|
||||
$this->entityManager->persist($groupPcOrganizationalUnit);
|
||||
}
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
$this->entityManager->flush();
|
||||
|
||||
return 1;
|
||||
return Command::SUCCESS;
|
||||
} catch (\Throwable $e) {
|
||||
$output->writeln("<error>FATAL ERROR IN COMMAND: " . $e->getMessage() . "</error>");
|
||||
$output->writeln($e->getTraceAsString());
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ class MigratePartitionClientCommand extends Command
|
|||
ini_set('memory_limit', '512M');
|
||||
|
||||
/** @var EntityManagerInterface $oldDatabaseEntityManager */
|
||||
$oldDatabaseEntityManager = $this->doctrine->getManager('og_1');
|
||||
$oldDatabaseEntityManager = $this->entityManager;
|
||||
|
||||
$clientRepository = $this->entityManager->getRepository(Client::class);
|
||||
$operativeSystemRepository = $this->entityManager->getRepository(OperativeSystem::class);
|
||||
|
|
@ -51,17 +51,21 @@ class MigratePartitionClientCommand extends Command
|
|||
|
||||
/** Particiones **/
|
||||
$output->writeln("PARTICIONES TOTAL: ". count($partitions));
|
||||
$count = 0;
|
||||
foreach ($partitions as $partition){
|
||||
$clientEntity = $clientRepository->findOneBy(['migrationId' => $partition['idordenador']]);
|
||||
if(!$clientEntity){
|
||||
$output->writeln("No se ha encontrado el cliente con id: ". $partition['idordenador']);
|
||||
$output->writeln("<error>No se ha encontrado el cliente con migrationId: ". $partition['idordenador'] . " en la tabla client de 2.0</error>");
|
||||
continue;
|
||||
}
|
||||
|
||||
$operativeSystemEntity = $operativeSystemRepository->findOneBy(['migrationId' => $partition['idnombreso']]);
|
||||
if(!$operativeSystemEntity){
|
||||
$output->writeln("No se ha encontrado el sistema operativo con id: ". $partition['idnombreso']);
|
||||
continue;
|
||||
$operativeSystemEntity = null;
|
||||
$legacyOsId = (int)$partition['idnombreso'];
|
||||
if ($legacyOsId > 0) {
|
||||
$operativeSystemEntity = $operativeSystemRepository->findOneBy(['migrationId' => $legacyOsId]);
|
||||
if(!$operativeSystemEntity){
|
||||
$output->writeln("No se ha encontrado el sistema operativo con id: ". $legacyOsId . " (se insertará con SO null)");
|
||||
}
|
||||
}
|
||||
|
||||
$partitionEntity = new Partition();
|
||||
|
|
@ -74,8 +78,14 @@ class MigratePartitionClientCommand extends Command
|
|||
$partitionEntity->setOperativeSystem($operativeSystemEntity);
|
||||
|
||||
$this->entityManager->persist($partitionEntity);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$count++;
|
||||
if ($count % 100 === 0) {
|
||||
$this->entityManager->flush();
|
||||
$this->entityManager->clear(Partition::class);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
$this->entityManager->flush();
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ class MigrateSoftwareAndSoftwareProfileCommand extends Command
|
|||
|
||||
|
||||
/** @var EntityManagerInterface $oldDatabaseEntityManager */
|
||||
$oldDatabaseEntityManager = $this->doctrine->getManager('og_1');
|
||||
$oldDatabaseEntityManager = $this->entityManager;
|
||||
|
||||
$organizationalUnitRepository = $this->entityManager->getRepository(OrganizationalUnit::class);
|
||||
$operativeSystemRepository = $this->entityManager->getRepository(OperativeSystem::class);
|
||||
|
|
@ -71,18 +71,6 @@ class MigrateSoftwareAndSoftwareProfileCommand extends Command
|
|||
$softwareEntity->setType($type);
|
||||
}
|
||||
|
||||
$migrationId = match ($software['softwares.grupoid']) {
|
||||
0 => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT . '-' . $software['softwares.idcentro'],
|
||||
default => OrganizationalUnitTypes::CLASSROOMS_GROUP . '-' . $software['softwares.grupoid'],
|
||||
};
|
||||
|
||||
$organizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $migrationId]);
|
||||
|
||||
/*
|
||||
if ($organizationalUnit){
|
||||
$softwareEntity->setOrganizationalUnit($organizationalUnit);
|
||||
}*/
|
||||
|
||||
$this->entityManager->persist($softwareEntity);
|
||||
}
|
||||
|
||||
|
|
@ -90,13 +78,10 @@ class MigrateSoftwareAndSoftwareProfileCommand extends Command
|
|||
$rsmSoftwareProfiles = new ResultSetMapping();
|
||||
$rsmSoftwareProfiles->addScalarResult('idperfilsoft', 'idperfilsoft');
|
||||
$rsmSoftwareProfiles->addScalarResult('descripcion', 'descripcion');
|
||||
$rsmSoftwareProfiles->addScalarResult('comentarios', 'perfilessoft.comentarios');
|
||||
$rsmSoftwareProfiles->addScalarResult('grupoid', 'perfilessoft.grupoid');
|
||||
$rsmSoftwareProfiles->addScalarResult('idcentro', 'perfilessoft.idcentro');
|
||||
$rsmSoftwareProfiles->addScalarResult('idnombreso', 'perfilessoft.idnombreso');
|
||||
$rsmSoftwareProfiles->addScalarResult('comentarios', 'comentarios');
|
||||
$rsmSoftwareProfiles->addScalarResult('idnombreso', 'idnombreso');
|
||||
|
||||
|
||||
$softwareProfilesQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idperfilsoft, descripcion, grupos.comentarios, perfilessoft.grupoid, perfilessoft.idcentro, perfilessoft.idnombreso FROM perfilessoft LEFT JOIN grupos ON perfilessoft.grupoid = grupos.idgrupo', $rsmSoftwareProfiles);
|
||||
$softwareProfilesQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idperfilsoft, descripcion, comentarios, idnombreso FROM perfilessoft', $rsmSoftwareProfiles);
|
||||
$softwareProfiles = $softwareProfilesQuery->getResult();
|
||||
|
||||
/** Perfiles software **/
|
||||
|
|
@ -108,21 +93,10 @@ class MigrateSoftwareAndSoftwareProfileCommand extends Command
|
|||
$softwareProfileEntity = new SoftwareProfile();
|
||||
$softwareProfileEntity->setMigrationId($softwareProfile['idperfilsoft']);
|
||||
$softwareProfileEntity->setDescription($softwareProfile['descripcion']);
|
||||
$softwareProfileEntity->setComments($softwareProfile['perfilessoft.comentarios']);
|
||||
$softwareProfileEntity->setComments($softwareProfile['comentarios']);
|
||||
}
|
||||
|
||||
$migrationId = match ($softwareProfile['perfilessoft.grupoid']) {
|
||||
0 => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT . '-' . $softwareProfile['perfilessoft.idcentro'],
|
||||
default => OrganizationalUnitTypes::CLASSROOMS_GROUP . '-' . $softwareProfile['perfilessoft.grupoid'],
|
||||
};
|
||||
|
||||
$organizationalUnit = $organizationalUnitRepository->findOneBy(['migrationId' => $migrationId]);
|
||||
|
||||
if ($organizationalUnit){
|
||||
$softwareProfileEntity->setOrganizationalUnit($organizationalUnit);
|
||||
}
|
||||
|
||||
$operativeSystem = $operativeSystemRepository->findOneBy(['migrationId' => $softwareProfile['perfilessoft.idnombreso']]);
|
||||
$operativeSystem = $operativeSystemRepository->findOneBy(['migrationId' => $softwareProfile['idnombreso']]);
|
||||
|
||||
if ($operativeSystem){
|
||||
$softwareProfileEntity->setOperativeSystem($operativeSystem);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Partition extends AbstractEntity
|
|||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $partitionCode = null;
|
||||
|
||||
#[ORM\Column]
|
||||
#[ORM\Column(type: Types::BIGINT)]
|
||||
private ?int $size = null;
|
||||
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue