コード例 #1
0
 /**
  * Handle the command.
  *
  * @param AssignmentSchema $schema
  */
 public function handle(AssignmentSchema $schema, AssignmentRepositoryInterface $assignments)
 {
     $stream = $this->assignment->getStream();
     /* @var AssignmentInterface $assignment */
     $assignment = $assignments->find($this->assignment->getId());
     // If nothing is different then skip it.
     if ($assignment->isTranslatable() == $this->assignment->isTranslatable()) {
         return;
     }
     /*
      * If it's NOW translatable then move it from
      * the main table to the translations table.
      */
     if ($this->assignment->isTranslatable()) {
         $schema->dropColumn($stream->getEntryTableName(), $assignment->getFieldType(true));
         $schema->addColumn($stream->getEntryTranslationsTableName(), $assignment->getFieldType(true), $assignment);
     }
     /*
      * If it's NOT translatable then move it from
      * the translations table to the main table.
      */
     if (!$this->assignment->isTranslatable()) {
         $schema->dropColumn($stream->getEntryTranslationsTableName(), $assignment->getFieldType(true));
         $schema->addColumn($stream->getEntryTableName(), $assignment->getFieldType(true), $assignment);
     }
 }
コード例 #2
0
 /**
  * Return the translatable label.
  *
  * @param string $size
  * @return null|string
  */
 protected function translatableLabel($size = 'sm')
 {
     if ($this->object->isTranslatable()) {
         return '<span class="label label-info label-' . $size . '">' . trans('streams::assignment.translatable.name') . '</span>';
     }
     return null;
 }
コード例 #3
0
 /**
  * Handle the command.
  *
  * @param AssignmentSchema $schema
  */
 public function handle(AssignmentSchema $schema)
 {
     $stream = $this->assignment->getStream();
     $type = $this->assignment->getFieldType();
     if (!$this->assignment->isTranslatable()) {
         $table = $stream->getEntryTableName();
     } else {
         $table = $stream->getEntryTranslationsTableName();
     }
     $schema->updateColumn($table, $type, $this->assignment);
 }
コード例 #4
0
 /**
  * Handle the command.
  *
  * @param AssignmentSchema              $schema
  * @param AssignmentRepositoryInterface $assignments
  */
 public function handle(AssignmentSchema $schema, AssignmentRepositoryInterface $assignments)
 {
     $stream = $this->assignment->getStream();
     $type = $this->assignment->getFieldType(true);
     if (!$this->assignment->isTranslatable()) {
         $table = $stream->getEntryTableName();
     } else {
         $table = $stream->getEntryTranslationsTableName();
     }
     /* @var AssignmentInterface $assignment */
     $assignment = $assignments->find($this->assignment->getId());
     $assignment = clone $assignment;
     $schema->renameColumn($table, $type, $assignment);
 }
コード例 #5
0
 /**
  * @param Blueprint           $table
  * @param AssignmentInterface $assignment
  */
 public function addColumn(Blueprint $table, AssignmentInterface $assignment)
 {
     // Skip if the column already exists.
     if ($this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     /**
      * Add the column to the table.
      *
      * @var Blueprint|Fluent $column
      */
     $column = $table->{$this->fieldType->getColumnType()}($this->fieldType->getColumnName(), 11, array_get($this->fieldType->getConfig(), 'decimals', 2))->nullable(!$assignment->isTranslatable() ? !$assignment->isRequired() : true);
     if (!str_contains($this->fieldType->getColumnType(), ['text', 'blob'])) {
         $column->default(array_get($this->fieldType->getConfig(), 'default_value'));
     }
     // Mark the column unique if desired and not translatable.
     if ($assignment->isUnique() && !$assignment->isTranslatable()) {
         $table->unique($this->fieldType->getColumnName());
     }
 }
コード例 #6
0
 /**
  * Add the field type column.
  *
  * @param Blueprint           $table
  * @param AssignmentInterface $assignment
  */
 public function addColumn(Blueprint $table, AssignmentInterface $assignment)
 {
     // Skip if the column already exists.
     if ($this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName() . '_id')) {
         return;
     }
     $table->string($this->fieldType->getColumnName() . '_type')->nullable(!$assignment->isRequired());
     $table->integer($this->fieldType->getColumnName() . '_id')->nullable(!$assignment->isRequired());
     if ($assignment->isUnique() && $assignment->isTranslatable()) {
         $table->unique([$this->fieldType->getColumnName() . '_type', $this->fieldType->getColumnName() . '_id']);
     }
 }
コード例 #7
0
 /**
  * Update the field type column to the table.
  *
  * @param Blueprint           $table
  * @param AssignmentInterface $assignment
  */
 public function updateColumn(Blueprint $table, AssignmentInterface $assignment)
 {
     // Skip if no column type.
     if (!$this->fieldType->getColumnType()) {
         return;
     }
     // Skip if the column doesn't exists.
     if (!$this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     /**
      * Update the column to the table.
      *
      * @var Blueprint|Fluent $column
      */
     $column = call_user_func_array([$table, $this->fieldType->getColumnType()], array_filter([$this->fieldType->getColumnName(), $this->fieldType->getColumnLength()]));
     $column->nullable(!$assignment->isTranslatable() ? !$assignment->isRequired() : true)->change();
     if (!str_contains($this->fieldType->getColumnType(), ['text', 'blob'])) {
         $column->default(array_get($this->fieldType->getConfig(), 'default_value'));
     }
     /**
      * Mark the column unique if desired and not translatable.
      * Otherwise, drop the unique index.
      */
     $connection = $this->schema->getConnection();
     $manager = $connection->getDoctrineSchemaManager();
     $doctrine = $manager->listTableDetails($connection->getTablePrefix() . $table->getTable());
     // The unique index name.
     $unique = md5('unique_' . $this->fieldType->getColumnName());
     /**
      * If the assignment is unique and not translatable
      * and the table does not already have the given the
      * given table index then go ahead and add it.
      */
     if ($assignment->isUnique() && !$assignment->isTranslatable() && !$doctrine->hasIndex($unique)) {
         $table->unique($this->fieldType->getColumnName(), $unique);
     }
     /**
      * If the assignment is NOT unique and not translatable
      * and the table DOES have the given table index
      * then we need to remove.
      */
     if (!$assignment->isUnique() && !$assignment->isTranslatable() && $doctrine->hasIndex($unique)) {
         $column->dropIndex(md5('unique_' . $this->fieldType->getColumnName()));
     }
 }