From 3ac74928586e0c210d2d44a8b9055c1ec74c434f Mon Sep 17 00:00:00 2001 From: James Brooks Date: Fri, 12 Jul 2019 11:08:25 +0100 Subject: [PATCH] Remove old Tag commands, refactor migration etc --- app/Bus/Commands/Tag/ApplyTagCommand.php | 51 ------------ app/Bus/Commands/Tag/CreateTagCommand.php | 48 ----------- app/Bus/Commands/Tag/DeleteTagCommand.php | 41 ---------- app/Bus/Commands/Tag/UpdateTagCommand.php | 59 -------------- .../Commands/Tag/ApplyTagCommandHandler.php | 39 --------- .../Commands/Tag/CreateTagCommandHandler.php | 39 --------- .../Commands/Tag/DeleteTagCommandHandler.php | 34 -------- .../Commands/Tag/UpdateTagCommandHandler.php | 38 --------- .../Controllers/Api/ComponentController.php | 2 - .../Dashboard/ComponentController.php | 2 - app/Models/Taggable.php | 79 ------------------- ..._04_02_163658_MigrateComponentTagTable.php | 10 +-- .../Bus/Commands/Tag/ApplyTagCommandTest.php | 54 ------------- .../Bus/Commands/Tag/CreateTagCommandTest.php | 52 ------------ .../Bus/Commands/Tag/DeleteTagCommandTest.php | 51 ------------ .../Bus/Commands/Tag/UpdateTagCommandTest.php | 55 ------------- tests/Models/TaggableTest.php | 31 -------- 17 files changed, 5 insertions(+), 680 deletions(-) delete mode 100644 app/Bus/Commands/Tag/ApplyTagCommand.php delete mode 100644 app/Bus/Commands/Tag/CreateTagCommand.php delete mode 100644 app/Bus/Commands/Tag/DeleteTagCommand.php delete mode 100644 app/Bus/Commands/Tag/UpdateTagCommand.php delete mode 100644 app/Bus/Handlers/Commands/Tag/ApplyTagCommandHandler.php delete mode 100644 app/Bus/Handlers/Commands/Tag/CreateTagCommandHandler.php delete mode 100644 app/Bus/Handlers/Commands/Tag/DeleteTagCommandHandler.php delete mode 100644 app/Bus/Handlers/Commands/Tag/UpdateTagCommandHandler.php delete mode 100644 app/Models/Taggable.php delete mode 100644 tests/Bus/Commands/Tag/ApplyTagCommandTest.php delete mode 100644 tests/Bus/Commands/Tag/CreateTagCommandTest.php delete mode 100644 tests/Bus/Commands/Tag/DeleteTagCommandTest.php delete mode 100644 tests/Bus/Commands/Tag/UpdateTagCommandTest.php delete mode 100644 tests/Models/TaggableTest.php diff --git a/app/Bus/Commands/Tag/ApplyTagCommand.php b/app/Bus/Commands/Tag/ApplyTagCommand.php deleted file mode 100644 index 1fbd74218..000000000 --- a/app/Bus/Commands/Tag/ApplyTagCommand.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ -final class ApplyTagCommand -{ - /** - * The model to apply the tag to. - * - * @var \Illuminate\Database\Eloquent\Model - */ - public $model; - - /** - * The tag to apply. - * - * @var \CachetHQ\Cachet\Models\Tag - */ - public $tag; - - /** - * Create a new apply tag command instance. - * - * @param \Illuminate\Database\Eloquent\Model $model - * @param \CachetHQ\Cachet\Models\Tag $tag - * - * @return void - */ - public function __construct(Model $model, Tag $tag) - { - $this->model = $model; - $this->tag = $tag; - } -} diff --git a/app/Bus/Commands/Tag/CreateTagCommand.php b/app/Bus/Commands/Tag/CreateTagCommand.php deleted file mode 100644 index 69ae89eb6..000000000 --- a/app/Bus/Commands/Tag/CreateTagCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - */ -final class CreateTagCommand -{ - /** - * The tag name. - * - * @var string - */ - public $name; - - /** - * The tag slug. - * - * @var string|null - */ - public $slug; - - /** - * Create a new create tag command instance. - * - * @param string $name - * @param string|null $slug - * - * @return void - */ - public function __construct($name, $slug = null) - { - $this->name = $name; - $this->slug = $slug; - } -} diff --git a/app/Bus/Commands/Tag/DeleteTagCommand.php b/app/Bus/Commands/Tag/DeleteTagCommand.php deleted file mode 100644 index 7ab950014..000000000 --- a/app/Bus/Commands/Tag/DeleteTagCommand.php +++ /dev/null @@ -1,41 +0,0 @@ - - */ -final class DeleteTagCommand -{ - /** - * The tag. - * - * @var \CachetHQ\Cachet\Models\Tag - */ - public $tag; - - /** - * Create a new delete tag command instance. - * - * @param \CachetHQ\Cachet\Models\Tag $tag - * - * @return void - */ - public function __construct(Tag $tag) - { - $this->tag = $tag; - } -} diff --git a/app/Bus/Commands/Tag/UpdateTagCommand.php b/app/Bus/Commands/Tag/UpdateTagCommand.php deleted file mode 100644 index f27475006..000000000 --- a/app/Bus/Commands/Tag/UpdateTagCommand.php +++ /dev/null @@ -1,59 +0,0 @@ - - */ -final class UpdateTagCommand -{ - /** - * The tag. - * - * @var \CachetHQ\Cachet\Models\Tag - */ - public $tag; - - /** - * The new tag name. - * - * @var string|null - */ - public $name; - - /** - * The new tag slug. - * - * @var string|null - */ - public $slug; - - /** - * Create a new update tag command instance. - * - * @param \CachetHQ\Cachet\Models\Tag $tag - * @param string|null $name - * @param string|null $slug - * - * @return void - */ - public function __construct(Tag $tag, $name, $slug) - { - $this->tag = $tag; - $this->name = $name; - $this->slug = $slug; - } -} diff --git a/app/Bus/Handlers/Commands/Tag/ApplyTagCommandHandler.php b/app/Bus/Handlers/Commands/Tag/ApplyTagCommandHandler.php deleted file mode 100644 index 7f1c4f4b7..000000000 --- a/app/Bus/Handlers/Commands/Tag/ApplyTagCommandHandler.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class ApplyTagCommandHandler -{ - /** - * Handle the command. - * - * @param \CachetHQ\Cachet\Bus\Commands\Tag\ApplyTagCommand $command - * - * @return void - */ - public function handle(ApplyTagCommand $command) - { - Taggable::firstOrCreate([ - 'tag_id' => $command->tag->id, - 'taggable_id' => $command->model->id, - 'taggable_type' => $command->model->getTable(), - ]); - } -} diff --git a/app/Bus/Handlers/Commands/Tag/CreateTagCommandHandler.php b/app/Bus/Handlers/Commands/Tag/CreateTagCommandHandler.php deleted file mode 100644 index 71f616ddc..000000000 --- a/app/Bus/Handlers/Commands/Tag/CreateTagCommandHandler.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class CreateTagCommandHandler -{ - /** - * Handle the command. - * - * @param \CachetHQ\Cachet\Bus\Commands\Tag\CreateTagCommand $command - * - * @return \CachetHQ\Cachet\Models\Tag - */ - public function handle(CreateTagCommand $command) - { - return Tag::firstOrCreate([ - 'name' => $command->name, - 'slug' => $command->slug ? $command->slug : Str::slug($command->name), - ]); - } -} diff --git a/app/Bus/Handlers/Commands/Tag/DeleteTagCommandHandler.php b/app/Bus/Handlers/Commands/Tag/DeleteTagCommandHandler.php deleted file mode 100644 index 08189349e..000000000 --- a/app/Bus/Handlers/Commands/Tag/DeleteTagCommandHandler.php +++ /dev/null @@ -1,34 +0,0 @@ - - */ -class DeleteTagCommandHandler -{ - /** - * Handle the command. - * - * @param \CachetHQ\Cachet\Bus\Commands\Tag\DeleteTagCommand $command - * - * @return \CachetHQ\Cachet\Models\Tag - */ - public function handle(DeleteTagCommand $command) - { - $command->tag->delete(); - } -} diff --git a/app/Bus/Handlers/Commands/Tag/UpdateTagCommandHandler.php b/app/Bus/Handlers/Commands/Tag/UpdateTagCommandHandler.php deleted file mode 100644 index 5a21d7d6d..000000000 --- a/app/Bus/Handlers/Commands/Tag/UpdateTagCommandHandler.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -class UpdateTagCommandHandler -{ - /** - * Handle the command. - * - * @param \CachetHQ\Cachet\Bus\Commands\Tag\UpdateTagCommand $command - * - * @return void - */ - public function handle(UpdateTagCommand $command) - { - return $command->tag->update([ - 'name' => $command->name, - 'slug' => $command->slug ? $command->slug : Str::slug($command->name), - ]); - } -} diff --git a/app/Http/Controllers/Api/ComponentController.php b/app/Http/Controllers/Api/ComponentController.php index 510c62c8f..c4d1a178b 100644 --- a/app/Http/Controllers/Api/ComponentController.php +++ b/app/Http/Controllers/Api/ComponentController.php @@ -14,8 +14,6 @@ namespace CachetHQ\Cachet\Http\Controllers\Api; use CachetHQ\Cachet\Bus\Commands\Component\CreateComponentCommand; use CachetHQ\Cachet\Bus\Commands\Component\RemoveComponentCommand; use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand; -use CachetHQ\Cachet\Bus\Commands\Tag\ApplyTagCommand; -use CachetHQ\Cachet\Bus\Commands\Tag\CreateTagCommand; use CachetHQ\Cachet\Models\Component; use GrahamCampbell\Binput\Facades\Binput; use Illuminate\Contracts\Auth\Guard; diff --git a/app/Http/Controllers/Dashboard/ComponentController.php b/app/Http/Controllers/Dashboard/ComponentController.php index 31026b2b9..43dfd6a25 100644 --- a/app/Http/Controllers/Dashboard/ComponentController.php +++ b/app/Http/Controllers/Dashboard/ComponentController.php @@ -15,8 +15,6 @@ use AltThree\Validator\ValidationException; use CachetHQ\Cachet\Bus\Commands\Component\CreateComponentCommand; use CachetHQ\Cachet\Bus\Commands\Component\RemoveComponentCommand; use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand; -use CachetHQ\Cachet\Bus\Commands\Tag\ApplyTagCommand; -use CachetHQ\Cachet\Bus\Commands\Tag\CreateTagCommand; use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\ComponentGroup; use GrahamCampbell\Binput\Facades\Binput; diff --git a/app/Models/Taggable.php b/app/Models/Taggable.php deleted file mode 100644 index 9b6c94a19..000000000 --- a/app/Models/Taggable.php +++ /dev/null @@ -1,79 +0,0 @@ - - */ -class Taggable extends Model -{ - use ValidatingTrait; - - /** - * The attributes that should be casted to native types. - * - * @var string[] - */ - protected $casts = [ - 'id' => 'int', - 'tag_id' => 'int', - 'taggable_id' => 'int', - 'taggable_type' => 'string', - ]; - - /** - * The attributes that are mass assignable. - * - * @var array - */ - protected $fillable = [ - 'tag_id', - 'taggable_id', - 'taggable_type', - ]; - - /** - * The validation rules. - * - * @var string[] - */ - public $rules = [ - 'tag_id' => 'required|int', - 'taggable_id' => 'required|int', - 'taggable_type' => 'required|string', - ]; - - /** - * Get the tag relation. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function tag() - { - return $this->belongsTo(Tag::class); - } - - /** - * Get the taggable relation. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphTo - */ - public function taggable() - { - return $this->morphTo(); - } -} diff --git a/database/migrations/2018_04_02_163658_MigrateComponentTagTable.php b/database/migrations/2018_04_02_163658_MigrateComponentTagTable.php index 0d33597f7..9a7088990 100644 --- a/database/migrations/2018_04_02_163658_MigrateComponentTagTable.php +++ b/database/migrations/2018_04_02_163658_MigrateComponentTagTable.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use CachetHQ\Cachet\Models\Taggable; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; @@ -24,15 +23,16 @@ class MigrateComponentTagTable extends Migration */ public function up() { - // Start by migrating the data into the new taggables field. - DB::table('component_tag')->get()->each(function ($tag) { - Taggable::create([ + $tags = DB::table('component_tag')->get()->map(function ($tag) { + return [ 'tag_id' => $tag->tag_id, 'taggable_type' => 'components', 'taggable_id' => $tag->component_id, - ]); + ]; }); + DB::table('taggables')->insert($tags); + Schema::dropIfExists('component_tag'); } diff --git a/tests/Bus/Commands/Tag/ApplyTagCommandTest.php b/tests/Bus/Commands/Tag/ApplyTagCommandTest.php deleted file mode 100644 index a1c8bd255..000000000 --- a/tests/Bus/Commands/Tag/ApplyTagCommandTest.php +++ /dev/null @@ -1,54 +0,0 @@ - - */ -class ApplyTagCommandTest extends AbstractTestCase -{ - use CommandTrait; - - protected function getObjectAndParams() - { - $params = [ - 'model' => new Component(), - 'tag' => new Tag(), - ]; - - $object = new ApplyTagCommand( - $params['model'], - $params['tag'] - ); - - return compact('params', 'object'); - } - - protected function objectHasRules() - { - return false; - } - - protected function getHandlerClass() - { - return ApplyTagCommandHandler::class; - } -} diff --git a/tests/Bus/Commands/Tag/CreateTagCommandTest.php b/tests/Bus/Commands/Tag/CreateTagCommandTest.php deleted file mode 100644 index 59bf63698..000000000 --- a/tests/Bus/Commands/Tag/CreateTagCommandTest.php +++ /dev/null @@ -1,52 +0,0 @@ - - */ -class CreateTagCommandTest extends AbstractTestCase -{ - use CommandTrait; - - protected function getObjectAndParams() - { - $params = [ - 'name' => 'Test', - 'slug' => 'test', - ]; - - $object = new CreateTagCommand( - $params['name'], - $params['slug'] - ); - - return compact('params', 'object'); - } - - protected function objectHasRules() - { - return false; - } - - protected function getHandlerClass() - { - return CreateTagCommandHandler::class; - } -} diff --git a/tests/Bus/Commands/Tag/DeleteTagCommandTest.php b/tests/Bus/Commands/Tag/DeleteTagCommandTest.php deleted file mode 100644 index 2bee7b971..000000000 --- a/tests/Bus/Commands/Tag/DeleteTagCommandTest.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ -class DeleteTagCommandTest extends AbstractTestCase -{ - use CommandTrait; - - protected function getObjectAndParams() - { - $params = [ - 'tag' => new Tag(), - ]; - - $object = new DeleteTagCommand( - $params['tag'] - ); - - return compact('params', 'object'); - } - - protected function objectHasRules() - { - return false; - } - - protected function getHandlerClass() - { - return DeleteTagCommandHandler::class; - } -} diff --git a/tests/Bus/Commands/Tag/UpdateTagCommandTest.php b/tests/Bus/Commands/Tag/UpdateTagCommandTest.php deleted file mode 100644 index 163c7477b..000000000 --- a/tests/Bus/Commands/Tag/UpdateTagCommandTest.php +++ /dev/null @@ -1,55 +0,0 @@ - - */ -class UpdateTagCommandTest extends AbstractTestCase -{ - use CommandTrait; - - protected function getObjectAndParams() - { - $params = [ - 'tag' => new Tag(), - 'name' => 'Test', - 'slug' => 'test', - ]; - - $object = new UpdateTagCommand( - $params['tag'], - $params['name'], - $params['slug'] - ); - - return compact('params', 'object'); - } - - protected function objectHasRules() - { - return false; - } - - protected function getHandlerClass() - { - return UpdateTagCommandHandler::class; - } -} diff --git a/tests/Models/TaggableTest.php b/tests/Models/TaggableTest.php deleted file mode 100644 index 8a5271a35..000000000 --- a/tests/Models/TaggableTest.php +++ /dev/null @@ -1,31 +0,0 @@ - - */ -class TaggableTest extends AbstractTestCase -{ - use ValidationTrait; - - public function testValidation() - { - $this->checkRules(new Taggable()); - } -}