1
|
|
|
<?php namespace Anomaly\Streams\Platform\Entry; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Entry\Command\DeleteEntryTranslations; |
4
|
|
|
use Anomaly\Streams\Platform\Entry\Command\SetMetaInformation; |
5
|
|
|
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface; |
6
|
|
|
use Anomaly\Streams\Platform\Entry\Event\EntryWasCreated; |
7
|
|
|
use Anomaly\Streams\Platform\Entry\Event\EntryWasDeleted; |
8
|
|
|
use Anomaly\Streams\Platform\Entry\Event\EntryWasRestored; |
9
|
|
|
use Anomaly\Streams\Platform\Entry\Event\EntryWasSaved; |
10
|
|
|
use Anomaly\Streams\Platform\Entry\Event\EntryWasUpdated; |
11
|
|
|
use Anomaly\Streams\Platform\Model\Command\CascadeDelete; |
12
|
|
|
use Anomaly\Streams\Platform\Model\Command\CascadeRestore; |
13
|
|
|
use Anomaly\Streams\Platform\Model\EloquentModel; |
14
|
|
|
use Anomaly\Streams\Platform\Model\Event\ModelsWereDeleted; |
15
|
|
|
use Anomaly\Streams\Platform\Model\Event\ModelsWereUpdated; |
16
|
|
|
use Anomaly\Streams\Platform\Support\Observer; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class EntryObserver |
20
|
|
|
* |
21
|
|
|
* @link http://pyrocms.com/ |
22
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
23
|
|
|
* @author Ryan Thompson <[email protected]> |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
class EntryObserver extends Observer |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Run before a record is created. |
31
|
|
|
* |
32
|
|
|
* @param EntryInterface $entry |
33
|
|
|
*/ |
34
|
|
|
public function creating(EntryInterface $entry) |
35
|
|
|
{ |
36
|
|
|
$entry->fireFieldTypeEvents('entry_creating'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Run after a record is created. |
41
|
|
|
* |
42
|
|
|
* @param EntryInterface $entry |
43
|
|
|
*/ |
44
|
|
|
public function created(EntryInterface $entry) |
45
|
|
|
{ |
46
|
|
|
$entry->fireFieldTypeEvents('entry_created'); |
47
|
|
|
|
48
|
|
|
$this->events->fire(new EntryWasCreated($entry)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Run before a record is updated. |
53
|
|
|
* |
54
|
|
|
* @param EntryInterface $entry |
55
|
|
|
*/ |
56
|
|
|
public function updating(EntryInterface $entry) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
// |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Run after a record is updated. |
63
|
|
|
* |
64
|
|
|
* @param EntryInterface $entry |
65
|
|
|
*/ |
66
|
|
|
public function updated(EntryInterface $entry) |
67
|
|
|
{ |
68
|
|
|
$entry->fireFieldTypeEvents('entry_updated'); |
69
|
|
|
|
70
|
|
|
$this->events->fire(new EntryWasUpdated($entry)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Run after multiple entries have been updated. |
75
|
|
|
* |
76
|
|
|
* @param EntryInterface $entry |
77
|
|
|
*/ |
78
|
|
|
public function updatedMultiple(EntryInterface $entry) |
79
|
|
|
{ |
80
|
|
|
$entry->flushCache(); |
81
|
|
|
|
82
|
|
|
$this->events->fire(new ModelsWereUpdated($entry)); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Before saving an entry touch the |
87
|
|
|
* meta information. |
88
|
|
|
* |
89
|
|
|
* @param EntryInterface $entry |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
|
|
public function saving(EntryInterface $entry) |
93
|
|
|
{ |
94
|
|
|
//$entry->fireFieldTypeEvents('entry_saving'); |
|
|
|
|
95
|
|
|
|
96
|
|
|
$this->commands->dispatch(new SetMetaInformation($entry)); |
|
|
|
|
97
|
|
|
|
98
|
|
|
return true; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Run after saving a record. |
103
|
|
|
* |
104
|
|
|
* @param EntryInterface $entry |
105
|
|
|
*/ |
106
|
|
|
public function saved(EntryInterface $entry) |
107
|
|
|
{ |
108
|
|
|
$entry->flushCache(); |
109
|
|
|
$entry->fireFieldTypeEvents('entry_saved'); |
110
|
|
|
|
111
|
|
|
$this->events->fire(new EntryWasSaved($entry)); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Run before a record is deleted. |
116
|
|
|
* |
117
|
|
|
* @param EntryInterface|EloquentModel $entry |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
|
public function deleting(EntryInterface $entry) |
121
|
|
|
{ |
122
|
|
|
$this->dispatch(new CascadeDelete($entry)); |
|
|
|
|
123
|
|
|
|
124
|
|
|
return true; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Run after a record has been deleted. |
129
|
|
|
* |
130
|
|
|
* @param EntryInterface $entry |
131
|
|
|
*/ |
132
|
|
|
public function deleted(EntryInterface $entry) |
133
|
|
|
{ |
134
|
|
|
$entry->flushCache(); |
135
|
|
|
$entry->fireFieldTypeEvents('entry_deleted'); |
136
|
|
|
|
137
|
|
|
$this->commands->dispatch(new DeleteEntryTranslations($entry)); |
138
|
|
|
|
139
|
|
|
$this->events->fire(new EntryWasDeleted($entry)); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Run after entries records have been deleted. |
144
|
|
|
* |
145
|
|
|
* @param EntryInterface $entry |
146
|
|
|
*/ |
147
|
|
|
public function deletedMultiple(EntryInterface $entry) |
148
|
|
|
{ |
149
|
|
|
$entry->flushCache(); |
150
|
|
|
|
151
|
|
|
$this->events->fire(new ModelsWereDeleted($entry)); |
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Fired just before restoring. |
156
|
|
|
* |
157
|
|
|
* @param EntryInterface|EloquentModel $entry |
158
|
|
|
*/ |
159
|
|
|
public function restoring(EntryInterface $entry) |
|
|
|
|
160
|
|
|
{ |
161
|
|
|
// |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Run after a record has been restored. |
166
|
|
|
* |
167
|
|
|
* @param EntryInterface|EloquentModel $entry |
168
|
|
|
*/ |
169
|
|
|
public function restored(EntryInterface $entry) |
170
|
|
|
{ |
171
|
|
|
$entry->flushCache(); |
172
|
|
|
$entry->fireFieldTypeEvents('entry_restored'); |
173
|
|
|
|
174
|
|
|
$this->dispatch(new CascadeRestore($entry)); |
|
|
|
|
175
|
|
|
|
176
|
|
|
$this->events->fire(new EntryWasRestored($entry)); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.