Skip to content

Enabled published posts #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Console/Commands/Cleanup/DeleteOldUnverifiedUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle()

if ($query->get()->isNotEmpty()) {
foreach ($query->get() as $user) {
$user->notify((new SendEMailToDeletedUser())->delay(now()->addMinute(5)));
$user->notify((new SendEMailToDeletedUser())->delay(now()->addMinutes(5)));
}
}

Expand Down
31 changes: 31 additions & 0 deletions app/Console/Commands/PublishArticles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Console\Commands;

use App\Models\Article;
use Illuminate\Console\Command;

class PublishArticles extends Command
{
protected $signature = 'lcm:publish-articles';

protected $description = 'Published all articles already submitted and approved';

public function handle(): void
{
$this->info('Published all submitted articles...');

$articles = Article::submitted()->approved()->whereNull('published_at')->get();

foreach ($articles as $article) {
$article->published_at = $article->submitted_at;
$article->save();
}

$count = $articles->count();

$this->comment("Published {$count} articles.");

$this->info('All done!');
}
}
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('media-library:delete-old-temporary-uploads')->daily();
// $schedule->command('media-library:delete-old-temporary-uploads')->daily();
$schedule->command('lcm:delete-old-unverified-users')->daily();
$schedule->command('lcm:post-article-to-twitter')->twiceDaily(12, 16);
$schedule->command('lcm:post-article-to-telegram')->everyFourHours();
Expand Down
1 change: 1 addition & 0 deletions app/Http/Livewire/Articles/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function store()
'title' => $this->title,
'slug' => $this->slug,
'body' => $this->body,
'published_at' => $this->published_at,
'submitted_at' => $this->submitted_at,
'approved_at' => $this->approved_at,
'show_toc' => $this->show_toc,
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Livewire/Articles/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function mount(Article $article)
$this->slug = $article->slug;
$this->show_toc = $article->show_toc;
$this->submitted_at = $article->submitted_at;
$this->published_at = $article->published_at ? $article->publishedAt()->format('Y-m-d') : null;
$this->canonical_url = $article->originalUrl();
$this->preview = $article->getFirstMediaUrl('media');
$this->associateTags = $this->tags_selected = old('tags', $article->tags()->pluck('id')->toArray());
Expand Down Expand Up @@ -66,6 +67,7 @@ public function save()
'show_toc' => $this->show_toc,
'canonical_url' => $this->canonical_url,
'submitted_at' => $this->submitted_at,
'published_at' => $this->published_at,
]);

$this->article->syncTags($this->associateTags);
Expand Down
25 changes: 17 additions & 8 deletions app/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
'declined_at',
'shared_at',
'sponsored_at',
'published_at',
];

/**
Expand All @@ -62,6 +63,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
'declined_at' => 'datetime',
'shared_at' => 'datetime',
'sponsored_at' => 'datetime',
'published_at' => 'datetime',
'show_toc' => 'boolean',
'is_pinned' => 'boolean',
];
Expand Down Expand Up @@ -150,6 +152,11 @@ public function sponsoredAt(): ?Carbon
return $this->sponsored_at;
}

public function publishedAt(): ?Carbon
{
return $this->published_at;
}

public function isSubmitted(): bool
{
return ! $this->isNotSubmitted();
Expand Down Expand Up @@ -192,12 +199,12 @@ public function isNotDeclined(): bool

public function isPublished(): bool
{
return ! $this->isNotPublished();
return ! $this->isNotPublished() && ($this->publishedAt() && $this->publishedAt()->lessThanOrEqualTo(now()));
}

public function isNotPublished(): bool
{
return $this->isNotSubmitted() || $this->isNotApproved();
return ($this->isNotSubmitted() || $this->isNotApproved()) && $this->published_at === null;
}

public function isPinned(): bool
Expand Down Expand Up @@ -249,7 +256,8 @@ public function scopeAwaitingApproval(Builder $query): Builder

public function scopePublished(Builder $query): Builder
{
return $query->submitted()
return $query->whereDate('published_at', '<=', now())
->submitted()
->approved();
}

Expand All @@ -258,6 +266,7 @@ public function scopeNotPublished(Builder $query): Builder
return $query->where(function ($query) {
$query->whereNull('submitted_at')
->orWhereNull('approved_at')
->orWhereNull('published_at')
->orWhereNotNull('declined_at');
});
}
Expand Down Expand Up @@ -300,14 +309,14 @@ public function scopeNotDeclined(Builder $query): Builder
public function scopeRecent(Builder $query): Builder
{
return $query->orderBy('is_pinned', 'desc')
->orderBy('submitted_at', 'desc');
->orderBy('published_at', 'desc');
}

public function scopePopular(Builder $query): Builder
{
return $query->withCount('reactions')
->orderBy('reactions_count', 'desc')
->orderBy('submitted_at', 'desc');
->orderBy('published_at', 'desc');
}

public function scopeTrending(Builder $query): Builder
Expand All @@ -316,7 +325,7 @@ public function scopeTrending(Builder $query): Builder
$query->where('created_at', '>=', now()->subWeek());
}])
->orderBy('reactions_count', 'desc')
->orderBy('submitted_at', 'desc');
->orderBy('published_at', 'desc');
}

public function markAsShared()
Expand All @@ -328,15 +337,15 @@ public static function nextForSharing(): ?self
{
return self::notShared()
->published()
->orderBy('submitted_at', 'asc')
->orderBy('published_at', 'asc')
->first();
}

public static function nexForSharingToTelegram(): ?self
{
return self::published()
->whereNull('tweet_id')
->orderBy('submitted_at', 'asc')
->orderBy('published_at', 'asc')
->first();
}

Expand Down
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class User extends Authenticatable implements MustVerifyEmail, HasMedia
'last_login_at',
'last_login_ip',
'email_verified_at',
'published_at',
'opt_in',
];

Expand Down Expand Up @@ -295,7 +296,7 @@ public function delete()
parent::delete();
}

public function scopeHasActivity(Builder $query)
public function scopeHasActivity(Builder $query): Builder
{
return $query->where(function ($query) {
$query->has('threads')
Expand Down
5 changes: 3 additions & 2 deletions app/Traits/WithArticleAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trait WithArticleAttributes
public bool $show_toc = false;
public ?string $submitted_at = null;
public ?string $approved_at = null;
public ?string $published_at = null;
public $file;

protected $rules = [
Expand All @@ -23,7 +24,7 @@ trait WithArticleAttributes
'file' => 'nullable|image|max:2048', // 1MB Max
];

public function removeImage()
public function removeImage(): void
{
$this->file = null;
}
Expand All @@ -38,7 +39,7 @@ public function messages(): array
];
}

public function updatedTitle(string $value)
public function updatedTitle(string $value): void
{
$this->slug = Str::slug($value);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"torchlight/torchlight-commonmark": "^0.5.5",
"wire-elements/modal": "^1.0",
"wire-elements/spotlight": "^1.0",
"wireui/wireui": "^1.1.3",
"wireui/wireui": "^1.6.0",
"yarri/link-finder": "^2.7"
},
"require-dev": {
Expand Down
Loading