Skip to content

Commit

Permalink
Improve the Content module
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyCyborg committed Jan 3, 2020
1 parent 586dbdc commit fab022b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/Platform/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Define The Application Version
//--------------------------------------------------------------------------

define('VERSION', '1.1.8');
define('VERSION', '1.1.9');

//--------------------------------------------------------------------------
// Set PHP Error Reporting Options
Expand Down
17 changes: 13 additions & 4 deletions modules/Content/Controllers/Admin/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public function update(Request $request, $id)

$count++;

$slug = $post->id .'-revision-v' .$count;
$slug = sprintf('%d-revision-v%d', $post->id, $count);

$revision = Post::create(array(
'content' => $post->content,
Expand All @@ -393,14 +393,16 @@ public function update(Request $request, $id)
'password' => $post->password,
'name' => $slug,
'parent_id' => $post->id,
'guid' => site_url('content/' .$slug),
'guid' => site_url($slug),
'menu_order' => $post->menu_order,
'type' => 'revision',
'mime_type' => $post->mime_type,
'author_id' => $authUser->id,
'comment_status' => 'closed',
));

$post->saveMeta('version', $count);

// Fire the finishing event.
Event::dispatch('content.post.updated', array($post, $creating));

Expand All @@ -424,7 +426,7 @@ public function update(Request $request, $id)
public function destroy($id)
{
try {
$post = Post::findOrFail($id);
$post = Post::with('revisions', 'taxonomies')->findOrFail($id);
}
catch (ModelNotFoundException $e) {
return Redirect::back()->with('danger', __d('content', 'Record not found: #{0}', $id));
Expand All @@ -435,14 +437,21 @@ public function destroy($id)
// Fire the starting event.
Event::dispatch('content.post.deleting', array($post));

// Delete the Post.
// Delete first the Post Revisions.
$post->revisions->each(function ($revision)
{
$revision->delete();
});

// Detach the associated Taxonomies.
$post->taxonomies()->detach();

$post->taxonomies->each(function ($taxonomy)
{
$taxonomy->updateCount();
});

// Finally, delete the Post.
$post->delete();

// Fire the finishing event.
Expand Down
25 changes: 15 additions & 10 deletions modules/Content/Controllers/Admin/Revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ protected function destroy($id)

$post = $revision->parent()->first();

if (preg_match('#^(?:\d+)-revision-v(\d+)$#', $revision->name, $matches) !== 1) {
$version = 0;
} else {
if (preg_match('#^(?:\d+)-revision-v(\d+)$#', $revision->name, $matches) === 1) {
$version = (int) $matches[1];
} else {
$version = 0;
}

$revision->delete();
Expand All @@ -74,20 +74,25 @@ public function restore($id)

$post = $revision->parent()->first();

// Restore the Post's title, content and excerpt.
$post->content = $revision->content;
$post->excerpt = $revision->excerpt;
$post->title = $revision->title;
// Restore the parent Post from Revision variables.
$post->content = $revision->content;
$post->excerpt = $revision->excerpt;
$post->title = $revision->title;
$post->password = $revision->password;
$post->menu_order = $revision->menu_order;
$post->mime_type = $revision->mime_type;

$post->save();

// Handle the MetaData.
if (preg_match('#^(?:\d+)-revision-v(\d+)$#', $revision->name, $matches) !== 1) {
$version = 0;
if (preg_match('#^(?:\d+)-revision-v(\d+)$#', $revision->name, $matches) === 1) {
$version = (int) $matches[1];
} else {
$post->saveMeta('version', $version = (int) $matches[1]);
$version = 0;
}

$post->saveMeta('version', $version);

// Invalidate the content caches.
Cache::section('content')->flush();

Expand Down
5 changes: 2 additions & 3 deletions modules/Content/Routes/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@
Route::post('content/{id}/revisions', 'Revisions@destroy');
Route::post('content/{id}/restore', 'Revisions@restore');

// The Post editor's Tags management
Route::group(array('namespace' => 'Editor'), function ()
{
Route::post('content/{id}/tags', 'Tags@attach');

// The Editor's Tags management
Route::post('content/{id}/tags', 'Tags@attach');
Route::post('content/{id}/tags/{tagId}/detach', 'Tags@detach')->where('tagId', '(\d+)');
});

Expand Down

0 comments on commit fab022b

Please sign in to comment.