Skip to content

Commit

Permalink
Bugs fixed
Browse files Browse the repository at this point in the history
- Users could not purchase item at 0 cost with no currency on hand
- Missing loot table pagination in admin panel
- Previous submissions field on submissions page not counting correctly
- Error uploading character image for a character belonging to an offsite user

Misc
- Dropped internal tracking of users' character/MYO slot counts as they weren't being displayed and would be inaccurate depending on your viewing permissions
  • Loading branch information
corowne committed May 2, 2020
1 parent 045154d commit aa7dd83
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getSubmission($id)
'items' => Item::orderBy('name')->pluck('name', 'id'),
'currencies' => Currency::where('is_user_owned', 1)->orderBy('name')->pluck('name', 'id'),
'tables' => LootTable::orderBy('name')->pluck('name', 'id'),
'count' => Submission::where('prompt_id', $id)->where('status', 'Approved')->where('user_id', $submission->user_id)->count()
'count' => Submission::where('prompt_id', $submission->prompt_id)->where('status', 'Approved')->where('user_id', $submission->user_id)->count()
] : []));
}

Expand Down
1 change: 0 additions & 1 deletion app/Models/Character/Character.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ public function updateOwner()
$this->save();

$owner->settings->is_fto = 0;
$owner->settings->character_count++;
$owner->settings->save();
}
}
Expand Down
5 changes: 0 additions & 5 deletions app/Models/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,9 @@ public function updateCharacters()
'user_id' => $this->id
])) {
$count = $this->characters->count();
$myoCount = $this->myoSlots->count();
if($count || $$myoCount) {
if($count) {
$this->settings->is_fto = 0;
$this->settings->character_count = $count;
}
if($myoCount) {
$this->settings->myo_slot_count = $myoCount;
}
$this->settings->save();
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/User/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UserSettings extends Model
* @var array
*/
protected $fillable = [
'is_fto', 'character_count', 'myo_slot_count', 'submission_count', 'banned_at', 'ban_reason'
'is_fto', 'submission_count', 'banned_at', 'ban_reason'
];

/**
Expand Down
17 changes: 3 additions & 14 deletions app/Services/CharacterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ public function createCharacter($data, $user, $isMyo = false)
if($recipient) {
if(!$isMyo) {
$recipient->settings->is_fto = 0; // MYO slots don't affect the FTO status - YMMV
$recipient->settings->character_count++;
}
else $recipient->settings->myo_slot_count++;
$recipient->settings->save();
}

Expand Down Expand Up @@ -404,8 +402,8 @@ public function createImage($data, $character, $user)

// Add a log for the character
// This logs all the updates made to the character
$this->createLog($user->id, null, $character->user_id, $character->user->alias, $character->id, 'Character Image Uploaded', '[#'.$image->id.']', 'character');

$this->createLog($user->id, null, $character->user_id, $character->user_id ? $character->user->alias : $character->owner_alias, $character->id, 'Character Image Uploaded', '[#'.$image->id.']', 'character');
// If the recipient has an account, send them a notification
if($character->user && $user->id != $character->user_id && $character->is_visible) {
Notifications::create('IMAGE_UPLOAD', $character->user, [
Expand Down Expand Up @@ -1026,7 +1024,6 @@ public function deleteCharacter($character, $user)

try {
if($character->user_id) {
$character->user->settings->{$character->is_myo_slot ? 'myo_slot_count' : 'character_count'}--;
$character->user->settings->save();
}

Expand Down Expand Up @@ -1355,17 +1352,11 @@ public function moveCharacter($character, $recipient, $data, $cooldown = -1, $lo

// Update character counts if the sender has an account
if($sender) {
if($character->is_myo_slot) $sender->settings->myo_slot_count--;
else $sender->settings->character_count--;
$sender->settings->save();
}

if(is_object($recipient)) {
if($character->is_myo_slot) $recipient->settings->myo_slot_count++;
else {
$recipient->settings->character_count++;
$recipient->settings->is_fto = 0;
}
if(!$character->is_myo_slot) $recipient->settings->is_fto = 0;
$recipient->settings->save();
}

Expand Down Expand Up @@ -1864,8 +1855,6 @@ public function approveRequest($data, $request, $user)
{
$request->character->is_myo_slot = 0;
$request->user->settings->is_fto = 0;
$request->user->settings->myo_slot_count--;
$request->user->settings->character_count++;
$request->user->settings->save();
}
$request->character->save();
Expand Down
2 changes: 1 addition & 1 deletion app/Services/ShopManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function buyStock($data, $user)
// - currency must be user-held
// - user has enough currency
if(!$shopStock->use_user_bank || !$shopStock->currency->is_user_owned) throw new \Exception("You cannot use your user bank to pay for this item.");
if(!(new CurrencyManager)->debitCurrency($user, null, 'Shop Purchase', 'Purchased '.$shopStock->item->name.' from '.$shop->name, $shopStock->currency, $shopStock->cost)) throw new \Exception("Not enough currency to make this purchase.");
if($shopStock->cost > 0 && !(new CurrencyManager)->debitCurrency($user, null, 'Shop Purchase', 'Purchased '.$shopStock->item->name.' from '.$shop->name, $shopStock->currency, $shopStock->cost)) throw new \Exception("Not enough currency to make this purchase.");
}

// If the item has a limited quantity, decrease the quantity
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

use App\Models\User\User;

class DropCharacterMyoCounts extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// This count is not being used anywhere and is inaccurate
// depending on your viewing permissions
Schema::table('user_settings', function(Blueprint $table) {
$table->dropColumn('character_count');
$table->dropColumn('myo_slot_count');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::table('user_settings', function(Blueprint $table) {
$table->integer('character_count')->unsigned()->default(0);
$table->integer('myo_slot_count')->unsigned()->default(0);
});

$users = User::all();
foreach($users as $user) {
$user->settings->character_count = $user->characters->count();
$user_settings->myo_slot_count = $user->myoSlots->count();
$user->settings->save();
}
}
}
2 changes: 2 additions & 0 deletions resources/views/admin/loot_tables/loot_tables.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@if(!count($tables))
<p>No loot tables found.</p>
@else
{!! $tables->render() !!}
<table class="table table-sm">
<thead>
<tr>
Expand All @@ -36,6 +37,7 @@
</tbody>

</table>
{!! $tables->render() !!}
@endif

@endsection
1 change: 0 additions & 1 deletion resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

<div class="col-md-6">
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required autofocus>

@if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
Expand Down

0 comments on commit aa7dd83

Please sign in to comment.