@@ 16-69 (lines=54) @@ | ||
13 | * @author Ryan Thompson <[email protected]> |
|
14 | * @package Anomaly\Streams\Platform\Assignment\Command |
|
15 | */ |
|
16 | class BackupAssignmentData implements SelfHandling |
|
17 | { |
|
18 | ||
19 | /** |
|
20 | * The assignment interface. |
|
21 | * |
|
22 | * @var AssignmentInterface |
|
23 | */ |
|
24 | protected $assignment; |
|
25 | ||
26 | /** |
|
27 | * Create a new BackupAssignmentData instance. |
|
28 | * |
|
29 | * @param AssignmentInterface $assignment |
|
30 | */ |
|
31 | public function __construct(AssignmentInterface $assignment) |
|
32 | { |
|
33 | $this->assignment = $assignment; |
|
34 | } |
|
35 | ||
36 | /** |
|
37 | * Handle the command. |
|
38 | * |
|
39 | * @param AssignmentSchema $schema |
|
40 | */ |
|
41 | public function handle(AssignmentSchema $schema, AssignmentRepositoryInterface $assignments) |
|
42 | { |
|
43 | $stream = $this->assignment->getStream(); |
|
44 | ||
45 | /* @var AssignmentInterface $assignment */ |
|
46 | $assignment = $assignments->find($this->assignment->getId()); |
|
47 | ||
48 | // If nothing is different then skip it. |
|
49 | if ($assignment->isTranslatable() == $this->assignment->isTranslatable()) { |
|
50 | return; |
|
51 | } |
|
52 | ||
53 | /** |
|
54 | * If it's NOW translatable then |
|
55 | * back it up from the main table. |
|
56 | */ |
|
57 | if ($this->assignment->isTranslatable()) { |
|
58 | $schema->backupColumn($stream->getEntryTableName(), $assignment->getFieldType(true)); |
|
59 | } |
|
60 | ||
61 | /** |
|
62 | * If it's NOT translatable then back |
|
63 | * it up from the translations table. |
|
64 | */ |
|
65 | if (!$this->assignment->isTranslatable()) { |
|
66 | $schema->backupColumn($stream->getEntryTranslationsTableName(), $assignment->getFieldType(true)); |
|
67 | } |
|
68 | } |
|
69 | } |
|
70 |
@@ 16-69 (lines=54) @@ | ||
13 | * @author Ryan Thompson <[email protected]> |
|
14 | * @package Anomaly\Streams\Platform\Assignment\Command |
|
15 | */ |
|
16 | class RestoreAssignmentData implements SelfHandling |
|
17 | { |
|
18 | ||
19 | /** |
|
20 | * The assignment interface. |
|
21 | * |
|
22 | * @var AssignmentInterface |
|
23 | */ |
|
24 | protected $assignment; |
|
25 | ||
26 | /** |
|
27 | * Create a new RestoreAssignmentData instance. |
|
28 | * |
|
29 | * @param AssignmentInterface $assignment |
|
30 | */ |
|
31 | public function __construct(AssignmentInterface $assignment) |
|
32 | { |
|
33 | $this->assignment = $assignment; |
|
34 | } |
|
35 | ||
36 | /** |
|
37 | * Handle the command. |
|
38 | * |
|
39 | * @param AssignmentSchema $schema |
|
40 | */ |
|
41 | public function handle(AssignmentSchema $schema, AssignmentRepositoryInterface $assignments) |
|
42 | { |
|
43 | $stream = $this->assignment->getStream(); |
|
44 | ||
45 | /* @var AssignmentInterface $assignment */ |
|
46 | $assignment = $assignments->find($this->assignment->getId()); |
|
47 | ||
48 | // If nothing is different then skip it. |
|
49 | if ($assignment->isTranslatable() == $this->assignment->isTranslatable()) { |
|
50 | return; |
|
51 | } |
|
52 | ||
53 | /** |
|
54 | * If it's NOW translatable then |
|
55 | * restore it to the main table. |
|
56 | */ |
|
57 | if ($this->assignment->isTranslatable()) { |
|
58 | $schema->restoreColumn($stream->getEntryTranslationsTableName(), $assignment->getFieldType(true)); |
|
59 | } |
|
60 | ||
61 | /** |
|
62 | * If it's NOT translatable then back |
|
63 | * it up from the translations table. |
|
64 | */ |
|
65 | if (!$this->assignment->isTranslatable()) { |
|
66 | $schema->restoreColumn($stream->getEntryTableName(), $assignment->getFieldType(true)); |
|
67 | } |
|
68 | } |
|
69 | } |
|
70 |