fix: [attach] 短代码跨文章全局解析 + 缺失残留清理;损坏附件导入降级不中断;media 导入幂等;sablog:import 支持 sqlite 老库 + 5 个导入自动化测试
This commit is contained in:
@@ -18,6 +18,7 @@ use Spatie\Tags\Tag;
|
||||
class SablogImport extends Command
|
||||
{
|
||||
protected $signature = 'sablog:import
|
||||
{--driver=mysql : 老库驱动(mysql / sqlite,测试可用 sqlite)}
|
||||
{--host=127.0.0.1 : 老库主机}
|
||||
{--port=3306 : 老库端口}
|
||||
{--database= : 老库名(必填)}
|
||||
@@ -81,6 +82,17 @@ class SablogImport extends Command
|
||||
|
||||
private function connect(string $database): void
|
||||
{
|
||||
$driver = $this->option('driver');
|
||||
|
||||
if ($driver === 'sqlite') {
|
||||
$this->db = new PDO('sqlite:'.$database, null, null, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$dsn = sprintf(
|
||||
'mysql:host=%s;port=%s;dbname=%s;charset=utf8mb4',
|
||||
$this->option('host'),
|
||||
@@ -94,6 +106,17 @@ class SablogImport extends Command
|
||||
]);
|
||||
}
|
||||
|
||||
private function hasTable(string $table): bool
|
||||
{
|
||||
try {
|
||||
$this->db->query("SELECT COUNT(*) FROM `{$this->prefix}{$table}` LIMIT 1");
|
||||
|
||||
return true;
|
||||
} catch (\Throwable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function rows(string $table): array
|
||||
{
|
||||
return $this->db->query('SELECT * FROM `'.$this->prefix.$table.'`')->fetchAll();
|
||||
@@ -349,7 +372,7 @@ class SablogImport extends Command
|
||||
|
||||
private function importAttachments(): void
|
||||
{
|
||||
if (! $this->db->query('SHOW TABLES LIKE "'.$this->prefix.'attachments"')->fetchColumn()) {
|
||||
if (! $this->hasTable('attachments')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user