1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Http\Controllers\CrudFeatures; |
4
|
|
|
|
5
|
|
|
trait Revisions { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Display the revisions for specified resource. |
9
|
|
|
* |
10
|
|
|
* @param int $id |
11
|
|
|
* |
12
|
|
|
* @return Response |
|
|
|
|
13
|
|
|
*/ |
14
|
|
View Code Duplication |
public function listRevisions($id) |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
$this->crud->hasAccessOrFail('revisions'); |
|
|
|
|
17
|
|
|
|
18
|
|
|
// get the info for that entry |
19
|
|
|
$this->data['entry'] = $this->crud->getEntry($id); |
|
|
|
|
20
|
|
|
$this->data['crud'] = $this->crud; |
21
|
|
|
$this->data['title'] = ucfirst($this->crud->entity_name).' '.trans('backpack::crud.revisions'); |
22
|
|
|
$this->data['id'] = $id; |
23
|
|
|
$this->data['revisions'] = $this->crud->listRevisions($id); |
24
|
|
|
|
25
|
|
|
// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
26
|
|
|
return view('crud::revisions', $this->data); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Restore a specific revision for the specified resource. |
31
|
|
|
* |
32
|
|
|
* Used via AJAX in the revisions view |
33
|
|
|
* |
34
|
|
|
* @param int $id |
35
|
|
|
* |
36
|
|
|
* @return JSON Response containing the new revision that was created from the update |
37
|
|
|
* @return HTTP 500 if the request did not contain the revision ID |
|
|
|
|
38
|
|
|
*/ |
39
|
|
|
public function restoreRevision($id) |
40
|
|
|
{ |
41
|
|
|
$this->crud->hasAccessOrFail('revisions'); |
42
|
|
|
|
43
|
|
|
// @TODO: Currently the route already contains the revision ID, so passing it as a POST param |
44
|
|
|
// is somewhat superfluous.. however if we are POSTing, it makes sense to actually have data to post. |
45
|
|
|
// Perhaps the route shoud be better named to reflect this (e.g. just /model/{id}/revisions) (??) |
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('crud::inc.revision_timeline', $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.