public function up() { if (!class_exists('URLify')) { throw new Exception('URLify class not found - please run composer update!'); } $this->addColumn('space', 'url', $this->string(45)); $this->createIndex('url-unique', 'space', 'url', true); $rows = (new Query())->select("*")->from('space')->all(); foreach ($rows as $row) { $url = \humhub\modules\space\components\UrlValidator::autogenerateUniqueSpaceUrl($row['name']); $this->updateSilent('space', ['url' => $url], ['id' => $row['id']]); } }
/** * @inheritdoc */ public function beforeSave($insert) { if ($insert) { $this->url = UrlValidator::autogenerateUniqueSpaceUrl($this->name); } if ($this->url == '') { $this->url = new \yii\db\Expression('NULL'); } else { $this->url = mb_strtolower($this->url); } return parent::beforeSave($insert); }