Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2015-10-18 19:40:33 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
3fd2613ab7f8c74a1f1bb417367f68d34489caf1
3fd2613a
1 parent
8ea75b0f
Prevent revision encoding issues
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
24 deletions
app/Http/Controllers/PageController.php
app/Repos/PageRepo.php
resources/views/base.blade.php
app/Http/Controllers/PageController.php
View file @
3fd2613
...
...
@@ -196,13 +196,19 @@ class PageController extends Controller
return
view
(
'pages/revision'
,
[
'page'
=>
$page
,
'book'
=>
$book
]);
}
/**
* Restores a page using the content of the specified revision.
* @param $bookSlug
* @param $pageSlug
* @param $revisionId
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public
function
restoreRevision
(
$bookSlug
,
$pageSlug
,
$revisionId
)
{
$this
->
checkPermission
(
'page-update'
);
$book
=
$this
->
bookRepo
->
getBySlug
(
$bookSlug
);
$page
=
$this
->
pageRepo
->
getBySlug
(
$pageSlug
,
$book
->
id
);
$revision
=
$this
->
pageRepo
->
getRevisionById
(
$revisionId
);
$page
=
$this
->
pageRepo
->
updatePage
(
$page
,
$book
->
id
,
$revision
->
toArray
());
$page
=
$this
->
pageRepo
->
restoreRevision
(
$page
,
$book
,
$revisionId
);
Activity
::
add
(
$page
,
'page_restore'
,
$book
->
id
);
return
redirect
(
$page
->
getUrl
());
}
...
...
app/Repos/PageRepo.php
View file @
3fd2613
...
...
@@ -82,7 +82,6 @@ class PageRepo
$page
->
updated_by
=
auth
()
->
user
()
->
id
;
$book
->
pages
()
->
save
(
$page
);
$this
->
saveRevision
(
$page
);
return
$page
;
}
...
...
@@ -202,13 +201,37 @@ class PageRepo
*/
public
function
updatePage
(
Page
$page
,
$book_id
,
$input
)
{
// Save a revision before updating
if
(
$page
->
html
!==
$input
[
'html'
]
||
$page
->
name
!==
$input
[
'name'
])
{
$this
->
saveRevision
(
$page
);
}
// Update with new details
$page
->
fill
(
$input
);
$page
->
slug
=
$this
->
findSuitableSlug
(
$page
->
name
,
$book_id
,
$page
->
id
);
$page
->
html
=
$this
->
formatHtml
(
$input
[
'html'
]);
$page
->
text
=
strip_tags
(
$page
->
html
);
$page
->
updated_by
=
Auth
::
user
()
->
id
;
$page
->
updated_by
=
auth
()
->
user
()
->
id
;
$page
->
save
();
return
$page
;
}
/**
* Restores a revision's content back into a page.
* @param Page $page
* @param Book $book
* @param int $revisionId
* @return Page
*/
public
function
restoreRevision
(
Page
$page
,
Book
$book
,
$revisionId
)
{
$this
->
saveRevision
(
$page
);
$revision
=
$this
->
getRevisionById
(
$revisionId
);
$page
->
fill
(
$revision
->
toArray
());
$page
->
slug
=
$this
->
findSuitableSlug
(
$page
->
name
,
$book
->
id
,
$page
->
id
);
$page
->
text
=
strip_tags
(
$page
->
html
);
$page
->
updated_by
=
auth
()
->
user
()
->
id
;
$page
->
save
();
return
$page
;
}
...
...
@@ -217,15 +240,12 @@ class PageRepo
* @param Page $page
* @return $this
*/
p
ublic
function
saveRevision
(
Page
$page
)
p
rivate
function
saveRevision
(
Page
$page
)
{
$lastRevision
=
$this
->
getLastRevision
(
$page
);
if
(
$lastRevision
&&
(
$lastRevision
->
html
===
$page
->
html
&&
$lastRevision
->
name
===
$page
->
name
))
{
return
$page
;
}
$revision
=
$this
->
pageRevision
->
fill
(
$page
->
toArray
());
$revision
->
page_id
=
$page
->
id
;
$revision
->
created_by
=
Auth
::
user
()
->
id
;
$revision
->
created_by
=
auth
()
->
user
()
->
id
;
$revision
->
created_at
=
$page
->
updated_at
;
$revision
->
save
();
// Clear old revisions
if
(
$this
->
pageRevision
->
where
(
'page_id'
,
'='
,
$page
->
id
)
->
count
()
>
50
)
{
...
...
@@ -236,17 +256,6 @@ class PageRepo
}
/**
* Gets the most recent revision for a page.
* @param Page $page
* @return mixed
*/
public
function
getLastRevision
(
Page
$page
)
{
return
$this
->
pageRevision
->
where
(
'page_id'
,
'='
,
$page
->
id
)
->
orderBy
(
'created_at'
,
'desc'
)
->
first
();
}
/**
* Gets a single revision via it's id.
* @param $id
* @return mixed
...
...
@@ -266,12 +275,17 @@ class PageRepo
public
function
doesSlugExist
(
$slug
,
$bookId
,
$currentId
=
false
)
{
$query
=
$this
->
page
->
where
(
'slug'
,
'='
,
$slug
)
->
where
(
'book_id'
,
'='
,
$bookId
);
if
(
$currentId
)
{
$query
=
$query
->
where
(
'id'
,
'!='
,
$currentId
);
}
if
(
$currentId
)
$query
=
$query
->
where
(
'id'
,
'!='
,
$currentId
);
return
$query
->
count
()
>
0
;
}
/**
* Sets the book id for the specified page.
* Changes the book id of any relations to the page that store the book id.
* @param int $bookId
* @param Page $page
* @return Page
*/
public
function
setBookId
(
$bookId
,
Page
$page
)
{
$page
->
book_id
=
$bookId
;
...
...
resources/views/base.blade.php
View file @
3fd2613
...
...
@@ -6,6 +6,7 @@
<!-- Meta-->
<meta
name=
"viewport"
content=
"width=device-width"
>
<meta
name=
"token"
content=
"{{ csrf_token() }}"
>
<meta
charset=
"utf-8"
>
<!-- Styles and Fonts -->
<link
rel=
"stylesheet"
href=
"/css/styles.css"
>
...
...
Please
register
or
sign in
to post a comment