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.
45 lines
1.1 KiB
45 lines
1.1 KiB
|
6 years ago
|
<?php
|
||
|
|
/* For licensing terms, see /license.txt */
|
||
|
|
|
||
|
|
use Chamilo\CoreBundle\Entity\ExtraField;
|
||
|
|
|
||
|
|
$plugin = MigrationMoodlePlugin::create();
|
||
|
|
|
||
|
|
try {
|
||
|
|
removeExtraField();
|
||
|
|
|
||
|
|
$plugin->uninstallHook();
|
||
|
|
} catch (Exception $exception) {
|
||
|
|
$message = sprintf(
|
||
|
|
$plugin->get_lang('UninstallError'),
|
||
|
|
$exception->getMessage()
|
||
|
|
);
|
||
|
|
|
||
|
|
echo Display::return_message($message, 'error');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @throws \Doctrine\ORM\ORMException
|
||
|
|
* @throws \Doctrine\ORM\OptimisticLockException
|
||
|
|
*/
|
||
|
|
function removeExtraField()
|
||
|
|
{
|
||
|
|
$em = Database::getManager();
|
||
|
|
|
||
|
|
/** @var ExtraField $extraField */
|
||
|
|
$extraField = $em
|
||
|
|
->getRepository('ChamiloCoreBundle:ExtraField')
|
||
|
|
->findOneBy(['variable' => 'moodle_password', 'extraFieldType' => ExtraField::USER_FIELD_TYPE]);
|
||
|
|
|
||
|
|
if (empty($extraField)) {
|
||
|
|
throw new Exception('User extra field not found.');
|
||
|
|
}
|
||
|
|
|
||
|
|
$em
|
||
|
|
->createQuery('DELETE FROM ChamiloCoreBundle:ExtraFieldValues efv WHERE efv.field = :field')
|
||
|
|
->execute(['field' => $extraField]);
|
||
|
|
|
||
|
|
$em->remove($extraField);
|
||
|
|
$em->flush();
|
||
|
|
}
|