1
|
|
|
<?php namespace Anomaly\Streams\Platform\Stream; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Entry\Command\GenerateEntryModelClassmap; |
4
|
|
|
use Anomaly\Streams\Platform\Search\Command\CheckEntryIndex; |
5
|
|
|
use Anomaly\Streams\Platform\Search\Command\DeleteEntryIndex; |
6
|
|
|
use Anomaly\Streams\Platform\Stream\Command\CreateStreamsEntryTable; |
7
|
|
|
use Anomaly\Streams\Platform\Stream\Command\DeleteStreamAssignments; |
8
|
|
|
use Anomaly\Streams\Platform\Stream\Command\DeleteStreamEntryModels; |
9
|
|
|
use Anomaly\Streams\Platform\Stream\Command\DeleteStreamTranslations; |
10
|
|
|
use Anomaly\Streams\Platform\Stream\Command\DropStreamsEntryTable; |
11
|
|
|
use Anomaly\Streams\Platform\Stream\Command\RenameStreamsEntryTable; |
12
|
|
|
use Anomaly\Streams\Platform\Stream\Contract\StreamInterface; |
13
|
|
|
use Anomaly\Streams\Platform\Stream\Event\StreamWasCreated; |
14
|
|
|
use Anomaly\Streams\Platform\Stream\Event\StreamWasDeleted; |
15
|
|
|
use Anomaly\Streams\Platform\Stream\Event\StreamWasSaved; |
16
|
|
|
use Anomaly\Streams\Platform\Stream\Event\StreamWasUpdated; |
17
|
|
|
use Anomaly\Streams\Platform\Support\Observer; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class StreamObserver |
21
|
|
|
* |
22
|
|
|
* @link http://pyrocms.com/ |
23
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
24
|
|
|
* @author Ryan Thompson <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class StreamObserver extends Observer |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Run before a stream is created. |
31
|
|
|
* |
32
|
|
|
* @param StreamInterface $model |
33
|
|
|
*/ |
34
|
|
|
public function creating(StreamInterface $model) |
35
|
|
|
{ |
36
|
|
|
$model->fireFieldTypeEvents('stream_creating'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Run after a stream is created. |
41
|
|
|
* |
42
|
|
|
* @param StreamInterface $model |
43
|
|
|
*/ |
44
|
|
|
public function created(StreamInterface $model) |
45
|
|
|
{ |
46
|
|
|
$model->compile(); |
47
|
|
|
$model->flushCache(); |
48
|
|
|
|
49
|
|
|
$this->dispatch(new CreateStreamsEntryTable($model)); |
50
|
|
|
|
51
|
|
|
$model->fireFieldTypeEvents('stream_created'); |
52
|
|
|
|
53
|
|
|
$this->events->fire(new StreamWasCreated($model)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Run after stream a record. |
58
|
|
|
* |
59
|
|
|
* @param StreamInterface $model |
60
|
|
|
*/ |
61
|
|
|
public function saved(StreamInterface $model) |
62
|
|
|
{ |
63
|
|
|
$model->compile(); |
64
|
|
|
$model->flushCache(); |
65
|
|
|
|
66
|
|
|
$this->dispatch(new CheckEntryIndex($model)); |
67
|
|
|
|
68
|
|
|
$model->fireFieldTypeEvents('stream_saved'); |
69
|
|
|
|
70
|
|
|
$this->events->fire(new StreamWasSaved($model)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Run before a record is updated. |
75
|
|
|
* |
76
|
|
|
* @param StreamInterface $model |
77
|
|
|
*/ |
78
|
|
|
public function updating(StreamInterface $model) |
79
|
|
|
{ |
80
|
|
|
$model->fireFieldTypeEvents('stream_updating'); |
81
|
|
|
|
82
|
|
|
$this->dispatch(new RenameStreamsEntryTable($model)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Run after a record is updated. |
87
|
|
|
* |
88
|
|
|
* @param StreamInterface $model |
89
|
|
|
*/ |
90
|
|
|
public function updated(StreamInterface $model) |
91
|
|
|
{ |
92
|
|
|
$model->fireFieldTypeEvents('stream_updated'); |
93
|
|
|
|
94
|
|
|
$this->events->fire(new StreamWasUpdated($model)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Run after a stream has been deleted. |
99
|
|
|
* |
100
|
|
|
* @param StreamInterface $model |
101
|
|
|
*/ |
102
|
|
|
public function deleted(StreamInterface $model) |
103
|
|
|
{ |
104
|
|
|
$model->compile(); |
105
|
|
|
$model->flushCache(); |
106
|
|
|
|
107
|
|
|
$model->fireFieldTypeEvents('stream_deleted'); |
108
|
|
|
|
109
|
|
|
$this->dispatch(new DeleteEntryIndex($model)); |
110
|
|
|
$this->dispatch(new DropStreamsEntryTable($model)); |
111
|
|
|
$this->dispatch(new DeleteStreamEntryModels($model)); |
112
|
|
|
$this->dispatch(new DeleteStreamAssignments($model)); |
113
|
|
|
$this->dispatch(new DeleteStreamTranslations($model)); |
114
|
|
|
$this->dispatch(new GenerateEntryModelClassmap()); |
115
|
|
|
|
116
|
|
|
$this->events->fire(new StreamWasDeleted($model)); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|