Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/owlchester/kanka into ch…
Browse files Browse the repository at this point in the history
…aracter-private-families
  • Loading branch information
spitfire305 committed Jul 15, 2024
2 parents 9fbc648 + b6b2c6f commit b14299a
Show file tree
Hide file tree
Showing 205 changed files with 1,426 additions and 781 deletions.
19 changes: 11 additions & 8 deletions app/Console/Commands/Cleanup/CleanupTrashed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use App\Models\Entity;
use App\Models\Post;
use App\Services\RecoveryService;
use App\Services\Entity\PurgeService;
use App\Services\Posts\PurgeService as PostPurgeService;
use App\Traits\HasJobLog;
use Carbon\Carbon;
use Exception;
Expand Down Expand Up @@ -33,17 +34,19 @@ class CleanupTrashed extends Command
* The recovery service
*
*/
protected RecoveryService $service;
protected PurgeService $service;
protected PostPurgeService $postService;

/**
* Create a new command instance.
*
* @return void
*/
public function __construct(RecoveryService $service)
public function __construct(PurgeService $service, PostPurgeService $postService)
{
parent::__construct();
$this->service = $service;
$this->postService = $postService;
}

/**
Expand All @@ -54,14 +57,13 @@ public function handle()
{
$delay = Carbon::now()->subDays(config('entities.hard_delete'))->toDateString();
$log = '';
$this->info('Looking to purge entities and posts deleted since ' . $delay);

DB::beginTransaction();
try {
Entity::onlyTrashed()
->where('deleted_at', '<=', $delay)
->allCampaigns()
// chunkById allows us to safely delete elements in a chunk
// see https://stackoverflow.com/questions/32700537/eloquent-chunk-missing-half-the-results
->chunkById(1000, function ($entities): void {
$this->info('Chunk deleting ' . count($entities) . ' entities.');
foreach ($entities as $entity) {
Expand All @@ -73,8 +75,9 @@ public function handle()
->where('deleted_at', '<=', $delay)
->chunkById(1000, function ($posts): void {
$this->info('Chunk deleting ' . count($posts) . ' posts.');
/** @var Post $post */
foreach ($posts as $post) {
$this->service->trash($post);
$this->postService->trash($post);
}
});
DB::commit();
Expand All @@ -88,8 +91,8 @@ public function handle()
$this->info('Deleted ' . $this->service->count() . ' trashed entities.');
$log .= '<br />' . 'Deleted ' . $this->service->count() . ' trashed entities.';

$this->info('Deleted ' . $this->service->countPosts() . ' trashed posts.');
$log .= '<br />' . 'Deleted ' . $this->service->countPosts() . ' trashed posts.';
$this->info('Deleted ' . $this->postService->count() . ' trashed posts.');
$log .= '<br />' . 'Deleted ' . $this->postService->count() . ' trashed posts.';
$this->log($log);

return 0;
Expand Down
7 changes: 4 additions & 3 deletions app/Console/Commands/Cleanup/CleanupTrashedCampaigns.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ public function handle()
{
Campaign::observe(CampaignObserver::class);

$this->service->purgeDeleted();
$this->info('');
$this->info('Deleted ' . $this->service->count() . ' trashed campaigns.');
$count = $this->service->purgeDeleted();
$log = 'Deleted ' . $count . ' trashed campaigns.';
$this->info($log);
$this->log($log);

return 0;
}
Expand Down
56 changes: 56 additions & 0 deletions app/Console/Commands/Migrations/MigrateTutorials.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Console\Commands\Migrations;

use App\Models\Users\Tutorial;
use App\User;
use Illuminate\Console\Command;

class MigrateTutorials extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'users:migrate-tutorials';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Migrate user tutorial settings';

private $count = 0;
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
User::whereNotNull('settings')
->chunk(5000, function ($users): void {
/** @var User $user */
foreach ($users as $user) {
$this->count++;
$settings = $user->settings;

foreach ($settings as $key => $setting) {
if (str_starts_with($key, 'tutorial_')) {
$tutorial = new Tutorial();
$tutorial->user_id = $user->id;
$tutorial->code = mb_substr($key, 9);
$tutorial->save();
unset($settings[$key]);
}
}
$user->updateQuietly(['settings' => $settings]);
}
});

$this->info('Migrated ' . $this->count . ' user tutorials.');
return Command::SUCCESS;
}
}
13 changes: 9 additions & 4 deletions app/Console/Commands/Migrations/NewsletterSubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ public function handle()
{
$this->service = app()->make(NewsletterService::class);
User::whereNotNull('pledge')
->where('pledge', '<>', '')
->where('settings', 'like', '%mail_release%')
->chunk(500, function ($users) {
->chunk(100, function ($users) {
foreach ($users as $user) {
if (!$user->mail_release) {
continue;
}
$options = [
'releases' => (bool) $user->mail_release
];
$this->service->user($user)->update($options);
$this->count++;
if ($this->service->user($user)->update($options)) {
$this->count++;
continue;
}
$this->error($this->service->error()->getMessage());
}
sleep(60);
});

$this->info('Processes ' . $this->count . ' users.');
$this->info('Processed ' . $this->count . ' users.');
}
}
6 changes: 6 additions & 0 deletions app/Console/Commands/Subscriptions/MigrateSubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands\Subscriptions;

use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Laravel\Cashier\Subscription;

class MigrateSubscriptions extends Command
Expand Down Expand Up @@ -34,6 +35,7 @@ public function handle()
Subscription::with(['user', 'user.subscriptions', 'user.subscriptions.owner'])
->where('stripe_status', 'active')
->whereIn('stripe_price', $old)
->whereNotIn('user_id', [177165, 200759])
->has('user')
->chunkById(200, function ($subs) {
if ($this->count > $this->limit) {
Expand All @@ -43,6 +45,10 @@ public function handle()
if ($this->count > $this->limit) {
return false;
}
// Don't touch sofort people
if (Str::startsWith($s->stripe_id, 'sofort_')) {
continue;
}
$this->info('User #' . $s->user->id . ' ' . $s->user->email . ' https://dashboard.stripe.com/customers/' . $s->user->stripe_id);
try {
$old = $s->stripe_price;
Expand Down
26 changes: 26 additions & 0 deletions app/Facades/Images.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Facades;

use App\Services\ImagesService;
use Illuminate\Support\Facades\Facade;

/**
* Class Img
* @package App\Facades
*
* @see ImagesService
* @mixin ImagesService
*/
class Images extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'images';
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/v1/EntityImageApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Http\Requests\API\UploadEntityImage;
use App\Models\Campaign;
use App\Models\Entity;
use App\Services\ImageService;
use App\Facades\Images;

class EntityImageApiController extends Controller
{
Expand All @@ -17,7 +17,7 @@ public function put(UploadEntityImage $request, Campaign $campaign, Entity $enti
$this->authorize('update', $entity->child);

// Let the service handle everything
ImageService::handle($entity);
Images::handle($entity);
$entity->update();

return response()->json([
Expand All @@ -38,7 +38,7 @@ public function destroy(Campaign $campaign, Entity $entity)
$this->authorize('update', $entity->child);

// Let the service handle everything
ImageService::cleanup($entity);
Images::cleanup($entity);

$entity->update(['image_path' => '']);

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/v1/EntityRecoveryApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Models\Campaign;
use App\Http\Resources\EntityResource as Resource;
use App\Http\Requests\RecoverEntity as Request;
use App\Services\RecoveryService;
use App\Services\Entity\RecoveryService;

class EntityRecoveryApiController extends ApiController
{
Expand Down Expand Up @@ -42,6 +42,6 @@ public function recover(Request $request, Campaign $campaign)
}
$this->service->recover($request->entities);

return response()->json(['success' => 'Succesfully recovered deleted entities']);
return response()->json(['success' => 'Successfully recovered deleted entities']);
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/v1/PostRecoveryApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Models\Campaign;
use App\Http\Resources\PostResource as Resource;
use App\Http\Requests\RecoverPost as Request;
use App\Services\RecoveryService;
use App\Services\Posts\RecoveryService;

class PostRecoveryApiController extends ApiController
{
Expand Down Expand Up @@ -40,8 +40,8 @@ public function recover(Request $request, Campaign $campaign)
if (!$campaign->boosted()) {
return response()->json(null, 204);
}
$this->service->recoverPosts($request->posts);
$this->service->recover($request->posts);

return response()->json(['success' => 'Succesfully recovered deleted posts']);
return response()->json(['success' => 'Successfully recovered deleted posts']);
}
}
4 changes: 3 additions & 1 deletion app/Http/Controllers/Campaign/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ public function back(Campaign $campaign)
}

/**
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function updateRoles(Campaign $campaign, CampaignUser $campaignUser, CampaignRole $campaignRole)
{
$this->authorize('update', $campaignUser);
if (request()->ajax()) {
return response()->json();
}

try {
$added = $this->service->update($campaignUser, $campaignRole);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Campaign/PostRecoveryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Facades\Datagrid;
use App\Http\Controllers\Controller;
use App\Models\Campaign;
use App\Services\RecoveryService;
use App\Services\Posts\RecoveryService;
use Carbon\Carbon;
use Exception;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -64,7 +64,7 @@ public function recover(Request $request, Campaign $campaign)
}

try {
$count = $this->service->recoverPosts($request->get('model', []));
$count = $this->service->recover($request->get('model', []));
return redirect()
->route('recovery.posts', $campaign)
->with('success', trans_choice('campaigns/recovery.posts.success', $count, ['count' => $count]));
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Campaign/RecoveryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Http\Controllers\Controller;
use App\Models\Campaign;
use App\Models\Entity;
use App\Services\RecoveryService;
use App\Services\Entity\RecoveryService;
use Carbon\Carbon;
use Exception;
use Illuminate\Http\Request;
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/Crud/CampaignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ public function update(UpdateCampaign $request, Campaign $campaign)
public function destroy(DeleteCampaign $request, Campaign $campaign)
{
$this->authorize('delete', $campaign);
if ($request->ajax()) {
return response()->json();
}

$this->deletionService
->campaign($campaign)
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Entity/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function storeFile(StoreEntityAsset $request, Campaign $campaign, Enti
$file = $service
->entity($entity)
->campaign($campaign)
->upload($request);
->upload($request, 'file', 'w/' . $campaign->id . '/entity-assets');

return redirect()
->route('entities.entity_assets.index', [$campaign, $entity])
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Entity/AttributeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function save(Campaign $campaign, Entity $entity)
$this->authorize('attribute', [$entity->child, 'edit']);
$this->authorize('attributes', $entity);

$attributes = request()->get('attribute');
$attributes = request()->get('attribute', []);

$this->service
->entity($entity)
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Entity/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Http\Requests\UpdateEntityImage;
use App\Models\Campaign;
use App\Models\Entity;
use App\Services\ImageService;
use App\Facades\Images;

class ImageController extends Controller
{
Expand Down Expand Up @@ -77,7 +77,7 @@ public function update(UpdateEntityImage $request, Campaign $campaign, Entity $e
} else {
$entity->image_uuid = null;
}
ImageService::entity($entity, 'w/' . $entity->campaign_id, 'image');
Images::entity($entity, 'w/' . $entity->campaign_id, 'image');
// New image requires a focus reset
if ($entity->isDirty(['image_uuid', 'image_path'])) {
$entity->focus_x = null;
Expand Down
Loading

0 comments on commit b14299a

Please sign in to comment.