PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.4
Independent Analytics – WordPress Analytics Plugin v2.15.4
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / illuminate / database / Eloquent / SoftDeletes.php
independent-analytics / vendor / illuminate / database / Eloquent Last commit date
Casts 1 month ago Concerns 1 month ago Factories 1 month ago Relations 1 month ago BroadcastableModelEventOccurred.php 1 month ago BroadcastsEvents.php 6 months ago Builder.php 1 month ago Collection.php 1 month ago HigherOrderBuilderProxy.php 2 years ago InvalidCastException.php 2 years ago JsonEncodingException.php 2 years ago MassAssignmentException.php 2 years ago MassPrunable.php 6 months ago MissingAttributeException.php 1 month ago Model.php 1 month ago ModelNotFoundException.php 1 month ago PendingHasThroughRelationship.php 1 month ago Prunable.php 2 years ago QueueEntityResolver.php 2 years ago RelationNotFoundException.php 2 years ago Scope.php 2 years ago SoftDeletes.php 1 month ago SoftDeletingScope.php 1 month ago
SoftDeletes.php
217 lines
1 <?php
2
3 namespace IAWPSCOPED\Illuminate\Database\Eloquent;
4
5 /**
6 * @method static \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withTrashed(bool $withTrashed = true)
7 * @method static \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder onlyTrashed()
8 * @method static \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withoutTrashed()
9 * @internal
10 */
11 trait SoftDeletes
12 {
13 /**
14 * Indicates if the model is currently force deleting.
15 *
16 * @var bool
17 */
18 protected $forceDeleting = \false;
19 /**
20 * Boot the soft deleting trait for a model.
21 *
22 * @return void
23 */
24 public static function bootSoftDeletes()
25 {
26 static::addGlobalScope(new SoftDeletingScope());
27 }
28 /**
29 * Initialize the soft deleting trait for an instance.
30 *
31 * @return void
32 */
33 public function initializeSoftDeletes()
34 {
35 if (!isset($this->casts[$this->getDeletedAtColumn()])) {
36 $this->casts[$this->getDeletedAtColumn()] = 'datetime';
37 }
38 }
39 /**
40 * Force a hard delete on a soft deleted model.
41 *
42 * @return bool|null
43 */
44 public function forceDelete()
45 {
46 if ($this->fireModelEvent('forceDeleting') === \false) {
47 return \false;
48 }
49 $this->forceDeleting = \true;
50 return \IAWPSCOPED\tap($this->delete(), function ($deleted) {
51 $this->forceDeleting = \false;
52 if ($deleted) {
53 $this->fireModelEvent('forceDeleted', \false);
54 }
55 });
56 }
57 /**
58 * Force a hard delete on a soft deleted model without raising any events.
59 *
60 * @return bool|null
61 */
62 public function forceDeleteQuietly()
63 {
64 return static::withoutEvents(fn() => $this->forceDelete());
65 }
66 /**
67 * Perform the actual delete query on this model instance.
68 *
69 * @return mixed
70 */
71 protected function performDeleteOnModel()
72 {
73 if ($this->forceDeleting) {
74 return \IAWPSCOPED\tap($this->setKeysForSaveQuery($this->newModelQuery())->forceDelete(), function () {
75 $this->exists = \false;
76 });
77 }
78 return $this->runSoftDelete();
79 }
80 /**
81 * Perform the actual delete query on this model instance.
82 *
83 * @return void
84 */
85 protected function runSoftDelete()
86 {
87 $query = $this->setKeysForSaveQuery($this->newModelQuery());
88 $time = $this->freshTimestamp();
89 $columns = [$this->getDeletedAtColumn() => $this->fromDateTime($time)];
90 $this->{$this->getDeletedAtColumn()} = $time;
91 if ($this->usesTimestamps() && !\is_null($this->getUpdatedAtColumn())) {
92 $this->{$this->getUpdatedAtColumn()} = $time;
93 $columns[$this->getUpdatedAtColumn()] = $this->fromDateTime($time);
94 }
95 $query->update($columns);
96 $this->syncOriginalAttributes(\array_keys($columns));
97 $this->fireModelEvent('trashed', \false);
98 }
99 /**
100 * Restore a soft-deleted model instance.
101 *
102 * @return bool
103 */
104 public function restore()
105 {
106 // If the restoring event does not return false, we will proceed with this
107 // restore operation. Otherwise, we bail out so the developer will stop
108 // the restore totally. We will clear the deleted timestamp and save.
109 if ($this->fireModelEvent('restoring') === \false) {
110 return \false;
111 }
112 $this->{$this->getDeletedAtColumn()} = null;
113 // Once we have saved the model, we will fire the "restored" event so this
114 // developer will do anything they need to after a restore operation is
115 // totally finished. Then we will return the result of the save call.
116 $this->exists = \true;
117 $result = $this->save();
118 $this->fireModelEvent('restored', \false);
119 return $result;
120 }
121 /**
122 * Restore a soft-deleted model instance without raising any events.
123 *
124 * @return bool
125 */
126 public function restoreQuietly()
127 {
128 return static::withoutEvents(fn() => $this->restore());
129 }
130 /**
131 * Determine if the model instance has been soft-deleted.
132 *
133 * @return bool
134 */
135 public function trashed()
136 {
137 return !\is_null($this->{$this->getDeletedAtColumn()});
138 }
139 /**
140 * Register a "softDeleted" model event callback with the dispatcher.
141 *
142 * @param \Closure|string $callback
143 * @return void
144 */
145 public static function softDeleted($callback)
146 {
147 static::registerModelEvent('trashed', $callback);
148 }
149 /**
150 * Register a "restoring" model event callback with the dispatcher.
151 *
152 * @param \Closure|string $callback
153 * @return void
154 */
155 public static function restoring($callback)
156 {
157 static::registerModelEvent('restoring', $callback);
158 }
159 /**
160 * Register a "restored" model event callback with the dispatcher.
161 *
162 * @param \Closure|string $callback
163 * @return void
164 */
165 public static function restored($callback)
166 {
167 static::registerModelEvent('restored', $callback);
168 }
169 /**
170 * Register a "forceDeleting" model event callback with the dispatcher.
171 *
172 * @param \Closure|string $callback
173 * @return void
174 */
175 public static function forceDeleting($callback)
176 {
177 static::registerModelEvent('forceDeleting', $callback);
178 }
179 /**
180 * Register a "forceDeleted" model event callback with the dispatcher.
181 *
182 * @param \Closure|string $callback
183 * @return void
184 */
185 public static function forceDeleted($callback)
186 {
187 static::registerModelEvent('forceDeleted', $callback);
188 }
189 /**
190 * Determine if the model is currently force deleting.
191 *
192 * @return bool
193 */
194 public function isForceDeleting()
195 {
196 return $this->forceDeleting;
197 }
198 /**
199 * Get the name of the "deleted at" column.
200 *
201 * @return string
202 */
203 public function getDeletedAtColumn()
204 {
205 return \defined(static::class . '::DELETED_AT') ? static::DELETED_AT : 'deleted_at';
206 }
207 /**
208 * Get the fully qualified "deleted at" column.
209 *
210 * @return string
211 */
212 public function getQualifiedDeletedAtColumn()
213 {
214 return $this->qualifyColumn($this->getDeletedAtColumn());
215 }
216 }
217