Skip to content

Commit d407e6c

Browse files
committed
[spalenque] - #14274 * fix slug in component categories creation
1 parent 829a66e commit d407e6c

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

software/code/infrastructure/active_records/OpenStackComponentCategory.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,22 @@ protected function onBeforeWrite()
4646
$this->Order = $siblings_count + 1;
4747
}
4848

49-
$slug = strtolower($this->Name);
50-
$slug = preg_replace("/[^a-z0-9_\s-]/", "", $slug);
51-
$slug = preg_replace("/[\s-]+/", " ", $slug);
52-
$slug = preg_replace("/[\s_]/", "-", $slug);
53-
54-
$checkSlug = $slug;
55-
$counter = 0;
56-
while($slugExists = OpenStackComponentCategory::get()->filter('Slug', $checkSlug)->count()) {
57-
$counter++;
58-
$checkSlug = $slug . '-' . $counter;
59-
}
49+
if (empty($this->Slug)) {
50+
$slug = strtolower($this->Name);
51+
$slug = preg_replace("/[^a-z0-9_\s-]/", "", $slug);
52+
$slug = preg_replace("/[\s-]+/", " ", $slug);
53+
$slug = preg_replace("/[\s_]/", "-", $slug);
54+
55+
$checkSlug = $slug;
56+
$counter = 0;
57+
while ($slugExists = OpenStackComponentCategory::get()->exclude('ID', $this->ID)->filter('Slug', $checkSlug)->count()) {
58+
$counter++;
59+
$checkSlug = $slug . '-' . $counter;
60+
}
6061

61-
if($checkSlug) {
62-
$slug = $checkSlug;
62+
$this->Slug = $checkSlug;
6363
}
6464

65-
$this->Slug = $slug;
66-
6765
// if removed from a collection of subcategories we disable the category
6866
if (!$this->ParentCategoryID && $this->isChanged('ParentCategoryID')) {
6967
$this->Enabled = 0;

0 commit comments

Comments
 (0)