Fix migration 1.11.x to 2.0, avoid double settings, fix session error

pull/2715/head
Julio Montoya 6 years ago
parent 80b8c0e8c2
commit 8bcaafc49a
  1. 23
      main/install/install.lib.php
  2. 7
      src/CoreBundle/Framework/Container.php
  3. 76
      src/CoreBundle/Migrations/Schema/V200/Version20.php
  4. 2
      src/CoreBundle/Settings/DisplaySettingsSchema.php
  5. 2
      src/CoreBundle/Settings/PlatformSettingsSchema.php
  6. 95
      src/SettingsBundle/Manager/SettingsManager.php

@ -3168,8 +3168,9 @@ function installPages($container)
/**
* @param SymfonyContainer $container
* @param EntityManager $manager
* @param bool $upgrade
*/
function installSchemas($container, $manager)
function installSchemas($container, $manager, $upgrade = false)
{
$settingsManager = Container::getSettingsManager();
@ -3190,23 +3191,29 @@ function installSchemas($container, $manager)
$toolChain = $container->get('chamilo_course.tool_chain');
$toolChain->createTools($manager);
// Installing schemas (filling settings_current table)
$settingsManager->installSchemas($accessUrl);
if ($upgrade) {
$settingsManager->updateSchemas($accessUrl);
} else {
// Installing schemas (filling settings_current table)
$settingsManager->installSchemas($accessUrl);
}
}
/**
* @param SymfonyContainer $container
*/
function updateWithContainer($container)
function upgradeWithContainer($container)
{
Container::setContainer($container);
Container::setLegacyServices($container);
Container::setLegacyServices($container, false);
error_log('setLegacyServices');
$manager = Database::getManager();
installGroups($container, $manager);
installSchemas($container, $manager);
error_log('installGroups');
installSchemas($container, $manager, true);
error_log('installSchemas');
installPages($container);
error_log('installPages');
}
/**

@ -396,7 +396,7 @@ class Container
/**
* @param ContainerInterface $container
*/
public static function setLegacyServices($container)
public static function setLegacyServices($container, $setSession = true)
{
\Database::setConnection($container->get('doctrine.dbal.default_connection'));
$em = $container->get('doctrine.orm.entity_manager');
@ -413,8 +413,9 @@ class Container
// Setting course tool chain (in order to create tools to a course)
\CourseManager::setToolList($container->get('chamilo_course.tool_chain'));
self::$session = $container->get('session');
if ($setSession) {
self::$session = $container->get('session');
}
// Setting legacy properties.
self::$dataDir = $container->get('kernel')->getDataDir();
self::$courseDir = $container->get('kernel')->getDataDir();

@ -298,6 +298,7 @@ class Version20 extends AbstractMigrationChamilo
'administratorName' => 'administrator_name',
'administratorTelephone' => 'administrator_phone',
'registration.soap.php.decode_utf8' => 'decode_utf8',
'show_toolshortcuts' => 'show_tool_shortcuts',
];
foreach ($settings as $oldSetting => $newSetting) {
@ -348,7 +349,6 @@ class Version20 extends AbstractMigrationChamilo
'show_administrator_data' => 'display',
'show_back_link_on_top_of_tree' => 'display',
'show_closed_courses' => 'display',
'show_different_course_language' => 'display',
'show_email_addresses' => 'display',
'show_empty_course_categories' => 'display',
'show_full_skill_name_on_skill_wheel' => 'skill',
@ -394,6 +394,78 @@ class Version20 extends AbstractMigrationChamilo
'server_type' => 'platform',
'show_official_code_whoisonline' => 'profile',
'show_terms_if_profile_completed' => 'ticket',
'enable_record_audio' => 'course',
'add_users_by_coach' => 'session',
'allow_captcha' => 'security',
'allow_coach_to_edit_course_session' => 'session',
'allow_delete_attendance' => 'attendance',
'allow_download_documents_by_api_key' => 'webservice',
'allow_email_editor' => 'editor',
'allow_message_tool' => 'message',
'allow_send_message_to_all_platform_users' => 'message',
'allow_personal_agenda' => 'agenda',
'allow_show_linkedin_url' => 'profile',
'allow_show_skype_account' => 'profile',
'allow_social_tool' => 'social',
'allow_students_to_create_groups_in_social' => 'social',
'allow_use_sub_language' => 'language',
'allow_user_course_subscription_by_course_admin' => 'course',
'allow_users_to_change_email_with_no_password' => 'profile',
'display_groups_forum_in_general_tool' => 'forum',
'documents_default_visibility_defined_in_course' => 'document',
'dropbox_allow_group' => 'dropbox',
'dropbox_allow_just_upload' => 'dropbox',
'dropbox_allow_mailing' => 'dropbox',
'dropbox_allow_overwrite' => 'dropbox',
'dropbox_allow_student_to_student' => 'dropbox',
'dropbox_hide_course_coach' => 'dropbox',
'dropbox_hide_general_coach' => 'dropbox',
'dropbox_max_filesize' => 'dropbox',
'email_alert_manager_on_new_quiz' => 'exercise',
'enable_webcam_clip' => 'document',
'enabled_support_pixlr' => 'editor',
'enabled_support_svg' => 'editor',
'enabled_text2audio' => 'document',
'extend_rights_for_coach' => 'session',
'extend_rights_for_coach_on_survey' => 'survey',
'hide_course_group_if_no_tools_available' => 'group',
'hide_dltt_markup' => 'language',
'if_file_exists_option' => 'document',
'language_priority_1' => 'language',
'language_priority_2' => 'language',
'language_priority_3' => 'language',
'language_priority_4' => 'language',
'lp_show_reduced_report' => 'course',
'message_max_upload_filesize' => 'message',
'messaging_allow_send_push_notification' => 'webservice',
'messaging_gdc_api_key' => 'webservice',
'messaging_gdc_project_number' => 'webservice',
'permanently_remove_deleted_files' => 'document',
'permissions_for_new_directories' => 'document',
'permissions_for_new_files' => 'document',
'platform_language' => 'language',
'registered' => 'platform',
'show_chat_folder' => 'chat',
'show_default_folders' => 'document',
'show_different_course_language' => 'language',
'show_documents_preview' => 'document',
'show_link_ticket_notification' => 'display',
'show_official_code_exercise_result_list' => 'exercise',
'show_users_folders' => 'document',
'split_users_upload_directory' => 'profile',
'students_download_folders' => 'document',
'students_export2pdf' => 'document',
'tool_visible_by_default_at_creation' => 'document',
'upload_extensions_blacklist' => 'document',
'upload_extensions_list_type' => 'document',
'upload_extensions_replace_by' => 'document',
'upload_extensions_skip' => 'document',
'upload_extensions_whitelist' => 'document',
'use_users_timezone' => 'profile',
'users_copy_files' => 'document',
'timezone' => 'platform',
'enable_profile_user_address_geolocalization' => 'profile',
'theme' => 'platform',
];
foreach ($settings as $variable => $category) {
@ -423,7 +495,7 @@ class Version20 extends AbstractMigrationChamilo
'facebook_description',
'ldap_description',
'openid_authentication',
//'platform_charset',
'platform_charset',
'shibboleth_description',
'sso_authentication',
'sso_authentication_domain',

@ -34,7 +34,6 @@ class DisplaySettingsSchema extends AbstractSettingsSchema
'show_number_of_courses' => 'false',
'show_empty_course_categories' => 'true',
'show_back_link_on_top_of_tree' => 'false',
'show_different_course_language' => 'true',
'display_categories_on_homepage' => 'false',
'show_closed_courses' => 'false',
'allow_students_to_browse_courses' => 'true',
@ -90,7 +89,6 @@ class DisplaySettingsSchema extends AbstractSettingsSchema
->add('show_empty_course_categories', YesNoType::class)
->add('show_back_link_on_top_of_tree', YesNoType::class)
->add('show_empty_course_categories', YesNoType::class)
->add('show_different_course_language', YesNoType::class)
->add('display_categories_on_homepage', YesNoType::class)
->add('show_closed_courses', YesNoType::class)
->add('allow_students_to_browse_courses', YesNoType::class)

@ -51,7 +51,6 @@ class PlatformSettingsSchema extends AbstractSettingsSchema
'keep_old_images_after_delete' => 'true',
'load_term_conditions_section' => 'login',
//'server_type' => 'prod', replaced by value in .env
'show_full_skill_name_on_skill_wheel' => 'false',
'show_tabs' => [],
'chamilo_database_version' => '2.0.0',
//
@ -155,7 +154,6 @@ class PlatformSettingsSchema extends AbstractSettingsSchema
],
]
)
->add('show_full_skill_name_on_skill_wheel', YesNoType::class)
->add(
'show_tabs',
ChoiceType::class,

@ -108,6 +108,24 @@ class SettingsManager implements SettingsManagerInterface
$this->url = $url;
}
/**
* @param AccessUrl $url
*/
public function updateSchemas(AccessUrl $url)
{
$this->url = $url;
$schemas = array_keys($this->getSchemas());
/**
* @var string
* @var \Sylius\Bundle\SettingsBundle\Schema\SchemaInterface $schema
*/
foreach ($schemas as $schema) {
$settings = $this->load($this->convertServiceToNameSpace($schema));
$this->update($settings);
}
}
/**
* @param AccessUrl $url
*/
@ -624,7 +642,7 @@ class SettingsManager implements SettingsManagerInterface
}
/**
* @param $name
* @param string $name
*
* @throws \InvalidArgumentException
*
@ -734,6 +752,77 @@ class SettingsManager implements SettingsManagerInterface
return $settings;
}
/**
* @param SettingsInterface $settings
*
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function update(SettingsInterface $settings)
{
$namespace = $settings->getSchemaAlias();
/** @var SchemaInterface $schema */
$schema = $this->schemaRegistry->get($settings->getSchemaAlias());
$settingsBuilder = new SettingsBuilder();
$schema->buildSettings($settingsBuilder);
$parameters = $settingsBuilder->resolve($settings->getParameters());
// Transform value. Example array to string using transformer. Example:
// 1. Setting "tool_visible_by_default_at_creation" it's a multiple select
// 2. Is defined as an array in class DocumentSettingsSchema
// 3. Add transformer for that variable "ArrayToIdentifierTransformer"
// 4. Here we recover the transformer and convert the array to string
foreach ($settingsBuilder->getTransformers() as $parameter => $transformer) {
if (array_key_exists($parameter, $parameters)) {
$parameters[$parameter] = $transformer->transform($parameters[$parameter]);
}
}
$settings->setParameters($parameters);
$persistedParameters = $this->repository->findBy(
['category' => $this->convertServiceToNameSpace($settings->getSchemaAlias())]
);
$persistedParametersMap = [];
/** @var SettingsCurrent $parameter */
foreach ($persistedParameters as $parameter) {
$persistedParametersMap[$parameter->getVariable()] = $parameter;
}
/** @var SettingsCurrent $url */
$url = $this->getUrl();
$simpleCategoryName = str_replace('chamilo_core.settings.', '', $namespace);
foreach ($parameters as $name => $value) {
if (isset($persistedParametersMap[$name])) {
$parameter = $persistedParametersMap[$name];
$parameter->setSelectedValue($value);
$parameter->setCategory($simpleCategoryName);
$this->manager->merge($parameter);
} else {
$parameter = new SettingsCurrent();
$parameter
->setVariable($name)
->setCategory($simpleCategoryName)
->setTitle($name)
->setSelectedValue($value)
->setUrl($url)
->setAccessUrlChangeable(1)
->setAccessUrlLocked(1)
;
/* @var $errors ConstraintViolationListInterface */
/*$errors = $this->validator->validate($parameter);
if (0 < $errors->count()) {
throw new ValidatorException($errors->get(0)->getMessage());
}*/
$this->manager->persist($parameter);
}
}
$this->manager->flush();
}
/**
* {@inheritdoc}
*
@ -775,7 +864,7 @@ class SettingsManager implements SettingsManagerInterface
new SettingsEvent($settings, $parameters)
);*/
/** @var \Chamilo\CoreBundle\Entity\SettingsCurrent $url */
/** @var SettingsCurrent $url */
$url = $this->getUrl();
$simpleCategoryName = str_replace('chamilo_core.settings.', '', $namespace);
@ -832,7 +921,7 @@ class SettingsManager implements SettingsManagerInterface
new SettingsEvent($settings)
);
/** @var \Chamilo\CoreBundle\Entity\SettingsCurrent $url */
/** @var SettingsCurrent $url */
$url = $event->getSettings()->getAccessUrl();
foreach ($parameters as $name => $value) {

Loading…
Cancel
Save