MongoDB 存储“静态块”无法显示,似乎是个BUG?

bug问题 · billgetjoy · 于 3年前 发布 · 1043 次阅读

很久没升级新版了,昨日升级到2.12.1版本,发现后台,CMS->静态块 中设置的内容,在前端无法显示。

查看代码发现,/services/cms/staticblock/StaticBlockMongodb.php 中,函数 getByIdentify() 与老版本相比,增加了status状态判断,去掉状态判断就能显示出静态块了。

public function getByIdentify($identify)
    {
        return $this->_staticBlockModel->find()->asArray()->where([
            'identify' => $identify,
            'status'  => $this->getEnableStatus() //这里新增了状态判断
        ])->one();
    }

通过在mongo里执行查询语句对比,发现

use fecmall;
db.static_block.find({'status':'1'});//能查询出内容
db.static_block.find({'status':1});//不能查询出内容

也就是说,MongoDB中status存储类型是 string ?? 追溯代码发现,/models/mongodb/cms/StaticBlock.php 中,

const STATUS_DELETED = 10;
//const STATUS_ACTIVE = 1;
const STATUS_ACTIVE = '1'; //这里修改为string 即可显示
const STATUS_DISACTIVE = 2;

最后通过自己重写StaticBlock 覆盖掉系统 StaticBlock 解决。

不知这里是否是Bug,其他朋友有遇到过吗?

共收到 1 条回复
Fecmall#13年前 0 个赞

这个的确是个bug,mongodb没有表结构,因此插入数据的时候,需要对status的值进行int转换处理

已经处理并提交代码:https://github.com/fecshop/yii2_fecshop/commit/07125b436a4555da37232dc3a1a0093bb11021ce

1.您可以先手动更改,等后面发新版更新

2.您需要将您后台的static block重新保存一下。

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics