Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
chamilo-lms/tests/scripts/fix_duplicate_settings.php

93 lines
2.3 KiB

<?php
/* For license terms, see /license.txt */
/**
* Remove the current_settings duplicates from migration 1.9.x to 1.10.x
*/
//exit;
require_once __DIR__.'/../../main/inc/global.inc.php';
//api_protect_admin_script();
$entityManager = Database::getManager();
$settingsCurrentRepo = $entityManager->getRepository('ChamiloCoreBundle:SettingsCurrent');
$settingsOptionsRepo = $entityManager->getRepository('ChamiloCoreBundle:SettingsOptions');
$settingsCurrent = $settingsCurrentRepo->findBy([], ['id' => 'ASC']);
$cleanList = [];
$duplicatedCurrent = [];
foreach ($settingsCurrent as $settingCurrent) {
$key = vsprintf(
"%s-%s-%s",
[
$settingCurrent->getVariable(),
$settingCurrent->getSubkey(),
$settingCurrent->getAccessUrl()
]
);
if (!array_key_exists($key, $cleanList)) {
$cleanList[$key] = $settingCurrent;
continue;
}
$duplicatedCurrent[] = $settingCurrent;
}
$settingsOptions = $settingsOptionsRepo->findBy([], ['id' => 'ASC']);
$cleanList = [];
$duplicatedOptions = [];
foreach ($settingsOptions as $settingOption) {
$key = vsprintf(
"%s-%s",
[
$settingOption->getVariable(),
$settingOption->getValue()
]
);
if (!array_key_exists($key, $cleanList)) {
$cleanList[$key] = $settingOption;
continue;
}
$duplicatedOptions[] = $settingOption;
}
// View
echo "<br>Removing the settings_current:<br>" . PHP_EOL;
if (empty($duplicatedCurrent)) {
echo "No results";
} else {
foreach ($duplicatedCurrent as $settingCurrent) {
echo vsprintf(
"variable = '%s' subkey = '%s' access_url = '%s'<br>" . PHP_EOL,
[$settingCurrent->getVariable(), $settingCurrent->getSubkey(), $settingCurrent->getAccessUrl()]
);
$entityManager->remove($settingCurrent);
}
}
echo "<br>Removing the settings_options:<br>" . PHP_EOL;
if (empty($duplicatedOptions)) {
echo "No results";
} else {
foreach ($duplicatedOptions as $settingOption) {
echo vsprintf(
"variable = '%s' value = '%s'<br>" . PHP_EOL,
[$settingOption->getVariable(), $settingOption->getValue()]
);
$entityManager->remove($settingOption);
}
}
$entityManager->flush();