Skip to content

Commit

Permalink
#182 added user activity update when saving a post in the guestbook
Browse files Browse the repository at this point in the history
  • Loading branch information
simba77 committed Jan 10, 2022
1 parent a25274e commit 4270b6f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class AddGuestbookPostsColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$schema = Capsule::schema();
if (! $schema->hasColumn('user_activity', 'guestbook_posts')) {
$schema->table('user_activity', function (Blueprint $table) {
$table->bigInteger('guestbook_posts')->nullable();
});
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$schema = Capsule::schema();
if ($schema->hasColumn('user_activity', 'guestbook_posts')) {
$schema->dropColumns('user_activity', ['guestbook_posts']);
}
}
}
17 changes: 6 additions & 11 deletions modules/johncms/guestbook/src/Services/GuestbookService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Johncms\Http\Session;
use Johncms\Settings\SiteSettings;
use Johncms\Users\User;
use Johncms\Users\UserManager;
use Johncms\Validator\Validator;
use League\Flysystem\FilesystemException;
use Mobicms\Captcha\Code;
Expand Down Expand Up @@ -150,17 +151,11 @@ public function create(): Guestbook
'attached_files' => $fields['attached_files'],
]
);
/*if ($this->user) {
$post_guest = $this->user->postguest + 1;
(new User())
->where('id', $this->user->id)
->update(
[
'postguest' => $post_guest,
'lastpost' => time(),
]
);
}*/
if ($this->user) {
// Update user activity
$userManager = di(UserManager::class);
$userManager->incrementActivity($this->user, 'guestbook_posts');
}
} else {
throw ValidationException::withErrors($validator->getErrors());
}
Expand Down

0 comments on commit 4270b6f

Please sign in to comment.