Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit c7387fc

Browse files
author
Charles Ma
committed
BUG: fixed bug #151 Now always check if the item exits
1 parent a535a3c commit c7387fc

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

core/AppController.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,29 +152,28 @@ public function preDispatch()
152152
$cookieData = $this->getRequest()->getCookie('recentItems'.$this->userSession->Dao->user_id);
153153
$this->view->recentItems = array();
154154
if(isset($cookieData) && file_exists(BASE_PATH.'/core/configs/database.local.ini')) //check if midas installed
155-
{
156-
$this->view->recentItems = unserialize($cookieData);
157-
$check = $this->_getParam('checkRecentItem');
158-
// check if recent items exit (every 5 minutes)
159-
if(isset($check) || !isset($user->Dao->lastAction) || strtotime($user->Dao->lastAction) < strtotime("-5 minute"))
155+
{
156+
$modelLoad = new MIDAS_ModelLoader();
157+
$itemModel = $modelLoad->loadModel('Item');
158+
$tmpRecentItems = unserialize($cookieData);
159+
$recentItems = array();
160+
if(!empty($tmpRecentItems) && is_array($tmpRecentItems))
160161
{
161-
$modelLoad = new MIDAS_ModelLoader();
162-
$itemModel = $modelLoad->loadModel('Item');
163-
foreach($this->view->recentItems as $key => $t)
164-
{
165-
if(!is_array($t))
166-
{
167-
unset($this->view->recentItems[$key]);
168-
continue;
169-
}
170-
$item = $itemModel->load($t['item_id']);
171-
if($item == false)
172-
{
173-
unset($this->view->recentItems[$key]);
174-
}
175-
}
176-
setcookie('recentItems'.$this->userSession->Dao->getKey(), serialize($this->view->recentItems), time() + 60 * 60 * 24 * 30, '/'); //30 days
162+
foreach($tmpRecentItems as $key => $t)
163+
{
164+
if(is_numeric($t))
165+
{
166+
$item = $itemModel->load($t);
167+
if($item !== false)
168+
{
169+
$recentItems[] = $item->toArray();
170+
}
171+
}
172+
}
177173
}
174+
175+
$this->view->recentItems = $recentItems;
176+
$check = $this->_getParam('checkRecentItem');
178177
}
179178
$user->Dao->lastAction = date('c');
180179
}

core/controllers/ItemController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function viewAction()
139139
$i = 0;
140140
foreach($tmp as $key => $t)
141141
{
142-
if($t['item_id'] == $itemDao->getKey())
142+
if($t == $itemDao->getKey() || !is_numeric($t))
143143
{
144144
unset($tmp[$key]);
145145
continue;
@@ -151,9 +151,7 @@ function viewAction()
151151
}
152152
}
153153
$recentItems = array_reverse($tmp);
154-
$itemDaoArray['item_id'] = $itemDao->getKey();
155-
$itemDaoArray['name'] = $itemDao->getName();
156-
$recentItems[] = $itemDaoArray;
154+
$recentItems[] = $itemDao->getKey();
157155

158156
setcookie('recentItems'.$this->userSession->Dao->getKey(), serialize($recentItems), time() + 60 * 60 * 24 * 30, '/'); //30 days
159157
}

core/layouts/layout.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ echo $this->doctype()
216216
{
217217
if(is_array($item))
218218
{
219-
echo "<li onclick=\"location.replace('{$this->webroot}/item/{$item['item_id']}');\" class='recentItem' title='". str_replace("'", '"', $item['name'])." | todo'><a href='{$this->webroot}/item/{$item['item_id']}'>".$this->slicename($item['name'],20)."</a></li>";
219+
echo "<li onclick=\"location.replace('{$this->webroot}/item/{$item['item_id']}');\" class='recentItem' title='". str_replace("'", '"', $item['name'])."'><a href='{$this->webroot}/item/{$item['item_id']}'>".$this->slicename($item['name'],20)."</a></li>";
220220
}
221221
}
222222
echo '</ul>';

0 commit comments

Comments
 (0)