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

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

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

有不少朋友来问,我们 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);
       //写入导入最后ID
    Storage::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

目录
相关文章
|
人工智能 前端开发 机器人
虚拟数字人开放平台产品分享
本文摘自虚拟数字人新品发布会姜望讲解部分
2278 0
虚拟数字人开放平台产品分享
|
9月前
|
机器学习/深度学习 监控 算法
《分子动力学模拟的参数困局:QML的突围方案》
量子机器学习力场(QMLF)通过机器学习模型结合量子力学数据,为分子动力学模拟提供高精度、低成本的势能函数。然而,其参数更新在长时间模拟中存在稳定性问题。为此,需从高质量数据、先进模型架构和优化训练策略三方面入手:高质量数据确保学习准确性,等变表示与多尺度模型提升对复杂相互作用的理解,自适应优化算法与正则化技术增强模型稳定性和泛化能力。这是一项系统性工程,旨在实现高效、可靠的分子动力学模拟。
142 7
|
Rust Ubuntu Linux
在Ubuntu中为ROG笔记本安装驱动asusctl
在Ubuntu中为ROG笔记本安装驱动asusctl
3143 0
在Ubuntu中为ROG笔记本安装驱动asusctl
|
存储 JavaScript 中间件
在 Redux 动态路由中进行数据预加载时,如何处理数据加载失败的情况?
【10月更文挑战第22天】在 Redux 动态路由中进行数据预加载时,数据加载失败是需要妥善处理的情况
280 62
|
分布式计算 DataWorks 安全
DataWorks产品使用合集之将多业务分表同步到odps的一个三级分区表中,每级分区怎么赋值
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。
153 4
c#网页抓取京东商城首页案列
c#网页抓取京东商城首页案列
171 0
|
Java 应用服务中间件 数据库连接
[记录]java jsp web无法解析绝对uri:[http://java.sun.com/jsp/jstl/core]
[记录]java jsp web无法解析绝对uri:[http://java.sun.com/jsp/jstl/core]
351 0
|
计算机视觉
实现抖音慢动作效果---OpenCV-Python开发指南(57)
实现抖音慢动作效果---OpenCV-Python开发指南(57)
479 1
|
监控 Cloud Native 大数据
带你读《企业级云原生白皮书项目实战》——5.3.3 任务性能(7)
带你读《企业级云原生白皮书项目实战》——5.3.3 任务性能(7)
218 0

热门文章

最新文章