Permalink
Browse files

Fix object without pattern

Sorry, can't launch test myself atm.
  • Loading branch information...
1 parent 226e460 commit ac390076e5e2120519a7fc83e10177df02819f72 @Divi Divi committed Aug 16, 2012
Showing with 23 additions and 7 deletions.
  1. +23 −7 generator/lib/behavior/sluggable/SluggableBehavior.php
@@ -79,11 +79,11 @@ protected function getColumnSetter()
public function preSave($builder)
{
$const = $builder->getColumnConstant($this->getColumnForParameter('slug_column'));
- $script = "
-if (\$this->isColumnModified($const)";
$pattern = $this->getParameter('slug_pattern');
- if ($pattern && $this->getParameter('permanent') == 'false') {
- $script .= " || ";
+
+ if ($pattern && $this->getParameter('permanent') != 'true') {
+ $script = "
+if ((\$this->isColumnModified($const) || ";
$count = preg_match_all('{[a-zA-Z]+}', $pattern, $matches, PREG_PATTERN_ORDER);
foreach ($matches[0] as $key => $match) {
@@ -94,12 +94,28 @@ public function preSave($builder)
$columnConst = $builder->getColumnConstant($column);
$script .= "\$this->isColumnModified($columnConst)" . ($key < $count - 1 ? " || " : "");
}
+
+ $script .= ") && \$this->{$this->getColumnGetter()}()) {";
+ }
+ else {
+ $script .= "if (\$this->isColumnModified($const) && \$this->{$this->getColumnGetter()}()) {";
}
- $script .= " && \$this->{$this->getColumnGetter()}()) {
- \$this->{$this->getColumnSetter()}(\$this->makeSlugUnique(\$this->{$this->getColumnGetter()}()));
+
+ $script .= "
+ \$this->{$this->getColumnSetter()}(\$this->makeSlugUnique(\$this->{$this->getColumnGetter()}()));";
+
+ if (null == $pattern && $this->getParameter('permanent') != 'true') {
+ $script .= "
+} else {
+ \$this->{$this->getColumnSetter()}(\$this->createSlug());
+}";
+ }
+ else {
+ $script .= "
} elseif (!\$this->{$this->getColumnGetter()}()) {
\$this->{$this->getColumnSetter()}(\$this->createSlug());
}";
+ }
return $script;
}
@@ -292,7 +308,7 @@ protected function makeSlugUnique(\$slug, \$separator = '" . $this->getParameter
->count();
if (1 == \$count) {
- return $getter();
+ return \$this->$getter();
}";
}

0 comments on commit ac39007

Please sign in to comment.