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

Commit 2d3e9f3

Browse files
author
Charles Ma
committed
BUG: fixed bug #142 Folders and items shouldn t have the same name and same parent
1 parent a017f20 commit 2d3e9f3

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

core/controllers/FolderController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ function editAction()
5454
if($this->_request->isPost())
5555
{
5656
$name = $this->_getParam('name');
57+
58+
// Check ifa folder with the same name already exists for the same parent
59+
if($this->Folder->getFolderExists($name, $folder->getParent()))
60+
{
61+
throw new Zend_Exception('This name is already used');
62+
}
63+
5764
$description = $this->_getParam('description');
5865
$teaser = $this->_getParam('teaser');
5966

core/models/base/FolderModelBase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ abstract function addItem($folder, $item);
5454
abstract function move($folder, $parent);
5555
abstract function removeItem($folder, $item);
5656
abstract function policyCheck($folderDao, $userDao = null, $policy = 0);
57-
abstract function getFolderExists($name, $description);
57+
abstract function getFolderExists($name, $parent);
5858
abstract function getByUuid($uuid);
5959
abstract function getRoot($folder);
6060

@@ -109,9 +109,9 @@ function createFolder($name, $description, $parent)
109109
}
110110

111111
// Check ifa folder with the same name already exists for the same parent
112-
if($this->getFolderExists($name, $parentId))
112+
if($this->getFolderExists($name, $parent))
113113
{
114-
$existingfolder = $this->getFolderExists($name, $parentId);
114+
$existingfolder = $this->getFolderExists($name, $parent);
115115
return $existingfolder;
116116
}
117117

core/models/pdo/FolderModel.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,12 @@ public function move($folder, $parent)
372372
{
373373
throw new Zend_Exception("Error parameter.");
374374
}
375+
376+
// Check ifa folder with the same name already exists for the same parent
377+
if($this->getFolderExists($folder->getName(), $parent))
378+
{
379+
throw new Zend_Exception('This name is already used');
380+
}
375381

376382
$node_id = $folder->getKey();
377383
$node_pos_left = $folder->getLeftIndice();
@@ -516,13 +522,13 @@ function getUser($folder)
516522
}
517523

518524
/** Returns ifa folder exists based on the name and description */
519-
function getFolderExists($name, $parentid)
525+
function getFolderExists($name, $parent)
520526
{
521527
$dao = $this->initDao('Folder', $this->database->fetchRow($this->database->select()
522528
->setIntegrityCheck(false)
523529
->from('folder')
524530
->where('name = ?', $name)
525-
->where('parent_id = ?', $parentid)));
531+
->where('parent_id = ?', $parent->getKey())));
526532
return $dao;
527533
}
528534

@@ -630,13 +636,26 @@ function getItemsFiltered($folder, $userDao = null, $policy = 0)
630636
$policyArray[$row['item_id']] = $row['policy'];
631637
}
632638
}
639+
640+
$listNamesArray = array();
641+
633642
foreach($rowset as $keyRow => $row)
634643
{
635644
if(isset($policyArray[$row['item_id']]))
636645
{
637646
$tmpDao = $this->initDao('Item', $row);
638647
$tmpDao->policy = $policyArray[$row['item_id']];
639648
$tmpDao->parent_id = $row['folder_id'];
649+
650+
if(isset($listNamesArray[$tmpDao->getName()]))
651+
{
652+
$listNamesArray[$tmpDao->getName()]++;
653+
$tmpDao->setName($tmpDao->getName().' ('.$listNamesArray[$tmpDao->getName()].')');
654+
}
655+
else
656+
{
657+
$listNamesArray[$tmpDao->getName()] = 0;
658+
}
640659
$return[] = $tmpDao;
641660
unset($policyArray[$row['item_id']]);
642661
}

0 commit comments

Comments
 (0)