/** * Reset the migration. * * @param Migration $migration */ public function reset(Migration $migration) { $this->input->read($migration); foreach ($migration->getFields() as $field) { if ($field = $this->fields->findBySlugAndNamespace($field['slug'], $field['namespace'])) { $this->fields->delete($field); } } }
/** * Run the seeder. */ public function run() { if ($type = $this->types->findBySlug('default_posts')) { $this->types->delete($type); } /* @var TypeInterface $type */ $type = $this->types->truncate()->create(['en' => ['name' => 'Default', 'description' => 'A simple post type.'], 'slug' => 'default', 'theme_layout' => 'theme::layouts/default.twig', 'layout' => '{{ post.content|raw }}']); $stream = $type->getEntryStream(); $this->assignments->create(['stream' => $stream, 'field' => $this->fields->findBySlugAndNamespace('content', 'posts')]); }
/** * Run the seeder. */ public function run() { if ($type = $this->types->findBySlug('default_pages')) { $this->types->delete($type); } /* @var TypeInterface $type */ $type = $this->types->truncate()->create(['en' => ['name' => 'Default', 'description' => 'A simple page type.'], 'slug' => 'default', 'handler' => 'anomaly.extension.default_page_handler', 'theme_layout' => 'theme::layouts/default.twig', 'layout' => '<h1>{{ page.title }}</h1> {{ page.content|raw }}']); $stream = $type->getEntryStream(); $this->assignments->create(['stream' => $stream, 'field' => $this->fields->findBySlugAndNamespace('content', 'pages')]); }
/** * Handle the command. * * @param RollbackFields $command */ public function handle(RollbackFields $command) { $migration = $command->getMigration(); $addon = $migration->getAddon(); $namespace = $migration->getNamespace(); foreach ($migration->getFields() as $slug => $field) { $namespace = array_get($field, 'namespace', $namespace ?: ($addon ? $addon->getSlug() : null)); if ($field = $this->fields->findBySlugAndNamespace($slug, $namespace)) { $this->fields->delete($field); } } }
/** * Reset the migration. * * @param Migration $migration */ public function reset(Migration $migration) { $this->input->read($migration); if (!($stream = $migration->getStream())) { return; } $assignments = $migration->getAssignments(); $stream = $this->streams->findBySlugAndNamespace(array_get($stream, 'slug'), array_get($stream, 'namespace')); if (!$stream) { return; } foreach ($assignments as $assignment) { /* * If there is no field to be * found then the assignment * needs to be cleaned out. * * @var FieldInterface */ if (!($field = $this->fields->findBySlugAndNamespace($assignment['field'], $stream->getNamespace()))) { continue; } $assignment['field'] = $field; $assignment['stream'] = $stream; /* * Check if the field is already * assigned to the stream and * then go ahead and delete. */ if ($assignment = $this->assignments->findByStreamAndField($stream, $field)) { $this->assignments->delete($assignment); } } }
/** * Handle the command. * * @param FieldRepositoryInterface $fields * @param StreamRepositoryInterface $streams * @param AssignmentRepositoryInterface $assignments */ public function handle(FieldRepositoryInterface $fields, StreamRepositoryInterface $streams, AssignmentRepositoryInterface $assignments) { $addon = $this->migration->getAddon(); $stream = $this->migration->getStream(); $namespace = array_get($stream, 'namespace', $this->migration->getNamespace()); $slug = array_get($stream, 'slug', $addon ? $addon->getSlug() : null); $stream = $streams->findBySlugAndNamespace($slug, $namespace); foreach ($this->migration->getAssignments() as $field => $assignment) { if (is_numeric($field)) { $field = $assignment; } if ($stream && ($field = $fields->findBySlugAndNamespace($field, $namespace))) { if ($assignment = $assignments->findByStreamAndField($stream, $field)) { $assignments->delete($assignment); } } } $assignments->cleanup(); }
/** * Handle the command. * * @param MigrateFields $command * @return bool */ public function handle(MigrateFields $command) { $migration = $command->getMigration(); /* @var Addon $addon */ $addon = $migration->getAddon(); $fields = $migration->getFields(); $namespace = $migration->getNamespace(); foreach ($fields as $slug => $field) { if (is_string($field)) { $field = ['type' => $field]; } $field['slug'] = $slug; $field['type'] = array_get($field, 'type'); $field['namespace'] = array_get($field, 'namespace', $namespace ?: ($addon ? $addon->getSlug() : null)); /** * If the name exists in the base array * then move it to the translated array * for the default locale. */ if ($name = array_pull($field, 'name')) { $field = array_add($field, config('app.fallback_locale') . '.name', $name); } /** * If the name is not set then make one * based on a standardized pattern. */ if (!array_get($field, config('app.fallback_locale') . '.name')) { $field = array_add($field, config('app.fallback_locale') . '.name', $addon ? $addon->getNamespace("field.{$slug}.name") : null); } /** * If the instructions exists in the base array * then move it to the translated array * for the default locale. */ if ($instructions = array_pull($field, 'instructions')) { $field = array_add($field, config('app.fallback_locale') . '.instructions', $instructions); } /** * If the instructions is not set then make one * based on a standardized pattern. */ if (!array_get($field, config('app.fallback_locale') . '.instructions')) { $field = array_add($field, config('app.fallback_locale') . '.instructions', $addon ? $addon->getNamespace("field.{$slug}.instructions") : null); } /** * If the placeholder exists in the base array * then move it to the translated array * for the default locale. */ if ($placeholder = array_pull($field, 'placeholder')) { $field = array_add($field, config('app.fallback_locale') . '.placeholder', $placeholder); } /** * If the placeholder is not set then make one * based on a standardized pattern. */ if (!array_get($field, config('app.fallback_locale') . '.placeholder')) { $field = array_add($field, config('app.fallback_locale') . '.placeholder', $addon ? $addon->getNamespace("field.{$slug}.placeholder") : null); } /** * If the warning exists in the base array * then move it to the translated array * for the default locale. */ if ($warning = array_pull($field, 'warning')) { $field = array_add($field, config('app.fallback_locale') . '.warning', $warning); } /** * If the instructions is not set then make one * based on a standardized pattern. */ if (!array_get($field, config('app.fallback_locale') . '.warning')) { $field = array_add($field, config('app.fallback_locale') . '.warning', $addon ? $addon->getNamespace("field.{$slug}.warning") : null); } // Only create if it does not exist already. if (!($entry = $this->fields->findBySlugAndNamespace($field['slug'], $field['namespace']))) { $this->fields->create($field); } else { $this->fields->save($entry->fill($field)); } } return true; }
/** * Handle the command. * * @param MigrateAssignments $command */ public function handle(MigrateAssignments $command) { $migration = $command->getMigration(); $stream = $migration->getStream(); $fields = $migration->getAssignments(); $namespace = $migration->getNamespace(); if (!$fields) { return; } $addon = $migration->getAddon(); $stream = $this->streams->findBySlugAndNamespace(array_get($stream, 'slug'), array_get($stream, 'namespace', $namespace ?: ($addon ? $addon->getSlug() : null))); foreach ($fields as $field => $assignment) { if (is_numeric($field)) { $field = $assignment; $assignment = []; } if (!is_array($assignment)) { throw new \Exception('The assignment must be an array or field_slug value.'); } /** * If the label exists in the base array * then move it to the translated array * for the default locale. */ if ($label = array_pull($assignment, 'label')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.label', $label); } /** * If the label is not set then make one * based on a standardized pattern. */ if (!array_get($assignment, config('app.fallback_locale') . '.label')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.label', $addon ? $addon->getNamespace("field.{$field}.label.{$stream->getSlug()}") : null); } /** * If the instructions exists in the base array * then move it to the translated array * for the default locale. */ if ($instructions = array_pull($assignment, 'instructions')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.instructions', $instructions); } /** * If the instructions is not set then make one * based on a standardized pattern. */ if (!array_get($assignment, config('app.fallback_locale') . '.instructions')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.instructions', $addon ? $addon->getNamespace("field.{$field}.instructions.{$stream->getSlug()}") : null); } /** * If the placeholder exists in the base array * then move it to the translated array * for the default locale. */ if ($placeholder = array_pull($assignment, 'placeholder')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.placeholder', $placeholder); } /** * If the placeholder is not set then make one * based on a standardized pattern. */ if (!array_get($assignment, config('app.fallback_locale') . '.placeholder')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.placeholder', $addon ? $addon->getNamespace("field.{$field}.placeholder.{$stream->getSlug()}") : null); } /** * If the warning exists in the base array * then move it to the translated array * for the default locale. */ if ($warning = array_pull($assignment, 'warning')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.warning', $warning); } /** * If the instructions is not set then make one * based on a standardized pattern. */ if (!array_get($assignment, config('app.fallback_locale') . '.warning')) { $assignment = array_add($assignment, config('app.fallback_locale') . '.warning', $addon ? $addon->getNamespace("field.{$field}.warning.{$stream->getSlug()}") : null); } $field = $this->fields->findBySlugAndNamespace($field, $stream->getNamespace()); if ($field) { $this->assignments->create(array_merge($assignment, compact('field', 'stream'))); } } }