Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php namespace Illuminate\Database\Eloquent;

trait SoftDeletingTrait {

	/**
	 * Indicates if the model is currently force deleting.
	 *
	 * @var bool
	 */
	protected $forceDeleting = false;

	/**
	 * Boot the soft deleting trait for a model.
	 *
	 * @return void
	 */
	public static function bootSoftDeletingTrait()
	{
		static::addGlobalScope(new SoftDeletingScope);
	}

	/**
	 * Force a hard delete on a soft deleted model.
	 *
	 * @return void
	 */
	public function forceDelete()
	{
		$this->forceDeleting = true;

		$this->delete();

		$this->forceDeleting = false;
	}

	/**
	 * Perform the actual delete query on this model instance.
	 *
	 * @return void
	 */
	protected function performDeleteOnModel()
	{
		if ($this->forceDeleting)
		{
			$this->withTrashed()->where($this->getKeyName(), $this->getKey())->forceDelete();
		}

		return $this->runSoftDelete();
	}

	/**
	 * Perform the actual delete query on this model instance.
	 *
	 * @return void
	 */
	protected function runSoftDelete()
	{
		$query = $this->newQuery()->where($this->getKeyName(), $this->getKey());

		$this->{$this->getDeletedAtColumn()} = $time = $this->freshTimestamp();

		$query->update(array($this->getDeletedAtColumn() => $this->fromDateTime($time)));
	}

	/**
	 * Restore a soft-deleted model instance.
	 *
	 * @return bool|null
	 */
	public function restore()
	{
		// If the restoring event does not return false, we will proceed with this
		// restore operation. Otherwise, we bail out so the developer will stop
		// the restore totally. We will clear the deleted timestamp and save.
		if ($this->fireModelEvent('restoring') === false)
		{
			return false;
		}

		$this->{$this->getDeletedAtColumn()} = null;

		// Once we have saved the model, we will fire the "restored" event so this
		// developer will do anything they need to after a restore operation is
		// totally finished. Then we will return the result of the save call.
		$this->exists = true;

		$result = $this->save();

		$this->fireModelEvent('restored', false);

		return $result;
	}

	/**
	 * Determine if the model instance has been soft-deleted.
	 *
	 * @return bool
	 */
	public function trashed()
	{
		return ! is_null($this->{$this->getDeletedAtColumn()});
	}

	/**
	 * Get a new query builder that includes soft deletes.
	 *
	 * @return \Illuminate\Database\Eloquent\Builder|static
	 */
	public static function withTrashed()
	{
		return (new static)->newQueryWithoutScope(new SoftDeletingScope);
	}

	/**
	 * Get a new query builder that only includes soft deletes.
	 *
	 * @return \Illuminate\Database\Eloquent\Builder|static
	 */
	public static function onlyTrashed()
	{
		$instance = new static;

		$column = $instance->getQualifiedDeletedAtColumn();

		return $instance->newQueryWithoutScope(new SoftDeletingScope)->whereNotNull($column);
	}

	/**
	 * Register a restoring model event with the dispatcher.
	 *
	 * @param  \Closure|string  $callback
	 * @return void
	 */
	public static function restoring($callback)
	{
		static::registerModelEvent('restoring', $callback);
	}

	/**
	 * Register a restored model event with the dispatcher.
	 *
	 * @param  \Closure|string  $callback
	 * @return void
	 */
	public static function restored($callback)
	{
		static::registerModelEvent('restored', $callback);
	}

	/**
	 * Get the name of the "deleted at" column.
	 *
	 * @return string
	 */
	public function getDeletedAtColumn()
	{
		return defined('static::DELETED_AT') ? static::DELETED_AT : 'deleted_at';
	}

	/**
	 * Get the fully qualified "deleted at" column.
	 *
	 * @return string
	 */
	public function getQualifiedDeletedAtColumn()
	{
		return $this->getTable().'.'.$this->getDeletedAtColumn();
	}

}

Commits for Nextrek/Aiba_backup/vendor/laravel/framework/src/Illuminate/Database/Eloquent/SoftDeletingTrait.php

Diff revisions: vs.
Revision Author Commited Message
1464 MOliva picture MOliva Tue 13 Oct, 2020 11:16:56 +0000