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 "
Removing the settings_current:
" . PHP_EOL;
if (empty($duplicatedCurrent)) {
echo "No results";
} else {
foreach ($duplicatedCurrent as $settingCurrent) {
echo vsprintf(
"variable = '%s' subkey = '%s' access_url = '%s'
" . PHP_EOL,
[$settingCurrent->getVariable(), $settingCurrent->getSubkey(), $settingCurrent->getAccessUrl()]
);
$entityManager->remove($settingCurrent);
}
}
echo "
Removing the settings_options:
" . PHP_EOL;
if (empty($duplicatedOptions)) {
echo "No results";
} else {
foreach ($duplicatedOptions as $settingOption) {
echo vsprintf(
"variable = '%s' value = '%s'
" . PHP_EOL,
[$settingOption->getVariable(), $settingOption->getValue()]
);
$entityManager->remove($settingOption);
}
}
$entityManager->flush();