Пример #1
0
 /**
  * Starts a migration
  *
  * @param array $courseList
  * @param string $path
  * @param string $toVersion
  * @param bool $dryRun
  * @param OutputInterface $output
  * @param bool $removeUnusedTables
  * @param InputInterface $mainInput
  *
  * @return bool
  * @throws \Exception
  */
 public function startMigration($courseList, $path, $toVersion, $dryRun, OutputInterface $output, $removeUnusedTables = false, InputInterface $mainInput, $runFixIds = true, $onlyUpdateDatabase = false)
 {
     // Cleaning query list.
     $this->queryList = array();
     // Main DB connection.
     $conn = $this->getConnection($mainInput);
     $_configuration = $this->getHelper('configuration')->getConfiguration($path);
     $versionInfo = $this->getAvailableVersionInfo($toVersion);
     $installPath = $this->getInstallationFolder() . $toVersion . '/';
     // Filling sqlList array with "pre" db changes.
     if (isset($versionInfo['pre']) && !empty($versionInfo['pre'])) {
         $sqlToInstall = $installPath . $versionInfo['pre'];
         $this->fillQueryList($sqlToInstall, $output, 'pre');
         // Processing sql query list depending of the section (course, main, user).
         $this->processQueryList($courseList, $output, $path, $toVersion, $dryRun, 'pre');
     }
     try {
         if (isset($versionInfo['hook_to_doctrine_version'])) {
             // Doctrine migrations:
             $em = $this->setDoctrineSettings($this->getHelperSet());
             $output->writeln('');
             $output->writeln("<comment>You have to select 'yes' for the 'Chamilo Migrations'<comment>");
             // Setting migrations temporal ymls
             $tempFolder = '/tmp';
             require_once $_configuration['root_sys'] . 'app/Migrations/AbstractMigrationChamilo.php';
             $migrationsFolder = $tempFolder . '/Migrations/';
             $fs = new Filesystem();
             if (!$fs->exists($migrationsFolder)) {
                 $fs->mkdir($migrationsFolder);
             }
             $migrations = array('name' => 'Chamilo Migrations', 'migrations_namespace' => $versionInfo['migrations_namespace'], 'table_name' => 'version', 'migrations_directory' => $versionInfo['migrations_directory']);
             $dumper = new Dumper();
             $yaml = $dumper->dump($migrations, 1);
             $file = $migrationsFolder . $versionInfo['migrations_yml'];
             if (file_exists($file)) {
                 unlink($file);
             }
             file_put_contents($file, $yaml);
             //$command = $this->getApplication()->find('migrations:migrate');
             $command = new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand();
             // Creates the helper set
             $helperSet = \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($em);
             $dialog = $this->getHelperSet()->get('dialog');
             $helperSet->set($dialog, 'dialog');
             $command->setHelperSet($helperSet);
             $arguments = array('--configuration' => $file, '--dry-run' => $dryRun, 'version' => $versionInfo['hook_to_doctrine_version']);
             $output->writeln("<comment>Executing migrations:migrate " . $versionInfo['hook_to_doctrine_version'] . " --configuration=" . $file . "<comment>");
             $input = new ArrayInput($arguments);
             $command->run($input, $output);
             $output->writeln("<comment>Migration ended successfully</comment>");
         }
         // Processing "db" changes.
         if (isset($versionInfo['update_db']) && !empty($versionInfo['update_db'])) {
             $sqlToInstall = $installPath . $versionInfo['update_db'];
             if (is_file($sqlToInstall) && file_exists($sqlToInstall)) {
                 if ($dryRun) {
                     $output->writeln("<comment>File to be executed but not fired because of dry-run option: <info>'{$sqlToInstall}'</info>");
                 } else {
                     $output->writeln("<comment>Executing update db: <info>'{$sqlToInstall}'</info>");
                 }
                 require $sqlToInstall;
                 if (!empty($update)) {
                     $update($_configuration, $conn, $courseList, $dryRun, $output, $this, $removeUnusedTables);
                 }
             } else {
                 $output->writeln(sprintf("File doesn't exist: '<info>%s</info>'", $sqlToInstall));
             }
         }
         // Processing "update file" changes.
         if (isset($versionInfo['update_files']) && !empty($versionInfo['update_files']) && $onlyUpdateDatabase == false) {
             $sqlToInstall = $installPath . $versionInfo['update_files'];
             if (is_file($sqlToInstall) && file_exists($sqlToInstall)) {
                 if ($dryRun) {
                     $output->writeln("<comment>Files to be executed but dry-run is on: <info>'{$sqlToInstall}'</info>");
                 } else {
                     $output->writeln("<comment>Executing update files: <info>'{$sqlToInstall}'</info>");
                     require $sqlToInstall;
                     if (!empty($updateFiles)) {
                         $updateFiles($_configuration, $conn, $courseList, $dryRun, $output, $this);
                     }
                 }
             } else {
                 $output->writeln(sprintf("File doesn't exist: '<info>%s</info>'", $sqlToInstall));
             }
         }
         // Filling sqlList array with "post" db changes.
         if (isset($versionInfo['post']) && !empty($versionInfo['post'])) {
             $sqlToInstall = $installPath . $versionInfo['post'];
             $this->fillQueryList($sqlToInstall, $output, 'post');
             // Processing sql query list depending of the section.
             $this->processQueryList($courseList, $output, $path, $toVersion, $dryRun, 'post');
         }
         if ($runFixIds) {
             require_once $this->getRootSys() . '/main/inc/lib/database.constants.inc.php';
             require_once $this->getRootSys() . '/main/inc/lib/system/session.class.php';
             require_once $this->getRootSys() . '/main/inc/lib/chamilo_session.class.php';
             require_once $this->getRootSys() . '/main/inc/lib/api.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/database.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/custom_pages.class.php';
             require_once $this->getRootSys() . '/main/install/install.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/display.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/group_portal_manager.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/model.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/events.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/extra_field.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/extra_field_value.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/urlmanager.lib.php';
             require_once $this->getRootSys() . '/main/inc/lib/usermanager.lib.php';
             require_once $this->getRootSys() . '/src/Chamilo/CoreBundle/Entity/ExtraField.php';
             require_once $this->getRootSys() . '/src/Chamilo/CoreBundle/Entity/ExtraFieldOptions.php';
             fixIds($em);
         }
     } catch (\Exception $e) {
         $output->write(sprintf('<error>Migration failed. Error %s</error>', $e->getMessage()));
         throw $e;
     }
     return false;
 }
Пример #2
0
     Database::query("ALTER TABLE c_quiz_answer MODIFY COLUMN hotspot_type varchar(40) default NULL");
     Database::query("ALTER TABLE c_tool MODIFY COLUMN target varchar(20) NOT NULL default '_self'");
     Database::query("ALTER TABLE c_link MODIFY COLUMN on_homepage char(10) NOT NULL default '0'");
     Database::query("ALTER TABLE c_blog_rating MODIFY COLUMN rating_type char(40) NOT NULL default 'post'");
     Database::query("ALTER TABLE c_survey MODIFY COLUMN anonymous char(10) NOT NULL default '0'");
     Database::query("ALTER TABLE c_document MODIFY COLUMN filetype char(10) NOT NULL default 'file'");
     Database::query("ALTER TABLE c_student_publication MODIFY COLUMN filetype char(10) NOT NULL default 'file'");
     echo '<a class="btn btn-default" href="javascript:void(0)" id="details_button">' . get_lang('Details') . '</a><br />';
     echo '<div id="details" style="display:none">';
     // Migrate using the migration files located in:
     // src/Chamilo/CoreBundle/Migrations/Schema/V110
     $result = migrate(110, $manager);
     echo '</div>';
     if ($result) {
         error_log('Migrations files were executed.');
         fixIds($manager);
         include 'update-files-1.9.0-1.10.0.inc.php';
         // Only updates the configuration.inc.php with the new version
         include 'update-configuration.inc.php';
         $configurationFiles = array('mail.conf.php', 'profile.conf.php', 'course_info.conf.php', 'add_course.conf.php', 'events.conf.php', 'auth.conf.php', 'portfolio.conf.php');
         foreach ($configurationFiles as $file) {
             if (file_exists(api_get_path(SYS_CODE_PATH) . 'inc/conf/' . $file)) {
                 copy(api_get_path(SYS_CODE_PATH) . 'inc/conf/' . $file, api_get_path(CONFIGURATION_PATH) . $file);
             }
         }
     } else {
         error_log('There was an error during running migrations. Check error.log');
     }
     break;
 default:
     break;