Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.
Draft
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
3 changes: 2 additions & 1 deletion app/Http/Controllers/BlogArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function update(Request $request, $id){
'title' => $rev->title,
'category' => $request->input('category'),
'revision_id' => $rev->id,
'handle_name' => $rev->handle_name
'handle_name' => $rev->handle_name,
'updated_at' => $rev->timestamp,
]);
SlackNotify::notify_article($article, 'updated', $request->user('admin')->name);
return response(new ArticleResource($article));
Expand Down
7 changes: 7 additions & 0 deletions app/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Article extends Model
'id', 'category', 'title', 'revision_id', 'created_at', 'updated_at', 'handle_name'
];

const UPDATED_AT = NULL;

protected $dates = [
'created_at',
'updated_at',
];

protected $primaryKey = 'id';

protected $keyType = 'string';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

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

class SetTimestampDefaultValueArticles extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('articles', function (Blueprint $table) {
if(env('DB_CONNECTION') == 'mysql') {
DB::statement('ALTER TABLE articles CHANGE created_at created_at timestamp NOT NULL DEFAULT \'0000-00-00 00:00:00\'');
DB::statement('ALTER TABLE articles CHANGE created_at created_at timestamp NOT NULL DEFAULT \'0000-00-00 00:00:00\'');
}
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('articles', function (Blueprint $table) {
if(env('DB_CONNECTION') == 'mysql') {
DB::statement('ALTER TABLE articles CHANGE created_at created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP');
DB::statement('ALTER TABLE articles CHANGE created_at created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP');
}
});
}
}
5 changes: 4 additions & 1 deletion tests/BlogArticleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public function test_update() {
'status' => 'accepted',
]);

Carbon::setTestNow(Carbon::now()->addSeconds(10));

$this->json('PATCH', "/blog/articles/{$article_id}",
[
'revision_id' => $revision->id,
Expand All @@ -139,11 +141,12 @@ public function test_update() {

$this->assertEquals($revision->title, $ret->title);
$this->assertEquals($revision->id, $ret->revision_id);
$this->assertEquals($revision->timestamp->toIso8601ZuluString(), $ret->updated_at);

$article = Article::find($article_id);
$this->assertEquals($revision->title, $article->title);
$this->assertEquals($revision->id, $article->revision_id);

Carbon::setTestNow();
}
}

Expand Down