Finish re-working tests to run on test database
This commit is contained in:
parent
09fc211623
commit
1abca77bdc
50 changed files with 535 additions and 265 deletions
|
@ -24,16 +24,6 @@ class ParseCachedWebMentions extends Command
|
|||
*/
|
||||
protected $description = 'Re-parse the webmention’s cached HTML';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
|
@ -41,15 +31,15 @@ class ParseCachedWebMentions extends Command
|
|||
*/
|
||||
public function handle(FileSystem $filesystem)
|
||||
{
|
||||
$HTMLfiles = $filesystem->allFiles(storage_path() . '/HTML');
|
||||
foreach ($HTMLfiles as $file) {
|
||||
if ($file->getExtension() != 'backup') { //we don’t want to parse.backup files
|
||||
$htmlFiles = $filesystem->allFiles(storage_path() . '/HTML');
|
||||
foreach ($htmlFiles as $file) {
|
||||
if ($file->getExtension() !== 'backup') { //we don’t want to parse `.backup` files
|
||||
$filepath = $file->getPathname();
|
||||
$this->info('Loading HTML from: ' . $filepath);
|
||||
$html = $filesystem->get($filepath);
|
||||
$url = $this->URLFromFilename($filepath);
|
||||
$microformats = \Mf2\parse($html, $url);
|
||||
$url = $this->urlFromFilename($filepath);
|
||||
$webmention = WebMention::where('source', $url)->firstOrFail();
|
||||
$microformats = \Mf2\parse($html, $url);
|
||||
$webmention->mf2 = json_encode($microformats);
|
||||
$webmention->save();
|
||||
$this->info('Saved the microformats to the database.');
|
||||
|
@ -63,12 +53,12 @@ class ParseCachedWebMentions extends Command
|
|||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
private function URLFromFilename(string $filepath): string
|
||||
private function urlFromFilename(string $filepath): string
|
||||
{
|
||||
$dir = mb_substr($filepath, mb_strlen(storage_path() . '/HTML/'));
|
||||
$url = str_replace(['http/', 'https/'], ['http://', 'https://'], $dir);
|
||||
if (mb_substr($url, -10) == 'index.html') {
|
||||
$url = mb_substr($url, 0, mb_strlen($url) - 10);
|
||||
if (mb_substr($url, -10) === 'index.html') {
|
||||
$url = mb_substr($url, 0, -10);
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
|
|
@ -7,16 +7,10 @@ namespace App\Http\Controllers\Admin;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Article;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ArticlesController extends Controller
|
||||
{
|
||||
/**
|
||||
* List the articles that can be edited.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$posts = Article::select('id', 'title', 'published')->orderBy('id', 'desc')->get();
|
||||
|
@ -24,11 +18,6 @@ class ArticlesController extends Controller
|
|||
return view('admin.articles.index', ['posts' => $posts]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the new article form.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
$message = session('message');
|
||||
|
@ -36,11 +25,6 @@ class ArticlesController extends Controller
|
|||
return view('admin.articles.create', ['message' => $message]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an incoming request for a new article and save it.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(): RedirectResponse
|
||||
{
|
||||
//if a `.md` is attached use that for the main content.
|
||||
|
@ -49,42 +33,21 @@ class ArticlesController extends Controller
|
|||
$content = $file->fread($file->getSize());
|
||||
}
|
||||
$main = $content ?? request()->input('main');
|
||||
$article = Article::create(
|
||||
[
|
||||
'url' => request()->input('url'),
|
||||
'title' => request()->input('title'),
|
||||
'main' => $main,
|
||||
'published' => request()->input('published') ?? 0,
|
||||
]
|
||||
);
|
||||
Article::create([
|
||||
'url' => request()->input('url'),
|
||||
'title' => request()->input('title'),
|
||||
'main' => $main,
|
||||
'published' => request()->input('published') ?? 0,
|
||||
]);
|
||||
|
||||
return redirect('/admin/blog');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the edit form for an existing article.
|
||||
*
|
||||
* @param int $articleId
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function edit(int $articleId): View
|
||||
public function edit(Article $article): View
|
||||
{
|
||||
$post = Article::select(
|
||||
'title',
|
||||
'main',
|
||||
'url',
|
||||
'published'
|
||||
)->where('id', $articleId)->get();
|
||||
|
||||
return view('admin.articles.edit', ['id' => $articleId, 'post' => $post]);
|
||||
return view('admin.articles.edit', ['article' => $article]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an incoming request to edit an article.
|
||||
*
|
||||
* @param int $articleId
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(int $articleId): RedirectResponse
|
||||
{
|
||||
$article = Article::find($articleId);
|
||||
|
@ -97,12 +60,6 @@ class ArticlesController extends Controller
|
|||
return redirect('/admin/blog');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a request to delete an aricle.
|
||||
*
|
||||
* @param int $articleId
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(int $articleId): RedirectResponse
|
||||
{
|
||||
Article::where('id', $articleId)->delete();
|
||||
|
|
|
@ -59,18 +59,14 @@ class ArticlesController extends Controller
|
|||
* We only have the ID, work out post title, year and month
|
||||
* and redirect to it.
|
||||
*
|
||||
* @param int $idFromUrl
|
||||
* @param string $idFromUrl
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function onlyIdInUrl(int $idFromUrl): RedirectResponse
|
||||
public function onlyIdInUrl(string $idFromUrl): RedirectResponse
|
||||
{
|
||||
$realId = resolve(Numbers::class)->b60tonum((string) $idFromUrl);
|
||||
$realId = resolve(Numbers::class)->b60tonum($idFromUrl);
|
||||
|
||||
try {
|
||||
$article = Article::findOrFail($realId);
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
abort(404);
|
||||
}
|
||||
$article = Article::findOrFail($realId);
|
||||
|
||||
return redirect($article->link);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace App\Models;
|
|||
use Cviebrock\EloquentSluggable\Sluggable;
|
||||
use Eloquent;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
@ -58,6 +59,7 @@ use Spatie\CommonMarkHighlighter\IndentedCodeRenderer;
|
|||
*/
|
||||
class Article extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Sluggable;
|
||||
use SoftDeletes;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace App\Models;
|
|||
|
||||
use Eloquent;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
|
@ -35,6 +36,8 @@ use Illuminate\Support\Carbon;
|
|||
*/
|
||||
class Contact extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The database table used by the model.
|
||||
*
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace App\Models;
|
|||
|
||||
use Eloquent;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
@ -41,6 +42,8 @@ use Illuminate\Support\Str;
|
|||
*/
|
||||
class Media extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
|
@ -62,7 +65,7 @@ class Media extends Model
|
|||
*/
|
||||
public function note(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo('App\Models\Note');
|
||||
return $this->belongsTo(Note::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,7 +121,7 @@ class Media extends Model
|
|||
$filenameParts = explode('.', $path);
|
||||
array_pop($filenameParts);
|
||||
|
||||
return ltrim(array_reduce($filenameParts, function ($carry, $item) {
|
||||
return ltrim(array_reduce($filenameParts, static function ($carry, $item) {
|
||||
return $carry . '.' . $item;
|
||||
}, ''), '.');
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class Tag extends Model
|
|||
*/
|
||||
public function notes()
|
||||
{
|
||||
return $this->belongsToMany('App\Models\Note');
|
||||
return $this->belongsToMany(Note::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@ use App\Traits\FilterHtml;
|
|||
use Codebird\Codebird;
|
||||
use Eloquent;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
@ -55,6 +56,7 @@ use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException;
|
|||
class WebMention extends Model
|
||||
{
|
||||
use FilterHtml;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The database table used by the model.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue