Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #30 from herpaderpaldent/development
Browse files Browse the repository at this point in the history
Merge `fix-job-issue`
  • Loading branch information
herpaderpaldent authored Sep 29, 2018
2 parents abdc5b1 + 524a7ed commit ba1325f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Version 1.3.4
Improvements on `GroupSync` and some UI improvements
* Merged pull request of @warlof aiming to improve `GroupSync` job with inconsistent user_groups. Namely when a main_character is missing (which should not happen anyway). Also some logging and tagging of the job was improved.
* Open-Group showed two join-buttons. Which is now fixed. Thank you @Anduriel for reporting this
* Action buttons in managed group modal collapsed in each other for large user_groups (many users). Bootstrap classes have been added to account for such cases. Thank you @Anduriel and @warlof for reporting this.

# Version 1.3.3
Some smaller improvements and bugfixes
* Improving `php artisan seat-groups:users:update --character_ids=ID` based on community feedback. Thank you @warlof for reporting this.
Expand Down
19 changes: 19 additions & 0 deletions src/Exceptions/MissingMainCharacterException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php


namespace Herpaderpaldent\Seat\SeatGroups\Jobs;


use Exception;
use Seat\Web\Models\Group;

class MissingMainCharacterException extends Exception
{
public function __construct(Group $group)
{
$message = sprintf('The group with ID %d does not have a main character set, ' .
'or related character information is missing.', $group->id);

parent::__construct($message, 0, null);
}
}
44 changes: 33 additions & 11 deletions src/Jobs/GroupSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ class GroupSync extends SeatGroupsJobBase
*/
protected $tags = ['sync'];

/**
* @var \Seat\Web\Models\Group
*/
private $group;

/**
* @var \Seat\Eveapi\Models\Character\CharacterInfo
*/
private $main_character;

/**
* @var int
*/
Expand All @@ -36,18 +44,32 @@ class GroupSync extends SeatGroupsJobBase
*/
public function __construct(Group $group)
{

logger()->debug('Initialising SeAT Group sync for ' . $group->main_character->name);

$this->group = $group;
$this->main_character = $group->main_character;
if (is_null($group->main_character)) {
logger()->warning('Group has no main character set. Attempt to make assignation based on first attached character.', [
'group_id' => $group->id,
]);
$this->main_character = $group->users->first()->character;
}

array_push($this->tags, 'main_character_id:' . $group->main_character_id);
// avoid the construct to throw an exception if no character has been set
if (! is_null($this->main_character)) {
logger()->debug('Initialising SeAT Group sync for ' . $this->main_character->name);

array_push($this->tags, sprintf('users: %s',
$this->group->users->map(function($user) { return $user->name; })->implode(', ')));
}

}

public function handle()
{
Redis::funnel('seat-groups:jobs.group_sync_'.$this->group->main_character_id)->limit(1)->then(function ()
// in case no main character has been set, throw an exception and abort the process
if (is_null($this->main_character))
throw new MissingMainCharacterException($this->group);

Redis::funnel('seat-groups:jobs.group_sync_'.$this->group->id)->limit(1)->then(function ()
{
$this->beforeStart();

Expand All @@ -70,7 +92,7 @@ public function handle()
foreach ($seat_group->role as $role) {
$roles->push($role->id);
}
if(!in_array($group->id,$seat_group->group->pluck('id')->toArray())){
if(!in_array($group->id, $seat_group->group->pluck('id')->toArray())){
// add user_group to seat_group as member if no member yet.
$seat_group->member()->attach($group->id);
}
Expand All @@ -95,7 +117,7 @@ public function handle()

$this->onFinish();

logger()->debug('Group has beend synced for '. $this->group->main_character->name);
logger()->debug('Group has beend synced for '. $this->main_character->name);

} catch (\Throwable $exception) {

Expand All @@ -105,7 +127,7 @@ public function handle()

}, function ()
{
logger()->warning('A GroupSync job is already running for ' . $this->group->main_character->name . ' Removing the job from the queue.');
logger()->warning('A GroupSync job is already running for ' . $this->main_character->name . ' Removing the job from the queue.');

$this->delete();
});
Expand All @@ -129,7 +151,7 @@ public function beforeStart()
SeatgroupLog::create([
'event' => 'warning',
'message' => sprintf('The RefreshToken of %s is missing, therefore user group of %s (%s) loses all permissions.',
$user->name, $this->group->main_character->name, $this->group->users->map(function($user) { return $user->name; })->implode(', '))
$user->name, $this->main_character->name, $this->group->users->map(function($user) { return $user->name; })->implode(', '))

]);

Expand All @@ -147,7 +169,7 @@ public function onFail($exception)
SeatgroupLog::create([
'event' => 'error',
'message' => sprintf('An error occurred while syncing user group of %s (%s). Please check the logs.',
$this->group->main_character->name, $this->group->users->map(function($user) { return $user->name; })->implode(', '))
$this->main_character->name, $this->group->users->map(function($user) { return $user->name; })->implode(', '))

]);

Expand All @@ -158,7 +180,7 @@ public function onFinish()
SeatgroupLog::create([
'event' => 'success',
'message' => sprintf('The user group of %s (%s) has successfully been synced.',
$this->group->main_character->name, $this->group->users->map(function($user) { return $user->name; })->implode(', '))
$this->main_character->name, $this->group->users->map(function($user) { return $user->name; })->implode(', '))

]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/seatgroups.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 10:24
*/
return [
'version' => '1.3.3'
'version' => '1.3.4'
];

//TODO: Update Version

0 comments on commit ba1325f

Please sign in to comment.