fecshop 安装mongodb-migrate 报错

安装报错 · V55V · 于 1年前 发布 · 1270 次阅读

安装第九步 9.1、Yii2 migratge方式导入表。 mongodb(导入mongodb的表,数据,索引):

./yii mongodb-migrate  --interactive=0 --migrationPath=@fecshop/migrations/mongodb

报错内容如下:

[root@localhost drop]# ./yii mongodb-migrate  --interactive=0 --migrationPath=@fecshop/migrations/mongodb
Yii Migration Tool (based on Yii v2.0.12)

Total 1 new migration to be applied:
	m170228_072455_fecshop_tables

*** applying m170228_072455_fecshop_tables
PHP Compile Error 'yii\base\ErrorException' with message 'require_once(): Failed opening required 'Array/m170228_072455_fecshop_tables.php' (include_path='.:')'

in /www/web/drop/vendor/yiisoft/yii2-mongodb/console/controllers/MigrateController.php:136

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}

共收到 2 条回复
Fecshop#11年前 0 个赞

尝试了一下,的确是报错,问题出在yii2 mongodb扩展存在问题

原因:vendor/yiisoft/yii2-mongodb/console/controllers/MigrateController.php

 /**
     * Creates a new migration instance.
     * @param string $class the migration class name
     * @return \yii\mongodb\Migration the migration instance
     */
    protected function createMigration($class)
    {
        $class = trim($class, '\\');
        if (strpos($class, '\\') === false) {
            $file = $this->migrationPath . DIRECTORY_SEPARATOR . $class . '.php';
            require_once($file);
        }

        return new $class(['db' => $this->db]);
    }

$this->migrationPath 输出是一个数组: var_dump( $this->migrationPath);

array(1) {
  [0]=>
  string(62) "/www/web/drop/vendor/fancyecommerce/fecshop/migrations/mongodb"
}

修改代码如下:

 protected function createMigration($class)
    {
        $class = trim($class, '\\');
        if (strpos($class, '\\') === false) {
            
            $file = $this->migrationPath[0] . DIRECTORY_SEPARATOR . $class . '.php';
            require_once($file);
        }

        return new $class(['db' => $this->db]);
    }

即可安装成功:

[root@localhost drop]# ./yii mongodb-migrate  --interactive=0 --migrationPath=@fecshop/migrations/mongodb
Yii Migration Tool (based on Yii v2.0.12)

Total 1 new migration to be applied:
	m170228_072455_fecshop_tables

*** applying m170228_072455_fecshop_tables
*** applied m170228_072455_fecshop_tables (time: 0.172s)


1 migration was applied.

Migrated up successfully.
[root@localhost drop]# 

这个是官方扩展的bug,已经提交给yii issues,地址如下:

https://github.com/yiisoft/yii2-mongodb/issues/214

Fecshop#21年前 0 个赞

这个问题,在php5中会出现,在php7中安装不会出现,应该是一个bug,已经提交给Yii

https://github.com/yiisoft/yii2-mongodb/commit/6e149bb55f801f7e44e0e1f71a98a2a7c3766fe7

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