added support for legacy tickets, fixed switching of modes and also style updates
This commit is contained in:
@@ -5,31 +5,19 @@ declare(strict_types=1);
|
||||
namespace Modules\Documentation\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Modules\Documentation\Models\DocumentationCategory;
|
||||
|
||||
use Modules\Documentation\Models\DocumentationDocument;
|
||||
|
||||
use SplFileInfo;
|
||||
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
use Throwable;
|
||||
|
||||
final class ImportDocumentationCommand extends Command
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
* The console command signature.
|
||||
|
||||
*/
|
||||
|
||||
protected $signature = 'helpdesk:import-documentation
|
||||
|
||||
{path? : Directory containing Markdown files; defaults to the bundled Sentinel documentation}
|
||||
@@ -39,21 +27,14 @@ final class ImportDocumentationCommand extends Command
|
||||
{--fresh : Remove previously imported documents in this category before importing}';
|
||||
|
||||
/**
|
||||
|
||||
* The console command description.
|
||||
|
||||
*/
|
||||
|
||||
protected $description = 'Import Markdown documentation into the Helpdesk Documentation module.';
|
||||
|
||||
/**
|
||||
|
||||
* Execute the console command.
|
||||
|
||||
*/
|
||||
|
||||
public function handle(): int
|
||||
|
||||
{
|
||||
|
||||
$path = $this->resolvePath();
|
||||
@@ -164,7 +145,7 @@ final class ImportDocumentationCommand extends Command
|
||||
|
||||
$this->importFile($category, $file, $path);
|
||||
|
||||
++$imported;
|
||||
$imported++;
|
||||
|
||||
$progress->advance();
|
||||
|
||||
@@ -198,7 +179,7 @@ final class ImportDocumentationCommand extends Command
|
||||
|
||||
$this->components->error(
|
||||
|
||||
'Documentation import failed: ' . $exception->getMessage(),
|
||||
'Documentation import failed: '.$exception->getMessage(),
|
||||
|
||||
);
|
||||
|
||||
@@ -217,13 +198,9 @@ final class ImportDocumentationCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Resolve the requested documentation source directory.
|
||||
|
||||
*/
|
||||
|
||||
private function resolvePath(): string
|
||||
|
||||
{
|
||||
|
||||
$argument = $this->argument('path');
|
||||
@@ -247,17 +224,13 @@ final class ImportDocumentationCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Find Markdown files recursively.
|
||||
|
||||
*
|
||||
|
||||
* @return list<SplFileInfo>
|
||||
|
||||
*/
|
||||
|
||||
private function markdownFiles(string $path): array
|
||||
|
||||
{
|
||||
|
||||
$finder = Finder::create()
|
||||
@@ -273,7 +246,6 @@ final class ImportDocumentationCommand extends Command
|
||||
->sortByName();
|
||||
|
||||
/** @var list<SplFileInfo> $files */
|
||||
|
||||
$files = iterator_to_array($finder, false);
|
||||
|
||||
return $files;
|
||||
@@ -281,11 +253,8 @@ final class ImportDocumentationCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Import one Markdown document.
|
||||
|
||||
*/
|
||||
|
||||
private function importFile(
|
||||
|
||||
DocumentationCategory $category,
|
||||
@@ -301,7 +270,6 @@ final class ImportDocumentationCommand extends Command
|
||||
if ($realPath === false || ! is_readable($realPath)) {
|
||||
|
||||
throw new \RuntimeException(
|
||||
|
||||
sprintf('Unable to read documentation file: %s', $file->getPathname()),
|
||||
|
||||
);
|
||||
@@ -313,7 +281,6 @@ final class ImportDocumentationCommand extends Command
|
||||
if ($body === false) {
|
||||
|
||||
throw new \RuntimeException(
|
||||
|
||||
sprintf('Unable to read documentation file: %s', $realPath),
|
||||
|
||||
);
|
||||
@@ -360,7 +327,7 @@ final class ImportDocumentationCommand extends Command
|
||||
|
||||
'status' => DocumentationDocument::STATUS_PUBLISHED,
|
||||
|
||||
'is_featured' => strtolower($file->getBasename('.' . $file->getExtension())) === 'index',
|
||||
'is_featured' => strtolower($file->getBasename('.'.$file->getExtension())) === 'index',
|
||||
|
||||
'version' => '1.0.0',
|
||||
|
||||
@@ -377,13 +344,9 @@ final class ImportDocumentationCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Extract the first Markdown H1 heading.
|
||||
|
||||
*/
|
||||
|
||||
private function extractTitle(string $body, SplFileInfo $file): string
|
||||
|
||||
{
|
||||
|
||||
if (preg_match('/^\s*#\s+(.+?)\s*$/m', $body, $matches) === 1) {
|
||||
@@ -417,13 +380,9 @@ final class ImportDocumentationCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Extract a useful summary from the first normal Markdown paragraph.
|
||||
|
||||
*/
|
||||
|
||||
private function extractSummary(string $body): ?string
|
||||
|
||||
{
|
||||
|
||||
$lines = preg_split('/\R/', $body);
|
||||
@@ -507,13 +466,9 @@ final class ImportDocumentationCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Generate a stable globally unique slug from the source path.
|
||||
|
||||
*/
|
||||
|
||||
private function makeSlug(string $relativePath, string $title): string
|
||||
|
||||
{
|
||||
|
||||
$withoutExtension = preg_replace(
|
||||
@@ -536,7 +491,7 @@ final class ImportDocumentationCommand extends Command
|
||||
|
||||
if ($slug === '') {
|
||||
|
||||
$slug = 'document-' . substr(sha1($relativePath), 0, 12);
|
||||
$slug = 'document-'.substr(sha1($relativePath), 0, 12);
|
||||
|
||||
}
|
||||
|
||||
@@ -545,13 +500,9 @@ final class ImportDocumentationCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* Remove a UTF-8 byte-order mark.
|
||||
|
||||
*/
|
||||
|
||||
private function stripBom(string $contents): string
|
||||
|
||||
{
|
||||
|
||||
if (str_starts_with($contents, "\xEF\xBB\xBF")) {
|
||||
@@ -563,6 +514,4 @@ final class ImportDocumentationCommand extends Command
|
||||
return $contents;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user