Skip to content

Commit a41c2df

Browse files
authored
Merge pull request #48 from laravelcm/enabled-published-posts
Enabled published posts
2 parents eb3efa1 + f564714 commit a41c2df

File tree

13 files changed

+254
-131
lines changed

13 files changed

+254
-131
lines changed

app/Console/Commands/Cleanup/DeleteOldUnverifiedUsers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function handle()
2222

2323
if ($query->get()->isNotEmpty()) {
2424
foreach ($query->get() as $user) {
25-
$user->notify((new SendEMailToDeletedUser())->delay(now()->addMinute(5)));
25+
$user->notify((new SendEMailToDeletedUser())->delay(now()->addMinutes(5)));
2626
}
2727
}
2828

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\Article;
6+
use Illuminate\Console\Command;
7+
8+
class PublishArticles extends Command
9+
{
10+
protected $signature = 'lcm:publish-articles';
11+
12+
protected $description = 'Published all articles already submitted and approved';
13+
14+
public function handle(): void
15+
{
16+
$this->info('Published all submitted articles...');
17+
18+
$articles = Article::submitted()->approved()->whereNull('published_at')->get();
19+
20+
foreach ($articles as $article) {
21+
$article->published_at = $article->submitted_at;
22+
$article->save();
23+
}
24+
25+
$count = $articles->count();
26+
27+
$this->comment("Published {$count} articles.");
28+
29+
$this->info('All done!');
30+
}
31+
}

app/Console/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Kernel extends ConsoleKernel
2424
*/
2525
protected function schedule(Schedule $schedule)
2626
{
27-
$schedule->command('media-library:delete-old-temporary-uploads')->daily();
27+
// $schedule->command('media-library:delete-old-temporary-uploads')->daily();
2828
$schedule->command('lcm:delete-old-unverified-users')->daily();
2929
$schedule->command('lcm:post-article-to-twitter')->twiceDaily(12, 16);
3030
$schedule->command('lcm:post-article-to-telegram')->everyFourHours();

app/Http/Livewire/Articles/Create.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function store()
5252
'title' => $this->title,
5353
'slug' => $this->slug,
5454
'body' => $this->body,
55+
'published_at' => $this->published_at,
5556
'submitted_at' => $this->submitted_at,
5657
'approved_at' => $this->approved_at,
5758
'show_toc' => $this->show_toc,

app/Http/Livewire/Articles/Edit.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function mount(Article $article)
3030
$this->slug = $article->slug;
3131
$this->show_toc = $article->show_toc;
3232
$this->submitted_at = $article->submitted_at;
33+
$this->published_at = $article->published_at ? $article->publishedAt()->format('Y-m-d') : null;
3334
$this->canonical_url = $article->originalUrl();
3435
$this->preview = $article->getFirstMediaUrl('media');
3536
$this->associateTags = $this->tags_selected = old('tags', $article->tags()->pluck('id')->toArray());
@@ -66,6 +67,7 @@ public function save()
6667
'show_toc' => $this->show_toc,
6768
'canonical_url' => $this->canonical_url,
6869
'submitted_at' => $this->submitted_at,
70+
'published_at' => $this->published_at,
6971
]);
7072

7173
$this->article->syncTags($this->associateTags);

app/Models/Article.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
4949
'declined_at',
5050
'shared_at',
5151
'sponsored_at',
52+
'published_at',
5253
];
5354

5455
/**
@@ -62,6 +63,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
6263
'declined_at' => 'datetime',
6364
'shared_at' => 'datetime',
6465
'sponsored_at' => 'datetime',
66+
'published_at' => 'datetime',
6567
'show_toc' => 'boolean',
6668
'is_pinned' => 'boolean',
6769
];
@@ -150,6 +152,11 @@ public function sponsoredAt(): ?Carbon
150152
return $this->sponsored_at;
151153
}
152154

155+
public function publishedAt(): ?Carbon
156+
{
157+
return $this->published_at;
158+
}
159+
153160
public function isSubmitted(): bool
154161
{
155162
return ! $this->isNotSubmitted();
@@ -192,12 +199,12 @@ public function isNotDeclined(): bool
192199

193200
public function isPublished(): bool
194201
{
195-
return ! $this->isNotPublished();
202+
return ! $this->isNotPublished() && ($this->publishedAt() && $this->publishedAt()->lessThanOrEqualTo(now()));
196203
}
197204

198205
public function isNotPublished(): bool
199206
{
200-
return $this->isNotSubmitted() || $this->isNotApproved();
207+
return ($this->isNotSubmitted() || $this->isNotApproved()) && $this->published_at === null;
201208
}
202209

203210
public function isPinned(): bool
@@ -249,7 +256,8 @@ public function scopeAwaitingApproval(Builder $query): Builder
249256

250257
public function scopePublished(Builder $query): Builder
251258
{
252-
return $query->submitted()
259+
return $query->whereDate('published_at', '<=', now())
260+
->submitted()
253261
->approved();
254262
}
255263

@@ -258,6 +266,7 @@ public function scopeNotPublished(Builder $query): Builder
258266
return $query->where(function ($query) {
259267
$query->whereNull('submitted_at')
260268
->orWhereNull('approved_at')
269+
->orWhereNull('published_at')
261270
->orWhereNotNull('declined_at');
262271
});
263272
}
@@ -300,14 +309,14 @@ public function scopeNotDeclined(Builder $query): Builder
300309
public function scopeRecent(Builder $query): Builder
301310
{
302311
return $query->orderBy('is_pinned', 'desc')
303-
->orderBy('submitted_at', 'desc');
312+
->orderBy('published_at', 'desc');
304313
}
305314

306315
public function scopePopular(Builder $query): Builder
307316
{
308317
return $query->withCount('reactions')
309318
->orderBy('reactions_count', 'desc')
310-
->orderBy('submitted_at', 'desc');
319+
->orderBy('published_at', 'desc');
311320
}
312321

313322
public function scopeTrending(Builder $query): Builder
@@ -316,7 +325,7 @@ public function scopeTrending(Builder $query): Builder
316325
$query->where('created_at', '>=', now()->subWeek());
317326
}])
318327
->orderBy('reactions_count', 'desc')
319-
->orderBy('submitted_at', 'desc');
328+
->orderBy('published_at', 'desc');
320329
}
321330

322331
public function markAsShared()
@@ -328,15 +337,15 @@ public static function nextForSharing(): ?self
328337
{
329338
return self::notShared()
330339
->published()
331-
->orderBy('submitted_at', 'asc')
340+
->orderBy('published_at', 'asc')
332341
->first();
333342
}
334343

335344
public static function nexForSharingToTelegram(): ?self
336345
{
337346
return self::published()
338347
->whereNull('tweet_id')
339-
->orderBy('submitted_at', 'asc')
348+
->orderBy('published_at', 'asc')
340349
->first();
341350
}
342351

app/Models/User.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class User extends Authenticatable implements MustVerifyEmail, HasMedia
4949
'last_login_at',
5050
'last_login_ip',
5151
'email_verified_at',
52+
'published_at',
5253
'opt_in',
5354
];
5455

@@ -295,7 +296,7 @@ public function delete()
295296
parent::delete();
296297
}
297298

298-
public function scopeHasActivity(Builder $query)
299+
public function scopeHasActivity(Builder $query): Builder
299300
{
300301
return $query->where(function ($query) {
301302
$query->has('threads')

app/Traits/WithArticleAttributes.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ trait WithArticleAttributes
1313
public bool $show_toc = false;
1414
public ?string $submitted_at = null;
1515
public ?string $approved_at = null;
16+
public ?string $published_at = null;
1617
public $file;
1718

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

26-
public function removeImage()
27+
public function removeImage(): void
2728
{
2829
$this->file = null;
2930
}
@@ -38,7 +39,7 @@ public function messages(): array
3839
];
3940
}
4041

41-
public function updatedTitle(string $value)
42+
public function updatedTitle(string $value): void
4243
{
4344
$this->slug = Str::slug($value);
4445
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"torchlight/torchlight-commonmark": "^0.5.5",
4040
"wire-elements/modal": "^1.0",
4141
"wire-elements/spotlight": "^1.0",
42-
"wireui/wireui": "^1.1.3",
42+
"wireui/wireui": "^1.6.0",
4343
"yarri/link-finder": "^2.7"
4444
},
4545
"require-dev": {

0 commit comments

Comments
 (0)