public function onBeforeUpdate() { /** @var $model \Mindy\Orm\TreeModel */ $model = $this->getModel(); // Случай когда обнулен slug, например из админки if (empty($model->{$this->name})) { $model->{$this->name} = Meta::cleanString($model->{$this->source}); } // if remove parent (parent is null) if (!$model->parent) { if (strpos($model->{$this->name}, '/') === false) { $url = Meta::cleanString($model->{$this->name}); } else { if ($model->{$this->name}) { $slugs = explode('/', $model->{$this->name}); $url = end($slugs); } else { $url = Meta::cleanString($model->{$this->source}); } } } else { $parentUrl = $model->parent->{$this->name}; $slugs = explode('/', $model->{$this->name}); $url = $parentUrl . '/' . end($slugs); } $url = ltrim($url, '/'); if ($this->unique) { $url = $this->uniqueUrl($url, 0, $model->pk); } $model->setAttribute($this->name, $url); $schema = ConnectionManager::getDb()->getSchema(); $model->tree()->filter(['lft__gt' => $model->getOldAttribute('lft'), 'rgt__lt' => $model->getOldAttribute('rgt'), 'root' => $model->getOldAttribute('root')])->update([$this->name => new Expression("REPLACE(" . $schema->quoteColumnName($this->name) . ", :from, :to)", [':from' => $model->getOldAttribute($this->name), ':to' => $url])]); }
public function onBeforeUpdate() { /** @var $model \Mindy\Orm\TreeModel */ $model = $this->getModel(); // Случай когда обнулен slug, например из админки if (empty($model->{$this->name})) { $this->value = Meta::cleanString($model->{$this->source}); } if ($this->unique) { $this->value = $this->uniqueUrl($this->value, 0, $model->pk); } $model->setAttribute($this->name, $this->value); }