Skip to content

Commit

Permalink
Merge pull request #6683 from Quetzacoalt91/module-page-reuse-request
Browse files Browse the repository at this point in the history
Reuse SQL result for module history
  • Loading branch information
aleeks committed Oct 14, 2016
2 parents 8ed72d0 + 1dea609 commit c87d842
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/Adapter/Module/ModuleDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,26 @@ public function findByName($name)
$result['installed'] = 1;
$result['active'] = $this->isEnabled($name);
$result['active_on_mobile'] = (bool)($this->getDeviceStatus($name) & AddonListFilterDeviceStatus::DEVICE_MOBILE);
$lastAccessDate = '0000-00-00 00:00:00';

if (!is_null($this->entityManager)) {
$moduleID = (int)$result['id'];
$legacyContext = new LegacyContext();
$legacyContext = $legacyContext->getContext();
$employeeID = (int)$legacyContext->employee->id;
$moduleHistory = $this->entityManager->getRepository('PrestaShopBundle:ModuleHistory')
->findOneBy([
'idEmployee' => $employeeID,
'idModule' => $moduleID
]);

if (is_null($moduleHistory)) {
$lastAccessDate = '0000-00-00 00:00:00';
} else {
$lastAccessDate = $moduleHistory->getDateUpd()->format('Y-m-d H:i:s');

$qb = $this->entityManager->createQueryBuilder();
$qb->select('mh')
->from('PrestaShopBundle:ModuleHistory', 'mh', 'mh.idModule')
->where('mh.idEmployee = ?1')
->setParameter(1, $employeeID);
$query = $qb->getQuery();
$query->useResultCache(true);
$modulesHistory = $query->getResult();

if (array_key_exists($moduleID, $modulesHistory)) {
$lastAccessDate = $modulesHistory[$moduleID]->getDateUpd()->format('Y-m-d H:i:s');
}
} else {
$lastAccessDate = '0000-00-00 00:00:00';
}
$result['last_access_date'] = $lastAccessDate;

Expand Down

0 comments on commit c87d842

Please sign in to comment.