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