/** * Guess the assignment names. * * @param Migration $migration */ public function guess(Migration $migration) { /** * If we don't have any addon then * we can't automate anything. * * @var Addon $addon */ if (!($addon = $migration->getAddon())) { return; } $stream = $migration->getStream(); $stream = $this->streams->findBySlugAndNamespace(array_get($stream, 'slug'), array_get($stream, 'namespace')); if (!$stream) { return; } $locale = $this->config->get('app.fallback_locale'); $assignments = $migration->getAssignments(); foreach ($assignments as &$assignment) { foreach (['label', 'warning', 'instructions', 'placeholder'] as $key) { if (is_null(array_get($assignment, $locale . '.' . $key))) { $assignment = array_add($assignment, $locale . '.' . $key, $addon->getNamespace('field.' . array_get($assignment, 'field') . '.' . $key . '.' . $stream->getSlug())); } } } $migration->setAssignments($assignments); }
/** * Execute the console command. * * @param Search $search * @param IndexManager $manager * @param StreamRepositoryInterface $streams */ public function fire(Search $search, IndexManager $manager, StreamRepositoryInterface $streams, EntryRepositoryInterface $repository) { $stream = $this->argument('stream'); list($namespace, $slug) = explode('.', $stream); if (!($stream = $streams->findBySlugAndNamespace($slug, $namespace))) { $this->error('Stream [' . $this->argument('stream') . '] could not be found.'); return; } /* @var EntryModel $model */ $repository->setModel($model = $stream->getEntryModel()); /** * If the stream is empty we can't * really index it. */ if (!($entry = $repository->first())) { $this->error('Stream [' . $this->argument('stream') . '] is empty.'); } /** * If the stream does not have a valid * search configuration then we don't * know how to insert it's entries. */ if (!($config = $this->dispatch(new GetConfig($entry)))) { $this->error('Stream [' . $this->argument('stream') . '] does not have a search configuration.'); } $this->info('Deleting ' . $this->argument('stream')); $search->search('stream', $stream)->delete(); $this->info('Rebuilding ' . $this->argument('stream')); $this->output->progressStart($repository->count()); foreach ($repository->all() as $entry) { $manager->insert($entry, $config); $this->output->progressAdvance(); } $this->output->progressFinish(); }
/** * Return a form to edit the variables. * * @param StreamRepositoryInterface $streams * @param VariableFormBuilder $form * @param $id * @return \Symfony\Component\HttpFoundation\Response */ public function edit(StreamRepositoryInterface $streams, VariableFormBuilder $form, $id) { /* @var StreamInterface $group */ $group = $streams->find($id); $entry = $group->getEntryModel()->firstOrNew([]); return $form->setModel($group->getEntryModelName())->render($entry); }
/** * Create a new field assignment. * * @param AssignmentFormBuilder $builder * @param DiskRepositoryInterface $disks * @param FieldRepositoryInterface $fields * @param StreamRepositoryInterface $streams * @param $id * @param $field * @return \Symfony\Component\HttpFoundation\Response */ public function create(AssignmentFormBuilder $builder, DiskRepositoryInterface $disks, FieldRepositoryInterface $fields, StreamRepositoryInterface $streams, $id, $field) { /* @var DiskInterface $disk */ $disk = $disks->find($id); $stream = $streams->findBySlugAndNamespace($disk->getSlug(), 'files'); return $builder->setOption('redirect', 'admin/files/disks/assignments/' . $id)->setField($fields->find($field))->setStream($stream)->render(); }
/** * Handle the command. * * @param StreamRepositoryInterface $streams */ public function handle(StreamRepositoryInterface $streams) { if (!$this->type->isForceDeleting()) { return; } $streams->delete($streams->findBySlugAndNamespace($this->type->getSlug() . '_posts', 'posts')); }
/** * Execute the console command. * * @param StreamRepositoryInterface $streams */ public function fire(StreamRepositoryInterface $streams) { /* @var StreamInterface $stream */ foreach ($streams->all() as $stream) { if ($streams->save($stream)) { $this->info($stream->getEntryModelName() . ' compiled successfully.'); } } }
/** * Handle the command. * * @param StreamSchema $schema */ public function handle(StreamSchema $schema, StreamRepositoryInterface $streams) { /* @var StreamInterface $stream */ $stream = $streams->find($this->stream->getId()); $schema->renameTable($stream, $this->stream); if ($stream->isTranslatable()) { $schema->renameTranslationsTable($stream, $this->stream); } }
/** * Handle the command. * * @param StreamRepositoryInterface $streams * @param TypeRepositoryInterface $types * @param Repository $config */ public function handle(StreamRepositoryInterface $streams, TypeRepositoryInterface $types, Repository $config) { /* @var TypeInterface $type */ $type = $types->find($this->type->getId()); /* @var StreamInterface $stream */ $stream = $type->getEntryStream(); $stream->fill([$config->get('app.fallback_locale') => ['name' => $this->type->getName(), 'description' => $this->type->getDescription()], 'slug' => $this->type->getSlug() . '_posts']); $streams->save($stream); }
/** * Execute the console command. * * @param FieldRepositoryInterface $fields * @param StreamRepositoryInterface $streams * @param AssignmentRepositoryInterface $assignments */ public function fire(FieldRepositoryInterface $fields, StreamRepositoryInterface $streams, AssignmentRepositoryInterface $assignments) { $streams->cleanup(); $this->info('Abandoned streams deleted successfully.'); $fields->cleanup(); $this->info('Abandoned fields deleted successfully.'); $assignments->cleanup(); $this->info('Abandoned assignments deleted successfully.'); }
/** * Reset the migration. * * @param Migration $migration */ public function reset(Migration $migration) { $this->input->read($migration); if (!($stream = $migration->getStream())) { return; } if ($stream = $this->streams->findBySlugAndNamespace($stream['slug'], $stream['namespace'])) { $this->streams->delete($stream); } }
/** * Handle the options. * * @param RelationshipFieldType $fieldType * @param FieldRepositoryInterface $fields * @param StreamRepositoryInterface $streams * @return array */ public function handle(RelationshipFieldType $fieldType, FieldRepositoryInterface $fields, StreamRepositoryInterface $streams) { $stream = array_get($fieldType->getConfig(), 'stream'); $unlocked = array_get($fieldType->getConfig(), 'unlocked'); $namespace = array_get($fieldType->getConfig(), 'namespace'); $fields = $fields->findAllByNamespace($namespace); if ($stream && ($stream = $streams->findBySlugAndNamespace($stream, $namespace))) { $fields = $fields->assignedTo($stream); } if ($unlocked) { $fields = $fields->unlocked(); } $fieldType->setOptions(array_combine($fields->lists('id')->toArray(), $fields->lists('name')->toArray())); }
/** * Handle the command. * * @param MigrateStream $command * @return StreamInterface */ public function handle(MigrateStream $command) { $migration = $command->getMigration(); $stream = $migration->getStream(); if (!$stream) { return null; } if (is_string($stream)) { $stream = ['slug' => $stream]; } $addon = $migration->getAddon(); $stream['slug'] = array_get($stream, 'slug', $addon ? $addon->getSlug() : null); $stream['namespace'] = array_get($stream, 'namespace', $addon ? $addon->getSlug() : null); if ($this->streams->findBySlugAndNamespace($stream['slug'], $stream['namespace'])) { return null; } /** * If the name exists in the base array * then move it to the translated array * for the default locale. */ if ($name = array_pull($stream, 'name')) { $stream = array_add($stream, config('app.fallback_locale') . '.name', $name); } /** * If the name is not set then make one * based on a standardized pattern. */ if (!array_get($stream, config('app.fallback_locale') . '.name')) { $stream = array_add($stream, config('app.fallback_locale') . '.name', $addon ? $addon->getNamespace("stream.{$stream['slug']}.name") : null); } /** * If the description exists in the base array * then move it to the translated array * for the default locale. */ if ($description = array_pull($stream, 'description')) { $stream = array_add($stream, config('app.fallback_locale') . '.description', $description); } /** * If the name is not set then make one * based on a standardized pattern. */ if (!array_get($stream, config('app.fallback_locale') . '.description')) { $stream = array_add($stream, config('app.fallback_locale') . '.description', $addon ? $addon->getNamespace("stream.{$stream['slug']}.description") : 'foo'); } // Create the stream. return $this->streams->create($stream); }
/** * Export all entries. * * @param $addon * @param $namespace * @param $stream * @return \Illuminate\Http\RedirectResponse */ public function export($addon, $namespace, $stream) { $addon = $this->addons->get($addon); /* @var StreamInterface $stream */ $stream = $this->streams->findBySlugAndNamespace($stream, $namespace); /* * Resolve the model and set * it on the repository. */ $this->repository->setModel($this->container->make($stream->getEntryModelName())); if (!$this->authorizer->authorize($addon->getNamespace($stream->getSlug() . '.export'))) { abort(403); } $headers = ['Content-Disposition' => 'attachment; filename=' . $stream->getSlug() . '.csv', 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Content-type' => 'text/csv', 'Pragma' => 'public', 'Expires' => '0']; $callback = function () { $output = fopen('php://output', 'w'); foreach ($this->repository->all() as $k => $entry) { if ($k == 0) { fputcsv($output, array_keys($entry->toArray())); } fputcsv($output, $entry->toArray()); } fclose($output); }; return $this->response->stream($callback, 200, $headers); }
/** * 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 RollbackStream $command */ public function handle(RollbackStream $command) { $migration = $command->getMigration(); $stream = $migration->getStream(); if (!$stream) { return; } if (is_string($stream)) { $stream = ['slug' => $stream]; } $addon = $migration->getAddon(); $stream['slug'] = array_get($stream, 'slug', $addon ? $addon->getSlug() : null); $stream['namespace'] = array_get($stream, 'namespace', $addon ? $addon->getSlug() : null); if ($stream = $this->streams->findBySlugAndNamespace($stream['slug'], $stream['namespace'])) { $this->streams->delete($stream); } }
/** * 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(); }
/** * Toggle the boolean value. * * @param StreamRepositoryInterface $streams * @param Container $container * @throws \Exception */ public function toggle(StreamRepositoryInterface $streams, Container $container) { /** * First fine the stream by * it's slug and namespace. */ if (!($stream = $streams->findBySlugAndNamespace($slug = $this->request->get('stream'), $namespace = $this->request->get('namespace')))) { throw new \Exception("Stream not found with slug [{$slug}] in namespace [{$namespace}]."); } /** * Grab the model from the stream. */ $model = $stream->getEntryModel(); /* @var EntryRepositoryInterface $repository */ $repository = $container->make(EntryRepositoryInterface::class); /** * Set the model manually since * it's a generic repository. */ $repository->setModel($model); /** * Try finding the entry with * our generic repository. */ if (!($entry = $repository->find($id = $this->request->get('entry')))) { throw new \Exception("Entry [{$id}] not found in stream [{$slug}] in namespace [{$namespace}]."); } /** * Make the request change to the entry * based on the state submitted. */ $entry->{$this->request->get('field')} = $this->request->get('state'); /** * Save and don't return a thing. */ $repository->save($entry); }
/** * Handle the command. * * @param StreamRepositoryInterface $streams */ public function handle(StreamRepositoryInterface $manager, Repository $config) { $manager->create([$config->get('app.fallback_locale') => ['name' => $this->type->getName(), 'description' => $this->type->getDescription()], 'namespace' => 'partials', 'slug' => $this->type->getSlug() . '_partials', 'translatable' => true, 'locked' => false]); }
/** * Execute the console command. * * @param StreamRepositoryInterface $streams */ public function fire(StreamRepositoryInterface $streams) { $streams->destroy($this->argument('namespace')); $this->info('[' . $this->argument('namespace') . '] namespace destroyed.'); }
/** * Handle the command. * * @param StreamRepositoryInterface $streams * @param Repository $config */ public function handle(StreamRepositoryInterface $streams, Repository $config) { $streams->create([$config->get('app.fallback_locale') => ['name' => $this->folder->getName(), 'description' => $this->folder->getDescription()], 'namespace' => 'files', 'slug' => $this->folder->getSlug(), 'translatable' => true, 'locked' => false]); }
/** * Handle the command. * * @param StreamRepositoryInterface $streams * @return \Anomaly\Streams\Platform\Stream\Contract\StreamInterface|null */ public function handle(StreamRepositoryInterface $streams) { return $streams->findAllByNamespace($this->namespace); }
/** * Handle the command. * * @param StreamRepositoryInterface $streams */ public function handle(StreamRepositoryInterface $streams) { $streams->delete($streams->findBySlugAndNamespace($this->type->getSlug() . '_partials', 'partials')); }
/** * Handle the command. * * @param StreamRepositoryInterface $streams * @return \Anomaly\Streams\Platform\Stream\Contract\StreamInterface|null */ public function handle(StreamRepositoryInterface $streams) { return $streams->findBySlugAndNamespace($this->folder->getSlug(), 'files'); }
/** * 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'))); } } }
/** * Handle the command. * * @param StreamRepositoryInterface $streams */ public function handle(StreamRepositoryInterface $streams) { $streams->delete($streams->findBySlugAndNamespace($this->folder->getSlug() . '_files', 'files')); }
/** * Return the form for a new field. * * @param FieldFormBuilder $form * @param StreamRepositoryInterface $streams * @param FieldTypeCollection $fieldTypes * @return \Symfony\Component\HttpFoundation\Response */ public function create(FieldFormBuilder $form, StreamRepositoryInterface $streams, FieldTypeCollection $fieldTypes) { $form->setStream($streams->findBySlugAndNamespace('posts', 'posts'))->setFieldType($fieldTypes->get($_GET['field_type'])); return $form->render(); }
/** * Handle the command. * * @param AssignmentRepositoryInterface $assignments * @param StreamRepositoryInterface $streams * @param FieldRepositoryInterface $fields */ public function handle(AssignmentRepositoryInterface $assignments, StreamRepositoryInterface $streams, FieldRepositoryInterface $fields) { $assignments->cleanup(); $streams->cleanup(); $fields->cleanup(); }
/** * Handle the command. * * @param StreamRepositoryInterface $streams * @return \Anomaly\Streams\Platform\Stream\Contract\StreamInterface|null */ public function handle(StreamRepositoryInterface $streams) { return $streams->findBySlugAndNamespace($this->type->getSlug() . '_pages', 'pages'); }
/** * Create a new VariableRepository instance. * * @param VariableCollection $variables * @param StreamRepositoryInterface $streams */ public function __construct(VariableCollection $variables, StreamRepositoryInterface $streams) { $this->variables = $variables->make($streams->findAllByNamespace('variables')->all()); }