public function handle()
{
- $this->call('backup:run');
+ //$this->call('backup:run');
$this->_handleMagicFolder([$this, '_resetSlug']);
$this->call('cache:clear');
}
}
$class = get_class($model);
$all = $class::all();
+ if ($class !== 'App\Models\Page') {
+ return;
+ }
+ $locale = $this->argument('locale');
foreach ($all as $instance) {
- /** @var CubistMagicAbstractModel $instance */
- echo $instance->getAttribute('slug');
+ $instance->setLocale($locale);
+ /** @var CubistMagicTranslatableModel $instance */
+ $translations = $instance->getTranslations('slug');
+ $reset = !isset($translations[$locale]) || !$translations[$locale] || $instance->getAttribute('name') === 'home';
+ if (!$reset) {
+ foreach ($translations as $loc => $translation) {
+ if ($loc === $locale) {
+ continue;
+ }
+ if ($translation === $translations[$locale]) {
+ $reset = true;
+ break;
+ }
+ }
+ }
+
+ if (!$reset) {
+ echo 'skip ' . $translations[$locale] . "\n";
+ continue;
+ }
+
+ $new = $instance->getSlugOrTitleAttribute(true);
+ if (!$new) {
+ continue;
+ }
+ echo 'reset "' . $translations[$locale] . '" -> ' . $new . "\n";
+ $instance->setTranslation('slug', $locale, $new);
+ $instance->save();
}
}
}
}
// The slug is created automatically from the "title" field if no slug exists.
- public function getSlugOrTitleAttribute()
+ public function getSlugOrTitleAttribute($reset = false)
{
+ if ($this->getAttribute('name') === 'home') {
+ return 'home';
+ }
foreach ($this->_slugFields as $item) {
$components = explode('+', $item);
$slug = [];
foreach ($components as $component) {
- $v = $this->getAttribute($component);
+ if ($reset && $component === 'slug') {
+ continue;
+ }
+ $v = $this->getAttributeValue($component);
if ($v) {
- $slug[] = $v;
+ $slug[$component] = $v;
}
}
if (count($slug) > 0) {
return Str::slug(implode('-', $slug));
}
}
- return Str::slug($this->getAttribute('id'));
+ if ($reset) {
+ return false;
+ }
+ return Str::slug($this->getAttributeValue('id'));
}
public function getOption($key, $default = null)