Scripts - Updates an user when official code is not empty - refs BT#19505 (#4104)

* Scripts - Updates an user when official code is not empty - refs BT#19505

* Scripts - Improve update user when official code is not empty - refs BT#19505

Co-authored-by: Christian <christian1827@gmail.com>
pull/4133/head
christianbeeznest 4 years ago committed by GitHub
parent 2bbca44d00
commit e3980794fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      tests/scripts/update_users_by_officialcode.php

@ -0,0 +1,34 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Updates an user when official code is not empty
*
* If official_code is not null then
* Update password by username encrypted and username by official_code
* else
* nothing to do
*
*/
exit;
require __DIR__.'/../../main/inc/global.inc.php';
$dql = "SELECT u FROM ChamiloUserBundle:User u WHERE (u.officialCode is not null AND u.officialCode != '')";
$qb = Database::getManager()->createQuery($dql);
$users = $qb->execute();
if (count($users) > 0) {
$userManager = UserManager::getManager();
foreach ($users as $user) {
$loginName = $user->getOfficialCode();
$password = $user->getUsername();
echo 'Updating official_code "'.$user->getOfficialCode().'": username: '.$user->getUsername().'<br />';
$user
->setUsername($loginName)
->setPlainPassword($password)
;
$userManager->updateUser($user);
}
}
Loading…
Cancel
Save