Skip to content

Commit fa86124

Browse files
committed
Add migration fix from 1.9.x to 1.11.x, fixes lp.id to be updated to iid
1 parent d4f57db commit fa86124

File tree

2 files changed

+119
-46
lines changed

2 files changed

+119
-46
lines changed

src/Chash/Command/Installation/UpgradeCommand.php

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
381381

382382
$lastItem = count($versionsToRun);
383383
$counter = 0;
384-
$runFixIds = false;
384+
385385
foreach ($versionsToRun as $versionItem => $versionInfo) {
386-
if ($lastItem == $counter) {
386+
$runFixIds = false;
387+
$runLpFix = false;
388+
if ($versionItem === '1.10.0') {
387389
$runFixIds = true;
388390
}
389391

392+
if ($versionItem === '1.11.0') {
393+
$runLpFix = true;
394+
}
395+
390396
if (isset($versionInfo['require_update']) &&
391397
$versionInfo['require_update'] == true
392398
) {
@@ -404,12 +410,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
404410
$removeUnusedTables,
405411
$input,
406412
$runFixIds,
407-
$onlyUpdateDatabase
413+
$onlyUpdateDatabase,
414+
$runLpFix
408415
);
409-
410-
$currentVersion = $versionItem;
411-
$output->writeln("<comment>End database migration</comment>");
416+
$output->writeln("<comment>Run fixes value: $runFixIds</comment>");
417+
$output->writeln("<comment>End database migration of version: $currentVersion</comment>");
418+
$output->writeln("----------------------------------------------------------------");
412419
$output->writeln("----------------------------------------------------------------");
420+
$currentVersion = $versionItem;
413421
} else {
414422
$currentVersion = $versionItem;
415423
$output->writeln("<comment>Skip migration from version: </comment><info>$currentVersion</info><comment> to version </comment><info>$versionItem ");
@@ -486,15 +494,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
486494
/**
487495
* Starts a migration
488496
*
489-
* @param array $courseList
490-
* @param string $path
491-
* @param string $toVersion
492-
* @param bool $dryRun
497+
* @param array $courseList
498+
* @param string $path
499+
* @param string $toVersion
500+
* @param bool $dryRun
493501
* @param OutputInterface $output
494-
* @param bool $removeUnusedTables
495-
* @param InputInterface $mainInput
496-
* @param bool $runFixIds
497-
* @param bool $onlyUpdateDatabase
502+
* @param bool $removeUnusedTables
503+
* @param InputInterface $mainInput
504+
* @param bool $runFixIds
505+
* @param bool $onlyUpdateDatabase
506+
* @param bool $runLpFix
498507
*
499508
* @return bool
500509
* @throws \Exception
@@ -508,7 +517,8 @@ public function startMigration(
508517
$removeUnusedTables = false,
509518
InputInterface $mainInput,
510519
$runFixIds = true,
511-
$onlyUpdateDatabase = false
520+
$onlyUpdateDatabase = false,
521+
$runLpFix = false
512522
) {
513523
// Cleaning query list.
514524
$this->queryList = array();
@@ -614,7 +624,10 @@ public function startMigration(
614624
}
615625

616626
// Processing "update file" changes.
617-
if (isset($versionInfo['update_files']) && !empty($versionInfo['update_files']) && $onlyUpdateDatabase == false) {
627+
if (isset($versionInfo['update_files']) &&
628+
!empty($versionInfo['update_files']) &&
629+
$onlyUpdateDatabase == false
630+
) {
618631
$sqlToInstall = $installPath.$versionInfo['update_files'];
619632
if (is_file($sqlToInstall) && file_exists($sqlToInstall)) {
620633
if ($dryRun) {
@@ -650,27 +663,52 @@ public function startMigration(
650663
$this->getRootSys().'/main/inc/lib/custom_pages.class.php',
651664
$this->getRootSys().'/main/install/install.lib.php',
652665
$this->getRootSys().'/main/inc/lib/display.lib.php',
653-
$this->getRootSys().'/main/inc/lib/group_portal_manager.lib.php',
666+
//$this->getRootSys().'/main/inc/lib/group_portal_manager.lib.php',
654667
$this->getRootSys().'/main/inc/lib/model.lib.php',
655668
$this->getRootSys().'/main/inc/lib/events.lib.php',
656669
$this->getRootSys().'/main/inc/lib/extra_field.lib.php',
657670
$this->getRootSys().'/main/inc/lib/extra_field_value.lib.php',
658671
$this->getRootSys().'/main/inc/lib/urlmanager.lib.php',
659672
$this->getRootSys().'/main/inc/lib/usermanager.lib.php',
673+
674+
$this->getRootSys().'/vendor/sylius/translation/Model/TranslatableInterface.php',
675+
$this->getRootSys().'/vendor/sylius/attribute/Model/AttributeTranslationInterface.php',
676+
$this->getRootSys().'/vendor/sylius/resource/Model/TimestampableInterface.php',
677+
$this->getRootSys().'/vendor/sylius/translation/Model/AbstractTranslatable.php',
678+
$this->getRootSys().'/vendor/sylius/attribute/Model/AttributeInterface.php',
679+
$this->getRootSys().'/vendor/sylius/attribute/Model/Attribute.php',
660680
$this->getRootSys().'/src/Chamilo/CoreBundle/Entity/ExtraField.php',
661-
$this->getRootSys().'/src/Chamilo/CoreBundle/Entity/ExtraFieldOptions.php'
681+
$this->getRootSys().'/src/Chamilo/CoreBundle/Entity/ExtraFieldOptions.php',
662682
];
663683

664684
if ($runFixIds) {
665685
foreach ($filesToLoad as $file) {
666-
require_once $file;
686+
if (file_exists($file)) {
687+
require_once $file;
688+
}
667689
}
668690

669691
$output->writeln("<comment>Run fixIds function </info>");
670692
fixIds($em);
693+
} else {
694+
$output->writeln("<comment>fixIds NOT run</info>");
695+
}
696+
697+
if ($runLpFix) {
698+
foreach ($filesToLoad as $file) {
699+
if (file_exists($file)) {
700+
require_once $file;
701+
}
702+
703+
}
704+
705+
$output->writeln("<comment>Run fixLpId function </info>");
706+
fixLpId($conn, true);
707+
} else {
708+
$output->writeln("<comment>fixLpId NOT run</info>");
671709
}
672710

673-
if (method_exists('fixPostGroupIds') &&
711+
if (function_exists('fixPostGroupIds') &&
674712
$versionInfo['migrations_yml'] == 'V111.yml'
675713
) {
676714
foreach ($filesToLoad as $file) {
@@ -681,14 +719,12 @@ public function startMigration(
681719
} else {
682720
$output->writeln("<comment>Not found function: fixPostGroupIds</info>");
683721
}
684-
685722
} catch (\Exception $e) {
686723
$output->write(sprintf('<error>Migration failed. Error %s</error>', $e->getMessage()));
687724

688725
throw $e;
689726
}
690727

691-
692728
return false;
693729
}
694730

src/Chash/Command/Installation/UpgradeDatabaseCommand.php

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
203203
}
204204
}
205205

206-
$lastItem = count($versionsToRun);
207206
$counter = 0;
208-
$runFixIds = false;
209207
foreach ($versionsToRun as $versionItem => $versionInfo) {
210-
if ($lastItem == $counter) {
208+
$runFixIds = false;
209+
$runLpFix = false;
210+
211+
if ($versionItem === '1.10.0') {
211212
$runFixIds = true;
212213
}
213214

215+
if ($versionItem === '1.11.0') {
216+
$runLpFix = true;
217+
}
218+
214219
if (isset($versionInfo['require_update']) && $versionInfo['require_update'] == true) {
215220
$output->writeln("----------------------------------------------------------------");
216221
$output->writeln("<comment>Starting migration from version: </comment><info>$currentVersion</info><comment> to version </comment><info>$versionItem ");
@@ -227,10 +232,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
227232
$input,
228233
$runFixIds,
229234
$onlyUpdateDatabase = true,
230-
$rootSys
235+
$rootSys,
236+
$runLpFix
231237
);
232238
$currentVersion = $versionItem;
233-
$output->writeln("<comment>End database migration</comment>");
239+
$output->writeln("<comment>Run fixes value: $runFixIds</comment>");
240+
$output->writeln("<comment>End database migration of version: $currentVersion</comment>");
234241
$output->writeln("----------------------------------------------------------------");
235242
} else {
236243
$currentVersion = $versionItem;
@@ -269,7 +276,8 @@ public function startMigration(
269276
InputInterface $mainInput,
270277
$runFixIds = true,
271278
$onlyUpdateDatabase = false,
272-
$rootSys = ''
279+
$rootSys = '',
280+
$runLpFix = false
273281
) {
274282
// Cleaning query list.
275283
$this->queryList = array();
@@ -357,33 +365,62 @@ public function startMigration(
357365
}
358366
}
359367

368+
$filesToLoad = [
369+
$this->getRootSys().'/main/inc/lib/database.constants.inc.php',
370+
$this->getRootSys().'/main/inc/lib/system/session.class.php',
371+
$this->getRootSys().'/main/inc/lib/chamilo_session.class.php',
372+
$this->getRootSys().'/main/inc/lib/api.lib.php',
373+
$this->getRootSys().'/main/inc/lib/database.lib.php',
374+
$this->getRootSys().'/main/inc/lib/custom_pages.class.php',
375+
$this->getRootSys().'/main/install/install.lib.php',
376+
$this->getRootSys().'/main/inc/lib/display.lib.php',
377+
//$this->getRootSys().'/main/inc/lib/group_portal_manager.lib.php',
378+
$this->getRootSys().'/main/inc/lib/model.lib.php',
379+
$this->getRootSys().'/main/inc/lib/events.lib.php',
380+
$this->getRootSys().'/main/inc/lib/extra_field.lib.php',
381+
$this->getRootSys().'/main/inc/lib/extra_field_value.lib.php',
382+
$this->getRootSys().'/main/inc/lib/urlmanager.lib.php',
383+
$this->getRootSys().'/main/inc/lib/usermanager.lib.php',
384+
385+
$this->getRootSys().'/vendor/sylius/translation/Model/TranslatableInterface.php',
386+
$this->getRootSys().'/vendor/sylius/attribute/Model/AttributeTranslationInterface.php',
387+
$this->getRootSys().'/vendor/sylius/resource/Model/TimestampableInterface.php',
388+
$this->getRootSys().'/vendor/sylius/translation/Model/AbstractTranslatable.php',
389+
$this->getRootSys().'/vendor/sylius/attribute/Model/AttributeInterface.php',
390+
$this->getRootSys().'/vendor/sylius/attribute/Model/Attribute.php',
391+
392+
$this->getRootSys().'/src/Chamilo/CoreBundle/Entity/ExtraField.php',
393+
$this->getRootSys().'/src/Chamilo/CoreBundle/Entity/ExtraFieldOptions.php',
394+
];
395+
360396
if ($runFixIds) {
361-
require_once $this->getRootSys().'/main/inc/lib/database.constants.inc.php';
362-
require_once $this->getRootSys().'/main/inc/lib/system/session.class.php';
363-
require_once $this->getRootSys().'/main/inc/lib/chamilo_session.class.php';
364-
require_once $this->getRootSys().'/main/inc/lib/api.lib.php';
365-
require_once $this->getRootSys().'/main/inc/lib/database.lib.php';
366-
require_once $this->getRootSys().'/main/inc/lib/custom_pages.class.php';
367-
require_once $this->getRootSys().'/main/install/install.lib.php';
368-
require_once $this->getRootSys().'/main/inc/lib/display.lib.php';
369-
require_once $this->getRootSys().'/main/inc/lib/group_portal_manager.lib.php';
370-
require_once $this->getRootSys().'/main/inc/lib/model.lib.php';
371-
require_once $this->getRootSys().'/main/inc/lib/events.lib.php';
372-
require_once $this->getRootSys().'/main/inc/lib/extra_field.lib.php';
373-
require_once $this->getRootSys().'/main/inc/lib/extra_field_value.lib.php';
374-
require_once $this->getRootSys().'/main/inc/lib/urlmanager.lib.php';
375-
require_once $this->getRootSys().'/main/inc/lib/usermanager.lib.php';
376-
require_once $this->getRootSys().'/src/Chamilo/CoreBundle/Entity/ExtraField.php';
377-
require_once $this->getRootSys().'/src/Chamilo/CoreBundle/Entity/ExtraFieldOptions.php';
397+
foreach ($filesToLoad as $file) {
398+
if (file_exists($file)) {
399+
require_once $file;
400+
}
401+
}
402+
$output->writeln("<comment>Run fixIds function </info>");
378403
fixIds($em);
379404
}
405+
406+
if ($runLpFix) {
407+
foreach ($filesToLoad as $file) {
408+
if (file_exists($file)) {
409+
require_once $file;
410+
}
411+
}
412+
413+
$output->writeln("<comment>Run fixLpId function </info>");
414+
fixLpId($em->getConnection(), true);
415+
} else {
416+
$output->writeln("<comment>fixLpId NOT run</info>");
417+
}
380418
} catch (\Exception $e) {
381419
$output->write(sprintf('<error>Migration failed. Error %s</error>', $e->getMessage()));
382420

383421
throw $e;
384422
}
385423

386-
387424
return false;
388425
}
389426

0 commit comments

Comments
 (0)