|
1
|
|
|
<?php namespace Anomaly\Streams\Platform\Assignment\Command; |
|
2
|
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Assignment\AssignmentSchema; |
|
4
|
|
|
use Anomaly\Streams\Platform\Assignment\Contract\AssignmentInterface; |
|
5
|
|
|
use Anomaly\Streams\Platform\Assignment\Contract\AssignmentRepositoryInterface; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class ChangeAssignmentColumn |
|
9
|
|
|
* |
|
10
|
|
|
* @link http://pyrocms.com/ |
|
11
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
|
12
|
|
|
* @author Ryan Thompson <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
View Code Duplication |
class ChangeAssignmentColumn |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The assignment interface. |
|
19
|
|
|
* |
|
20
|
|
|
* @var AssignmentInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $assignment; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create a new ChangeAssignmentColumn instance. |
|
26
|
|
|
* |
|
27
|
|
|
* @param AssignmentInterface $assignment |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(AssignmentInterface $assignment) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->assignment = $assignment; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Handle the command. |
|
36
|
|
|
* |
|
37
|
|
|
* @param AssignmentSchema $schema |
|
38
|
|
|
* @param AssignmentRepositoryInterface $assignments |
|
39
|
|
|
*/ |
|
40
|
|
|
public function handle(AssignmentSchema $schema, AssignmentRepositoryInterface $assignments) |
|
41
|
|
|
{ |
|
42
|
|
|
$stream = $this->assignment->getStream(); |
|
43
|
|
|
$type = $this->assignment->getFieldType(true); |
|
44
|
|
|
|
|
45
|
|
|
if (!$this->assignment->isTranslatable()) { |
|
46
|
|
|
$table = $stream->getEntryTableName(); |
|
47
|
|
|
} else { |
|
48
|
|
|
$table = $stream->getEntryTranslationsTableName(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/* @var AssignmentInterface $assignment */ |
|
52
|
|
|
$assignment = $assignments->find($this->assignment->getId()); |
|
53
|
|
|
|
|
54
|
|
|
$assignment = clone($assignment); |
|
55
|
|
|
|
|
56
|
|
|
$schema->renameColumn($table, $type, $assignment); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.