Implements check for duplicate default categories
This commit is contained in:
committed by
Frédéric Guillot
parent
e488fdd154
commit
7283bfaef6
@@ -137,17 +137,13 @@ class CategoryModel extends Base
|
|||||||
public function createDefaultCategories($project_id)
|
public function createDefaultCategories($project_id)
|
||||||
{
|
{
|
||||||
$results = array();
|
$results = array();
|
||||||
$categories = explode(',', $this->configModel->get('project_categories'));
|
$categories = array_unique(explode_csv_field($this->configModel->get('project_categories')));
|
||||||
|
|
||||||
foreach ($categories as $category) {
|
foreach ($categories as $category) {
|
||||||
$category = trim($category);
|
$results[] = $this->db->table(self::TABLE)->insert(array(
|
||||||
|
'project_id' => $project_id,
|
||||||
if (! empty($category)) {
|
'name' => $category,
|
||||||
$results[] = $this->db->table(self::TABLE)->insert(array(
|
));
|
||||||
'project_id' => $project_id,
|
|
||||||
'name' => $category,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return in_array(false, $results, true);
|
return in_array(false, $results, true);
|
||||||
|
|||||||
@@ -156,7 +156,8 @@ class CategoryModelTest extends Base
|
|||||||
$categoryModel = new CategoryModel($this->container);
|
$categoryModel = new CategoryModel($this->container);
|
||||||
$configModel = new ConfigModel($this->container);
|
$configModel = new ConfigModel($this->container);
|
||||||
|
|
||||||
$this->assertTrue($configModel->save(array('project_categories' => 'C1, C2, C3')));
|
// Custom categories: spaces should be trimed, no empty and no duplicates
|
||||||
|
$this->assertTrue($configModel->save(array('project_categories' => 'C1, C2, C2 , C3, C1, ')));
|
||||||
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
|
$this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
|
||||||
$this->assertTrue($categoryModel->createDefaultCategories(1));
|
$this->assertTrue($categoryModel->createDefaultCategories(1));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user