Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how tags are created #3087

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions app/Bus/Commands/Tag/ApplyTagCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Bus\Commands\Tag;

use CachetHQ\Cachet\Models\Tag;
use Illuminate\Database\Eloquent\Model;

/**
* This is the apply tag coommand class.
*
* @author James Brooks <[email protected]>
*/
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;
}
}
48 changes: 48 additions & 0 deletions app/Bus/Commands/Tag/CreateTagCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Bus\Commands\Tag;

/**
* This is the create tag coommand class.
*
* @author James Brooks <[email protected]>
*/
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;
}
}
41 changes: 41 additions & 0 deletions app/Bus/Commands/Tag/DeleteTagCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Bus\Commands\Tag;

use CachetHQ\Cachet\Models\Tag;

/**
* This is the delete tag coommand class.
*
* @author James Brooks <[email protected]>
*/
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;
}
}
59 changes: 59 additions & 0 deletions app/Bus/Commands/Tag/UpdateTagCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Bus\Commands\Tag;

use CachetHQ\Cachet\Models\Tag;

/**
* This is the update tag coommand class.
*
* @author James Brooks <[email protected]>
*/
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;
}
}
39 changes: 39 additions & 0 deletions app/Bus/Handlers/Commands/Tag/ApplyTagCommandHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Bus\Handlers\Commands\Tag;

use CachetHQ\Cachet\Bus\Commands\Tag\ApplyTagCommand;
use CachetHQ\Cachet\Models\Taggable;

/**
* This is the apply tag command handler class.
*
* @author James Brooks <[email protected]>
*/
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(),
]);
}
}
39 changes: 39 additions & 0 deletions app/Bus/Handlers/Commands/Tag/CreateTagCommandHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Bus\Handlers\Commands\Tag;

use CachetHQ\Cachet\Bus\Commands\Tag\CreateTagCommand;
use CachetHQ\Cachet\Models\Tag;
use Illuminate\Support\Str;

/**
* This is the create tag command handler class.
*
* @author James Brooks <[email protected]>
*/
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),
]);
}
}
34 changes: 34 additions & 0 deletions app/Bus/Handlers/Commands/Tag/DeleteTagCommandHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Bus\Handlers\Commands\Tag;

use CachetHQ\Cachet\Bus\Commands\Tag\DeleteTagCommand;

/**
* This is the delete tag command handler class.
*
* @author James Brooks <[email protected]>
*/
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();
}
}
38 changes: 38 additions & 0 deletions app/Bus/Handlers/Commands/Tag/UpdateTagCommandHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Bus\Handlers\Commands\Tag;

use CachetHQ\Cachet\Bus\Commands\Tag\UpdateTagCommand;
use Illuminate\Support\Str;

/**
* This is the create tag command handler class.
*
* @author James Brooks <[email protected]>
*/
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),
]);
}
}
Loading