forceDelete(); newArticleProperty::withTrashed()->forceDelete(); newArticle::withTrashed()->forceDelete(); SubsiteArticle::truncate(); ArticleCategoryRole::truncate(); //导入分类 $categories = ArticleCategory::orderBy('id', 'asc')->get(); $cate_count = 0; $cate_last_id = 0; if ($categories->isNotEmpty()) { $cate_data = []; foreach ($categories as $k => $v) { $time = date('Y-m-d H:i:s', time()); $cate_data = array( 'id' => $v->id, 'category_name' => $v->categoryname, 'parent_id' => $v->parentid, 'list_order' => $v->category_order, 'title' => $v->title, 'keywords' => $v->keywords, 'description' => $v->description, 'admin_set' => $v->admin_set, 'created_at' => $time, 'updated_at' => $time ); if (newArticleCategory::insert($cate_data)) { $cate_count++; $cate_last_id = $v->id; } else { $this->info('导入新闻分类' . $v->id . '失败'); } } } $this->info("导入新闻分类:" . $cate_count . '条,最后导入的新闻分类id是:' . $cate_last_id); //导入属性 $properties = ArticleProperty::orderBy('id', 'asc')->get(); $pro_count = 0; $pro_last_id = 0; if ($properties->isNotEmpty()) { $pro_data = []; foreach ($properties as $key => $val) { $ptime = date('Y-m-d H:i:s', time()); $pro_data = array( 'id' => $val->id, 'category_name' => $val->categoryname, 'list_order' => $val->category_order, 'admin_set' => $val->admin_set, 'created_at' => $ptime, 'updated_at' => $ptime ); if (newArticleProperty::insert($pro_data)) { $pro_count++; $pro_last_id = $val->id; } else { $this->info('导入新闻属性' . $val->id . '失败'); } } } $this->info("导入新闻属性:" . $pro_count . '条,最后导入的新闻属性id是:' . $pro_last_id); //导入新闻 $articles = Article::orderBy('id', 'asc')->get(); $article_count = 0; $article_last_id = 0; if ($articles->isNotEmpty()) { $article_data = []; foreach ($articles as $n => $article) { $content = htmlspecialchars_decode($article->content); $match_str = '/data/upload'; if (strpos($content, $match_str) >= 0) { $content = str_replace($match_str, '/storage/old', $content); } /*$content = htmlspecialchars_decode($article->content); $match_str = 'class="ke-insertfile" href="'; $content = substr_replace($content, 'old', (int)(28+strpos($content, $match_str)), 0);*/ $atime = date('Y-m-d H:i:s', $article->addtime); $article_data = array( 'id' => $article->id, 'type_id' => $article->type_id, 'parent_id' => $article->parentid, 'title' => $article->title, 'content' => $content, 'tit_color' => $article->tit_color, 'tit_b' => $article->tit_b, 'small_img' => !empty($article->Small_img) ? 'old/images/' . $article->Small_img : '', 'is_display' => $article->is_display, 'released_at' => $article->addtime, 'list_order' => $article->article_order == 255 ? 0 : $article->article_order, 'author' => $article->author, 'source' => $article->source, 'property_id' => $article->focos, 'is_url' => $article->is_url, 'seo_keywords' => $article->seo_keywords, 'seo_description' => $article->seo_description, 'click' => $article->click, 'subsite_id' => $article->subsite_id, 'robot' => $article->robot, 'created_at' => $atime, 'updated_at' => $atime ); if (newArticle::insert($article_data)) { $subsite_data = array( 'article_id' => $article->id, 'subsite_id' => $article->subsite_id?$article->subsite_id:0, 'created_at' => $atime, 'updated_at' => $atime, ); SubsiteArticle::insert($subsite_data); $article_count++; $article_last_id = $article->id; } else { $this->info('导入新闻' . $article->id . '失败'); } } } $this->info("导入新闻:" . $article_count . '条,最后导入的新闻id是:' . $article_last_id); } }