轻松实现织梦网站数据迁移到新站点

news/2024/5/20 22:20:51/文章来源:https://blog.csdn.net/yinyueboke/article/details/122647275

众所周知,织梦已经开始收费了,这对国内版权意识增强应该不算坏事,但想要免费使用又不想惹麻烦的站长们就有点麻烦了。

有不少朋友来问,我们 MyCms 支不支持织梦数据迁移,目前我们已经实现一键导入织梦的原文章和商品了,现在简要讲述一下实现过程。

一、连接数据库

要想实现数据的迁移导入,那么先要得到数据库信息,所以我们第一步就要实现填写数据库信息功能。

11.png

可以打开织梦网站的 data/common.inc.php 文件对照填写。

单次导入数据字段为执行一次导入多少量的数据,默认100条,这个可以依照自己的服务器来调整。

这一步仅仅是保存数据库信息,别无他用。

附上连接数据库代码

//$this->config 为保存的数据库信息$dedeConnection = array_merge(['driver' => 'mysql','charset' => 'utf8','collation' => 'utf8_unicode_ci','prefix' => $this->config['dede_prefix'],
], $this->config);config(['database.connections.dedecms' => $dedeConnection]);$this->connection = DB::connection('dedecms');

二、导入分类/文章

1.导入文章分类,并明确上下级关系。

public function articleCategory()
{if (!Storage::exists("dede_article_category")) {//导入分类$categories = $this->connection->table('arctype')->get();$catArray = $catParentArray = [];foreach ($categories as $category) {$cid = ArticleCategory::insert(['pid' => 0,'name' => $category->typename,]);$catArray[$category->id] = $cid;$catParentArray[$cid] = $category->topid;}foreach ($catParentArray as $key => $value) {if ($value > 0) {$ac = ArticleCategory::find($key);$ac->pid = $catArray[$value];$ac->save();}}Storage::put("dede_article_category", json_encode($catArray));} else {$catArray = json_decode(Storage::get("dede_article_category"), true);}return $catArray;
}

2.要先明确要导入文章的那些信息,然后对应好自身系统的字段,开始导入。

附上 MyCms 导入的代码给大家参考。


public function article(): JsonResponse
{$date = date('Y-m-d H:i:s');//最后导入ID$lastId = Storage::exists("dede_article_last_id") ? Storage::get("dede_article_last_id") : 0;$articles = $this->connection->table('archives')->leftJoin('addonarticle', 'aid', '=', 'id')->where([['channel', '=', 1],['id', '>', $lastId],])->limit($this->config['batch_number'])->get();$importLog = [];$catArray = $this->articleCategory();foreach ($articles as $article) {$aid = Article::insert(['category_id' => $catArray[$article->typeid],'title' => $article->title,'content' => $article->body,'description' => $article->description,'img' => $article->litpic,'author' => $article->writer,'view' => $article->click,'created_at' => date('Y-m-d H:i:s', $article->senddate),'updated_at' => date('Y-m-d H:i:s', $article->pubdate),]);if ($article->shorttitle) {$meta = ['article_id' => $aid,'meta_key' => 'short_title','meta_value' => $article->shorttitle,];ArticleMeta::insert($meta);}$lastId = $article->id;$tagIds = (new ArticleTag)->insertTags(explode(",", trim($article->keywords, ",")));(new ArticleTagRel)->insertRel($aid, $tagIds);//导入记录$importLog[] = ['type' => '文章','oid' => $article->id,'mid' => $aid,'title' => $article->title,'created_at' => $date,'updated_at' => $date,];}Dedecms::insertAll($importLog);//写入导入最后IDStorage::put("dede_article_last_id", $lastId);return $this->result(true);
}

三、导入商品

导入商品也是一样的道理,就不多少,直接附上代码。

public function goods()
{$date = date('Y-m-d H:i:s');$lastId = Storage::exists("dede_goods_last_id") ? Storage::get("dede_goods_last_id") : 0;$articles = $this->connection->table('archives')->leftJoin('addonshop', 'aid', '=', 'id')->where([['channel', '=', 6],['id', '>', $lastId],])->limit($this->config['batch_number'])->get();$importLog = [];$catArray = $this->goodsCategory();foreach ($articles as $article) {$aid = Goods::insert(['category_id' => $catArray[$article->typeid],'goods_name' => $article->title,'content' => $article->body,'description' => $article->description,'goods_image' => $article->litpic,'view' => $article->click,'shop_price' => $article->trueprice ?: $article->price,'market_price' => $article->price,'created_at' => date('Y-m-d H:i:s', $article->senddate),'updated_at' => date('Y-m-d H:i:s', $article->pubdate),]);if ($article->shorttitle) {$meta = ['goods_id' => $aid,'meta_key' => 'short_title','meta_value' => $article->shorttitle,];GoodsMeta::insert($meta);}$lastId = $article->id;$importLog[] = ['type' => '商品','oid' => $article->id,'mid' => $aid,'title' => $article->title,'created_at' => $date,'updated_at' => $date,];}Dedecms::insertAll($importLog);Storage::put("dede_goods_last_id", $lastId);return $this->result(true);
}

最后导入成功,并记录下来。

222.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_897614.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

开源多语言商城 CMS 企业建站系统,MyCms v3.9 发布

MyCms 是一款基于 Laravel 开发的开源免费的开源多语言商城 CMS 企业建站系统。 MyCms 基于 Apache2.0 开源协议发布,免费且可商业使用,欢迎持续关注我们。 V3.9 更新内容 新增:模板自定义配置 新增:读取模板配置函数 新增&…

网站架构

百科名片 网站架构 网站架构,一般认为是根据 客户需求分析的结果,准确定位网站目标群体,设定网站整体架构,规划、设计网站栏目及其内容,制定 网站开发流程及顺序,以最大限度地进行高效资源分配与管理的设计…

转载:程序员实用工具网站

转载 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/m0_38106923/article/details/100130354 目录 1、搜索引擎 2、PPT 3、图片操作 4、文件共…

http://www.miuo.com 我的网站.密友地带,RSS Home,密友,RSS,XML

http://www.miuo.com http://miuo.com http://www.miuo.com/syndication.axd 密友科技资讯[miuo.com]_致力于从世界日新月异的科技信息中获取最大的信息价值,提供简明IT新闻,IT业界资讯,提供讨论平台,报道即时信息,讨论热烈的新闻、评论、…

10个设计最经典的web2.0网站

10个设计最经典的web2.0网站 <script type"text/javascript"> </script><script src"http://pagead2.googlesyndication.com/pagead/show_ads.js" type"text/javascript"> </script> 做好一个网站&#xff0c;不仅要在服…

源代码Search网站 www.krugle.com

推荐一个相当好的源代码搜索网站, www.krugle.com . 可以根据某段代码进行搜索,搜索结构可以是某段代码,或者某个工程. 支持相当多的程序开发语言. 感兴趣的可以去看看 ^_^ 界面如下:

学生社区(学校交流社区)网站源码推荐

学生社区网站&#xff08;或者说学校交流社区&#xff09;的特点是注重互动和个人展示&#xff0c;老墨今天为大家推荐几个比较适合创建学生社区网站的源码。 记事狗 记事狗微博系统是一套创新的PHP开源微博程序&#xff0c;其支持Wap、手机客户端、短信、QQ机器人等多种方式发…

Intel Edison Arduino 温度检测并上传至网站

采用的Arduino的温度传感器&#xff0c;其说明见此链接。参数罗列如下&#xff1a; Voltage: 3.3 ~ 5VZero power resistance: 100 KΩResistance Tolerance: 1%Operating temperature range: -40 ~ 125 ℃Nominal B-Constant&#xff1a; 4250 ~ 4299K 关键计算公式如下&#…

JAVA里面读取PostgreSQL数据库最近80条温度检测记录,并用Highcharts展示在网站上

效果如下&#xff1a; 花了2天时间处理了服务器端的GET处理部分&#xff0c;和前端HTML部分。 难点(1)&#xff1a;series[0]["data"][jjj]parseFloat(arr_temp[jjj]); 首先series[0]的[0]是不能省掉的&#xff0c;因为采用的这个是多曲线展示&#xff0c;要展示的是…

部署在线网站

1、注册账号 https://www.ngrok.cc/ 2、开通一个隧道账号 记录一下隧道ID 33adb03ff15e3705 3、下载客户端&#xff0c;最下面 https://www.ngrok.cc/ windows64下载 http://pan.baidu.com/s/1o8HQHxo 4、解压双击&#xff0c;输入33adb03ff15e3705按回车即可 注意&#xff1…

找xpath好用的工具(比较少用,针对只能在IE上打开的网站)

有一些网站只能在IE浏览器里打开&#xff0c;不像firefox那样有好多好用的插件来找元素的xpath,css path等。 当然现在IE也可以&#xff0c;F12出现像firebug那样的窗口&#xff0c;来查看元素。 这里呢在介绍一个工具&#xff0c;Fire-IEBrowser1.4.zip&#xff0c;我已经上…

Echarts一些社区网站,亲测可用,新更新了Antv(阿里旗下)

1.makeapie echarts图表可视化案例makeapie echarts图表可视化案例, 分享你的可视化作品https://www.makeapie.cn/echarts 2.Examples - Apache EChartsECharts, a powerful, interactive charting and visualization library for browserhttps://echarts.apache.org/examples…

使用css和jquery实现一个网站首页轮播图的功能

效果展示说明 页面代码&#xff0c;在一个div框中用img标签放置图片和小圆点 <div id"box01"><img src"img/fengxueshanshenmiao.jpg"/><img src"img/sandazhujiazhuang.jpg" /><img src"img/shuihuAll.jpg" /&…

动态网站的搭建-学习笔记-阿里云服务器测试

1.静态网站&动态网站 Wordpress 2.静态&#xff1a;公司业务介绍等 减轻服务器负担&#xff08;无额外计算&#xff09; 打开快、搜索引擎收录全 动态&#xff1a;交互式网站&#xff0c;电商的库存 降低维护的工作量 用户注册、在线调查、订单管理等 3.iis是在windows下常…

网站的目录分类与TAG标签有什么区别?如何使用?

博客文章或电商网站商品一定要分类&#xff1f; 分类是不是越多越好&#xff1f; 分类与标签有什么不同&#xff1f; 做好标签与分类是不是对于网站在搜索引擎中有帮助&#xff1f; 相信许多在经营博客或是电商网站的人员都会遇到这样的问题。如果你上网百度相关问题&#…

网站转换率如何提高?知道这四点足矣!

网站转换率如何提高&#xff1f;知道这四点足矣&#xff01; 原文出处&#xff1a;http://www.tunan321.com 什么是转换率 转换率顾名思义首先考虑转换&#xff0c;而转换意味着&#xff0c;在不同情况下进行了切换&#xff0c;转换率就是指每个人在不同情况下切换成功的比率…

建设网站到底需不需要用WordPress?

WordPress 最知名的大概就是所谓的 5 分钟安装 (5-Minute install)&#xff0c;让你可以快速地安装 WordPress 并开始撰写内容和设计页面。这几年随著社群的蓬勃发展&#xff0c;各种线上或线下教学以及教学推广 (联盟行销&#xff1f;)&#xff0c;WordPress 的能见度提高很多…

创建自己的博客网站

一直想拥有自己的博客网站&#xff0c;在云上搭建&#xff0c;免服务的。 https://developer.aliyun.com/adc/series/activity/wulin?accounttraceid5944bc16d86f49fca9559abbd2b5f1bbfkjd 我在上面使用WordPress搭建了一个博客&#xff0c;可以自定义主题

ASP.NET MVC3细嚼慢咽---(1)网站创建与发布

这一节我们演示下怎样使用VS2010创建与发布MVC3建立的网站。使用VS2010创建MVC3.0网站&#xff0c;需要下载MVC3.0的安装包&#xff0c;这个大家可以去网络上下载。 1.项目创建 打开VS2010&#xff0c;选择 文件--新建项目---ASP.NET MVC3 web应用程序&#xff0c;如下图 接着选…

模式识别和机器学习实战-K近邻算法(KNN)- Python实现 - 约会网站配对效果判断和手写数字识别

文章目录 前言一、 k-近邻算法&#xff08;KNN&#xff09;1.算法介绍2.举个例子——电影分类3.步骤描述4.来了——代码实现 二、实战之约会网站配对效果判断1.导入数据2.分析数据3.数据归一化4. 测试算法→使用错误率来检测性能5. 构建完整的系统6.总结分析 三、实战之手写数字…