-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix how tags are created. Fixes #3004
- Loading branch information
Showing
14 changed files
with
584 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
]); | ||
} | ||
} |
Oops, something went wrong.