1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Http\Controllers\Operations; |
4
|
|
|
|
5
|
|
|
trait Revisions |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Display the revisions for specified resource. |
9
|
|
|
* |
10
|
|
|
* @param int $id |
11
|
|
|
* |
12
|
|
|
* @return Response |
|
|
|
|
13
|
|
|
*/ |
14
|
|
|
public function listRevisions($id) |
15
|
|
|
{ |
16
|
|
|
$this->crud->hasAccessOrFail('revisions'); |
|
|
|
|
17
|
|
|
|
18
|
|
|
// get entry ID from Request (makes sure its the last ID for nested resources) |
19
|
|
|
$id = $this->crud->getCurrentEntryId() ?? $id; |
20
|
|
|
|
21
|
|
|
// get the info for that entry |
22
|
|
|
$this->data['entry'] = $this->crud->getEntry($id); |
|
|
|
|
23
|
|
|
$this->data['crud'] = $this->crud; |
24
|
|
|
$this->data['title'] = ucfirst($this->crud->entity_name).' '.trans('backpack::crud.revisions'); |
25
|
|
|
$this->data['id'] = $id; |
26
|
|
|
$this->data['revisions'] = $this->crud->listRevisions($id); |
27
|
|
|
|
28
|
|
|
// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
29
|
|
|
return view($this->crud->getRevisionsView(), $this->data); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Restore a specific revision for the specified resource. |
34
|
|
|
* |
35
|
|
|
* Used via AJAX in the revisions view |
36
|
|
|
* |
37
|
|
|
* @param int $id |
38
|
|
|
* |
39
|
|
|
* @return JSON Response containing the new revision that was created from the update |
40
|
|
|
* @return HTTP 500 if the request did not contain the revision ID |
|
|
|
|
41
|
|
|
*/ |
42
|
|
|
public function restoreRevision($id) |
43
|
|
|
{ |
44
|
|
|
$this->crud->hasAccessOrFail('revisions'); |
45
|
|
|
|
46
|
|
|
$revisionId = \Request::input('revision_id', false); |
|
|
|
|
47
|
|
|
if (! $revisionId) { |
48
|
|
|
abort(500, 'Can\'t restore revision without revision_id'); |
49
|
|
|
} else { |
50
|
|
|
$this->crud->restoreRevision($id, $revisionId); // do the update |
51
|
|
|
|
52
|
|
|
$this->data['entry'] = $this->crud->getEntry($id); |
53
|
|
|
$this->data['crud'] = $this->crud; |
54
|
|
|
$this->data['revisions'] = $this->crud->listRevisions($id); // Reload revisions as they have changed |
55
|
|
|
|
56
|
|
|
// Rebuild the revision timeline HTML and return it to the AJAX call |
57
|
|
|
// @TODO: Return only the latest revision to save bandwidth - 15/9/16 @se1exin |
58
|
|
|
return view($this->crud->getRevisionsTimelineView(), $this->data); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.