mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Convert to User entity for usr.lastModel field
This commit is contained in:
@@ -113,7 +113,6 @@ class patch_390alpha2a implements patchInterface
|
||||
$user->setGuest(!!$row['invite']);
|
||||
$user->setJob($row['fonction']);
|
||||
$user->setLastConnection(new \DateTime($row['last_conn']));
|
||||
$user->setLastModel($row['lastModel']);
|
||||
$user->setLastName($row['usr_nom']);
|
||||
$user->setLdapCreated(!!$row['ldap_created']);
|
||||
try {
|
||||
@@ -170,6 +169,49 @@ class patch_390alpha2a implements patchInterface
|
||||
$em->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets last_model from usr table.
|
||||
*/
|
||||
private function updateLastModels(EntityManager $em, $conn)
|
||||
{
|
||||
$sql = "SELECT lastModel, usr_login
|
||||
FROM usr
|
||||
WHERE lastModel > 0";
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$n = 0;
|
||||
|
||||
$repository = $em->getRepository('Alchemy\Phrasea\Model\Entities\User');
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$user = $repository->findOneByLogin($row['usr_login']);
|
||||
if (null === $lastModel = $repository->findOneByLogin($row['usr_login'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (false === $lastModel->isTemplate()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->setLastModel($row['lastModel']);
|
||||
$em->persist($user);
|
||||
|
||||
$n++;
|
||||
|
||||
if ($n % 100 === 0) {
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets model from usr table.
|
||||
*/
|
||||
@@ -209,6 +251,8 @@ class patch_390alpha2a implements patchInterface
|
||||
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
|
||||
$this->updateLastModels($em, $conn);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user