mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Add default licenses and license sync
This commit is contained in:
parent
072d55d1a8
commit
ea0fc90c92
3 changed files with 67 additions and 2 deletions
|
@ -22,6 +22,7 @@ use App\Http\Controllers\Settings\{
|
|||
SecuritySettings
|
||||
};
|
||||
use App\Jobs\DeletePipeline\DeleteAccountPipeline;
|
||||
use App\Jobs\MediaPipeline\MediaSyncLicensePipeline;
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
|
@ -274,11 +275,21 @@ class SettingsController extends Controller
|
|||
$license = $request->input('default');
|
||||
$sync = $request->input('sync') == 'on';
|
||||
$media_descriptions = $request->input('media_descriptions') == 'on';
|
||||
$uid = $request->user()->id;
|
||||
|
||||
$setting = UserSetting::whereUserId($request->user()->id)->firstOrFail();
|
||||
$setting = UserSetting::whereUserId($uid)->firstOrFail();
|
||||
$compose = json_decode($setting->compose_settings, true);
|
||||
$changed = false;
|
||||
|
||||
if($sync) {
|
||||
$key = 'pf:settings:mls_recently:'.$uid;
|
||||
if(Cache::get($key) == 2) {
|
||||
$msg = 'You can only sync licenses twice per 24 hours. Try again later.';
|
||||
return redirect(route('settings'))
|
||||
->with('error', $msg);
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($compose['default_license']) || $compose['default_license'] !== $license) {
|
||||
$compose['default_license'] = (int) $license;
|
||||
$changed = true;
|
||||
|
@ -295,6 +306,13 @@ class SettingsController extends Controller
|
|||
Cache::forget('profile:compose:settings:' . $request->user()->id);
|
||||
}
|
||||
|
||||
if($sync) {
|
||||
$val = Cache::has($key) ? 2 : 1;
|
||||
Cache::put($key, $val, 86400);
|
||||
MediaSyncLicensePipeline::dispatch($uid, $license);
|
||||
return redirect(route('settings'))->with('status', 'Media licenses successfully synced! It may take a few minutes to take effect for every post.');
|
||||
}
|
||||
|
||||
return redirect(route('settings'))->with('status', 'Media settings successfully updated!');
|
||||
}
|
||||
|
||||
|
|
47
app/Jobs/MediaPipeline/MediaSyncLicensePipeline.php
Normal file
47
app/Jobs/MediaPipeline/MediaSyncLicensePipeline.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\MediaPipeline;
|
||||
|
||||
use App\Media;
|
||||
use App\User;
|
||||
use Cache;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Services\StatusService;
|
||||
|
||||
class MediaSyncLicensePipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $userId;
|
||||
protected $licenseId;
|
||||
|
||||
public function __construct($userId, $licenseId)
|
||||
{
|
||||
$this->userId = $userId;
|
||||
$this->licenseId = $licenseId;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$licenseId = $this->licenseId;
|
||||
|
||||
if(!$licenseId || !$this->userId) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Media::whereUserId($this->userId)
|
||||
->chunk(100, function($medias) use($licenseId) {
|
||||
foreach($medias as $media) {
|
||||
$media->license = $licenseId;
|
||||
$media->save();
|
||||
Cache::forget('status:transformer:media:attachments:'. $media->status_id);
|
||||
StatusService::del($media->status_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
<div class="form-check pb-3">
|
||||
<input class="form-check-input" type="checkbox" name="sync">
|
||||
<label class="form-check-label font-weight-bold" for="">Sync Licenses</label>
|
||||
<p class="text-muted small help-text">Update existing posts with your new default license. You can sync once every 24 hours.</p>
|
||||
<p class="text-muted small help-text">Update existing posts with your new default license. You can sync twice every 24 hours.<br />License changes may not be reflected on remote servers.</p>
|
||||
</div>
|
||||
|
||||
<div class="form-check pb-3">
|
||||
|
|
Loading…
Reference in a new issue