Skip to content

Commit

Permalink
Move schema to the SCHEMA class.. Duh
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanThompson committed May 20, 2016
1 parent 9992b63 commit 31169e9
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 132 deletions.
70 changes: 70 additions & 0 deletions src/FilesFieldTypeSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php namespace Anomaly\FilesFieldType;

use Anomaly\Streams\Platform\Addon\FieldType\FieldType;
use Anomaly\Streams\Platform\Addon\FieldType\FieldTypeSchema;
use Anomaly\Streams\Platform\Assignment\Contract\AssignmentInterface;
use Illuminate\Database\Schema\Blueprint;

/**
* Class FilesFieldTypeSchema
*
* @link http://pyrocms.com/
* @author PyroCMS, Inc. <support@pyrocms.com>
* @author Ryan Thompson <ryan@pyrocms.com>
* @package Anomaly\FilesFieldType
*/
class FilesFieldTypeSchema extends FieldTypeSchema
{

/**
* Add the field type's pivot table.
*
* @param Blueprint $table
* @param AssignmentInterface $assignment
*/
public function addColumn(Blueprint $table, AssignmentInterface $assignment)
{
$table = $table->getTable() . '_' . $this->fieldType->getField();

$this->schema->dropIfExists($table);

$this->schema->create(
$table,
function (Blueprint $table) {

$table->integer('entry_id');
$table->integer('file_id');
$table->integer('sort_order')->nullable();

$table->primary(['entry_id', 'file_id']);
}
);
}

/**
* Rename the pivot table.
*
* @param Blueprint $table
* @param FieldType $from
*/
public function renameColumn(Blueprint $table, FieldType $from)
{
$this->schema->rename(
$table->getTable() . '_' . $from->getField(),
$table->getTable() . '_' . $this->fieldType->getField()
);
}

/**
* Drop the pivot table.
*
* @param Blueprint $table
*/
public function dropColumn(Blueprint $table)
{
$this->schema->dropIfExists(
$table->getTable() . '_' . $this->fieldType->getField()
);
}

}
15 changes: 0 additions & 15 deletions src/FilesFieldTypeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,4 @@ class FilesFieldTypeServiceProvider extends AddonServiceProvider
'streams/files-field_type/handle' => 'Anomaly\FilesFieldType\Http\Controller\UploadController@upload',
'streams/files-field_type/recent' => 'Anomaly\FilesFieldType\Http\Controller\UploadController@recent',
];

/**
* The addon listeners.
*
* @var array
*/
protected $listeners = [
'Anomaly\Streams\Platform\Assignment\Event\AssignmentWasCreated' => [
'Anomaly\FilesFieldType\Listener\CreatePivotTable'
],
'Anomaly\Streams\Platform\Assignment\Event\AssignmentWasDeleted' => [
'Anomaly\FilesFieldType\Listener\DropPivotTable'
]
];

}
65 changes: 0 additions & 65 deletions src/Listener/CreatePivotTable.php

This file was deleted.

52 changes: 0 additions & 52 deletions src/Listener/DropPivotTable.php

This file was deleted.

0 comments on commit 31169e9

Please sign in to comment.