月度归档: 2021 年 4 月

  • 在 Yii 2.0 中的命令行中,从A数据库迁移数据至B数据库的实现

    在 Yii 2.0 中的命令行中,从A数据库迁移数据至B数据库的实现

    1、将数据从csp的数据库中迁移至cloud的数据库中。`channel-pub-api-csp`.`cpa_channel_app_source`。条件查询出 95 条记录。如图1

    将数据从csp的数据库中迁移至cloud的数据库中。`channel-pub-api-csp`.`cpa_channel_app_source`。条件查询出 95 条记录。
    图1

    2、`channel-pub-api-cloud`.`cpa_channel_app_source`。总计查询出 158 条记录。如图2

    `channel-pub-api-cloud`.`cpa_channel_app_source`。总计查询出 158 条记录。
    图2

    3、将数据从csp的数据库中迁移至cloud的数据库中。字段值变动:id,INSERT `channel-pub-api-cloud`.`cpa_channel_app_source`。编辑命令行脚本。/console/controllers/Migrate20210425Controller.php

    <?php
    /**
     * Created by PhpStorm.
     * User: Qiang Wang
     * Date: 2021/04/25
     * Time: 13:59
     */
     
    namespace console\controllers;
     
    use Yii;
    use yii\console\Controller;
    use yii\console\ExitCode;
    use yii\db\Connection;
    use yii\db\Exception;
     
    /**
     * 数据库迁移(20210425)
     *
     * @author Qiang Wang <shuijingwanwq@163.com>
     * @since  1.0
     */
    class Migrate20210425Controller extends Controller
    {
        /**
         * 将数据从csp的数据库中迁移至cloud的数据库中(仅导入视频兔兔下的相关数据)
         *
         * @return int
         * @throws Exception
         */
        public function actionCspToCloud()
        {
            // 创建一个单独的非缓存链接到数据库(dsp)
            $cspDb = new Connection([
                'dsn' => 'mysql:host=localhost;dbname=channel-pub-api-csp',
                'username' => 'mysql',
                'password' => 'hqy-webtv',
                'tablePrefix' => 'cpa_',
                'charset' => 'utf8mb4',
            ]);
            $cspDb->open();
            // 设置 PDO 连接属性 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY 为 false
            $cspDb->pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
     
            // 创建一个单独的非缓存链接到数据库(cloud)
            $cloudDb = new Connection([
                'dsn' => 'mysql:host=localhost;dbname=channel-pub-api-cloud',
                'username' => 'mysql',
                'password' => 'hqy-webtv',
                'tablePrefix' => 'cpa_',
                'charset' => 'utf8mb4',
            ]);
            $cloudDb->open();
            // 设置 PDO 连接属性 PDO::MYSQL_ATTR_USE_BUFFERED_QUERY 为 false
            $cloudDb->pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
     
            $channelAppSources = $cspDb->createCommand('SELECT group_id, group_name, uuid, channel_id, channel_code, channel_type_id, channel_type_code, name, avatar, fans_count, source, source_uuid, source_product_id, source_user_token, permission, status, is_deleted, created_at, updated_at, deleted_at FROM {{%channel_app_source}} WHERE channel_type_code LIKE \'vtt_%\'')->queryAll();
            $cloudDb->createCommand()->batchInsert('cpa_channel_app_source', ['group_id', 'group_name', 'uuid', 'channel_id', 'channel_code', 'channel_type_id', 'channel_type_code', 'name', 'avatar', 'fans_count', 'source', 'source_uuid', 'source_product_id', 'source_user_token', 'permission', 'status', 'is_deleted', 'created_at', 'updated_at', 'deleted_at'], $channelAppSources)->execute();
     
            $cspDb->close();
            $cloudDb->close();
     
            return ExitCode::OK;
        }
    }
    

    4、执行命令:./yii migrate20210425/csp-to-cloud。`channel-pub-api-cloud`.`cpa_channel_app_source`。总计查询出 253 条记录,新增 95 条记录。符合预期。如图3

    执行命令:./yii migrate20210425/csp-to-cloud。`channel-pub-api-cloud`.`cpa_channel_app_source`。总计查询出 253 条记录,新增 95 条记录。符合预期。
    图3

     

  • 基于 Python 脚本,实现 Redis 数据迁移(自建 Redis 迁移至 腾讯云自带 Redis)

    基于 Python 脚本,实现 Redis 数据迁移(自建 Redis 迁移至 腾讯云自带 Redis)

    1、参考网址:https://blog.csdn.net/zhanghan18333611647/article/details/81434786 。通过程序 ( python 版本 2.x ) 实现。新建 migrate.py 文件。

    
    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
     
    # 把redis里面一个数据库的东西,迁移到另外一个数据库里面
    # 建立两个redis连接
    # 获取到所有的key .keys()
    # 判断key的类型 string\hash\list\set
    
    import redis
    #redis_from源数据,redis_to目标数据  redis_from——>redis_to
    redis_from = redis.StrictRedis(host='ip',port=6379,password='',db=10)
    redis_to = redis.StrictRedis(host='ip',port=6379,password='',db=0)
     
    if __name__ == '__main__':
        cnt = 0
        scnt = 0
        lcnt = 0
        setcnt = 0
        hcnt = 0
        
        for k in redis_from.keys():
            # 循环keys里面每一个key
     
            data_type = redis_from.type(k)
            # 判断key的类型 string\hash\list\set
     
            if data_type == 'string':
                v = redis_from.get(k)
                t = redis_from.ttl(k)
                redis_to.set(k, v)
                if int(t) > 0:
                    redis_to.expire(k,t)
     
                scnt = scnt + 1
     
            elif data_type == 'list':
                values = redis_from.lrange(k, 0, -1)
                t = redis_from.ttl(k)           
                redis_to.lpush(k, values)
                if int(t) > 0:
                    redis_to.expire(k,t)
     
                lcnt = lcnt + 1
            elif data_type == 'set':
                values = redis_from.smembers(k)
                t = redis_from.ttl(k)
                redis_to.sadd(k, values)
     
                if int(t) > 0:
                    redis_to.expire(k,t)
                setcnt = setcnt + 1
            elif data_type == 'hash':
                hcnt = hcnt + 1
                keys = redis_from.hkeys(k)                        
                for key in keys:
                    value = redis_from.hget(k, key)
                    t = redis_from.ttl(k)
                    redis_to.hset(k, key, value)
                    if int(t) > 0:
                        redis_to.expire(k,t)
     
            else:
                print 'not known type'
                print data_type
                file_object = open('/data/thefile.txt','a+')
                file_object.write(data_type)
                file_object.write('\n')
                file_object.close( )
     
     
     
            cnt = cnt + 1
     
        print 'total', cnt
        print 'string', scnt
        print 'list', lcnt
        print 'set', setcnt
        print 'hash', hcnt
    
    
    

    2、在自建 Redis 的机器上,分别连接自建 Redis 与腾讯云自带 Redis。腾讯云自带 Redis 的 数据库 0 为空。计划以此数据库做为迁移目标。如图1

    在自建 Redis 的机器上,分别连接自建 Redis 与腾讯云自带 Redis。腾讯云自带 Redis 的 数据库 0 为空。计划以此数据库做为迁移目标。
    图1

    3、查看 python 版本,Python 2.7.5。版本符合要求。如图2

    查看 python 版本,Python 2.7.5。版本符合要求。
    图2
    
    
    [root@iz2zeeh3rrqalw11oajd6zz ~]# python
    Python 2.7.5 (default, Nov 16 2020, 22:23:17)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    
    
    
    

    4、连接自建 Redis ,查看数据库 0 下的健的总数:40。

    
    
    [root@iz2zeeh3rrqalw11oajd6zz ~]# redis-cli -h 127.0.0.1 -p 6379 -a 2021Chinamcloud
    127.0.0.1:6379> select 0
    OK
    127.0.0.1:6379> dbsize
    (integer) 40
    127.0.0.1:6379>
    
    
    
    

    5、运行 python migrate.py。导入报错:ImportError:没有名为redis的模块。如图3

    运行 python migrate.py。导入报错:ImportError:没有名为redis的模块。
    图3
    
    [root@iz2zeeh3rrqalw11oajd6zz ~]# python migrate.py
    Traceback (most recent call last):
      File "migrate.py", line 9, in 
        import redis
    ImportError: No module named redis
    [root@iz2zeeh3rrqalw11oajd6zz ~]#
    
    
    
    

    6、安装 redis-py 后。继续运行 python migrate.py。

    
    
    [root@iz2zeeh3rrqalw11oajd6zz ~]# python migrate.py
    Traceback (most recent call last):
      File "migrate.py", line 39, in 
        redis_to.lpush(k, values)
      File "/usr/lib/python2.7/site-packages/redis/client.py", line 1961, in lpush
        return self.execute_command('LPUSH', name, *values)
      File "/usr/lib/python2.7/site-packages/redis/client.py", line 900, in execute_command
        conn.send_command(*args)
      File "/usr/lib/python2.7/site-packages/redis/connection.py", line 725, in send_command
        self.send_packed_command(self.pack_command(*args),
      File "/usr/lib/python2.7/site-packages/redis/connection.py", line 775, in pack_command
        for arg in imap(self.encoder.encode, args):
      File "/usr/lib/python2.7/site-packages/redis/connection.py", line 120, in encode
        "bytes, string, int or float first." % typename)
    redis.exceptions.DataError: Invalid input of type: 'list'. Convert to a bytes, string, int or float first.
    [root@iz2zeeh3rrqalw11oajd6zz ~]#
    
    
    
    

    7、分别查看 Redis 版本。自建 Redis 的版本号:3.2.12。腾讯云自带 Redis 的版本号:2.8.23。版本号不一致。如图4、图5

    自建 Redis 的版本号:3.2.12。
    图4

     

    腾讯云自带 Redis 的版本号:2.8.23。
    图5
    
    
    [root@iz2zeeh3rrqalw11oajd6zz ~]# redis-cli -h 127.0.0.1 -p 6379 -a 2021Chinamcloud
    127.0.0.1:6379> select 0
    OK
    127.0.0.1:6379> info
    # Server
    redis_version:3.2.12
    redis_git_sha1:00000000
    redis_git_dirty:0
    redis_build_id:7897e7d0e13773f
    redis_mode:standalone
    os:Linux 3.10.0-1160.11.1.el7.x86_64 x86_64
    
    
    
    
    
    RDM Redis Console
    连接中...
    已连接。
    腾讯云(公司开发环境):0>info
    "# Server
    redis_version:2.8.23
    run_id:0a99b4d4dac9744a76075aa77a978a2dfcdf1ba6
    uptime_in_seconds:74995115
    uptime_in_days:867
    hz:10
    lru_clock:8808554
    
    
    

    8、python 查看 redis 安装版本。新建文件 python_redis.py,查看到版本为 3.5.3。如图6

    python 查看 redis 安装版本。新建文件 python_redis.py,查看到版本为 3.5.3。
    图6
    
    import redis
    
    print redis.VERSION
    
    
    

    9、执行命令:pip install redis==2.10.6。回退版本至 2.10.6。如图7

    执行命令:pip install redis==2.10.6。回退版本至 2.10.6。
    图7

    10、回退版本至 2.10.6 后,继续运行 python migrate.py。数据迁移成功。为何迁移了数据库 0 下的健的总数:53,原因在于自建 Redis 中的数据在变化中所导致。如图8

    回退版本至 2.10.6 后,继续运行 python migrate.py。数据迁移成功。为何迁移了数据库 0 下的健的总数:53,原因在于自建 Redis 中的数据在变化中所导致。
    图8
    
    [root@iz2zeeh3rrqalw11oajd6zz ~]# python python_redis.py
    (2, 10, 6)
    [root@iz2zeeh3rrqalw11oajd6zz ~]# python migrate.py
    total 53
    string 25
    list 3
    set 0
    hash 25
    
    
    
    

    11、查看腾讯云自带 Redis 中的数据库 0 下的数据。总数:53。确认迁移成功。当腾讯云自带 Redis 为 4.0 版本时,同样能够迁移成功。如图9

    查看腾讯云自带 Redis 中的数据库 0 下的数据。总数:53。确认迁移成功。当腾讯云自带 Redis 为 4.0 版本时,同样能够迁移成功。
    图9
  • Yii 2.0 的 Docker 部署,单域名与多域名模式同时支持的实现

    Yii 2.0 的 Docker 部署,单域名与多域名模式同时支持的实现

    1、从多域名模式修改为单域名模式,修改了文件:frontend/config/main.php。如图1
    从多域名模式修改为单域名模式,修改了文件:frontend/config/main.php。
    图1
    2、从多域名模式修改为单域名模式,修改了文件:etc/nginx/conf.d/ccp_api.conf。如图2
    从多域名模式修改为单域名模式,修改了文件:etc/nginx/conf.d/ccp_api.conf。
    图2
    3、现在计划在容器升级时,基于环境变量:CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE=single|multiple。默认:single。可切换域名模式。 4、决定准备多域名下的两份文件,基于 shell 脚本,判断环境变量:CHANNEL_PUB_API_CFG_DOMAIN_NAME_MODE=multiple,执行文件拷贝。 5、编辑 shell 脚本,/config/init/config.sh。放在其他 shell 脚本之前。如图3
    编辑 shell 脚本,/config/init/config.sh。放在其他 shell 脚本之前。
    图3
    
    
    #!/bin/bash
    env | grep CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE || export CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE="single"
    if [[ $CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE == "multiple" ]]
    then
        \cp /mcloud/ccp_api.conf /etc/nginx/conf.d/
        chmod +x /etc/nginx/conf.d/*
        echo "前端的域名模式:多域名,复制 ccp_api.conf 至 /etc/nginx/conf.d/"
        \cp /mcloud/frontend/config/main.php /mcloud/www/ccp_api/frontend/config/
        echo "前端的域名模式:多域名,复制 main.php 至 /mcloud/www/ccp_api/frontend/config/"
    elif [[ $CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE == "single" ]]
    then
        echo "前端的域名模式:单域名"
    else
        echo "please set environment variable CHANNEL_PUB_API_CFG_FRONTEND_DOMAIN_MODE single or multiple"
    fi
    
    
    
    6、Nginx 未启动。原因在于 config0.sh 先于 config.sh 执行。将 config.sh 重命名为 ccp_init.sh。
    
    
    [root@07ca67a1f3c1 conf.d]# nginx -t
    nginx: [emerg] host not found in "CHANNEL_PUB_API_CFG_NGINX_AUTH_LISTEN" of the "listen" directive in /etc/nginx/conf.d/ccp_api.conf:2
    nginx: configuration file /etc/nginx/nginx.conf test failed
    [root@07ca67a1f3c1 conf.d]#
    
    
    
    7、Nginx 已启动。如图4
    Nginx 已启动。
    图4
    
    
    [root@b9b472c89102 /]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    [root@b9b472c89102 /]#
    
    
    
     
  • 在更新Gutenberg时发生了错误:因为我们不能复制一些文件,升级未被安装。这通常是因为存在不一致的文件权限。

    在更新Gutenberg时发生了错误:因为我们不能复制一些文件,升级未被安装。这通常是因为存在不一致的文件权限。

    1、在更新Gutenberg时发生了错误:因为我们不能复制一些文件,升级未被安装。这通常是因为存在不一致的文件权限。如图1
    在更新Gutenberg时发生了错误:因为我们不能复制一些文件,升级未被安装。这通常是因为存在不一致的文件权限。
    图1
    2、参考网址:https://www.shuijingwanwq.com/2021/02/19/4734/ 。原因在于之前更新Gutenberg时,也使用了 root 用户进行操作更新所导致。 3、登录服务器,查看 /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins/gutenberg 的用户与用户组皆为 root。如图2
    登录服务器,查看 /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins/gutenberg 的用户与用户组皆为 root。
    图2
    
    
    [root@iZ23wv7v5ggZ wp-admin]# cd /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins
    [root@iZ23wv7v5ggZ plugins]# ls -l
    total 68
    drwxr-xr-x  4 www  www  4096 Mar  8 10:03 akismet
    drwxr-xr-x 10 www  www  4096 Mar  9 09:44 backupwordpress
    drwxr-xr-x  3 www  www  4096 Aug 13  2020 classic-editor
    drwxr-xr-x  7 www  www  4096 Mar  1 15:31 contact-form-7
    drwxr-xr-x  2 www  www  4096 Dec  5  2019 disable-google-fonts
    drwxr-xr-x  2 www  www  4096 Dec  5  2019 golang-brush-for-syntaxhighlighter-evolved
    drwxr-xr-x  6 root root 4096 Apr  1 21:11 gutenberg
    drwxr-xr-x  2 www  www  4096 Dec  5  2019 hello-dolly
    drwxr-xr-x  6 www  www  4096 Feb 19 11:30 hueman-addons
    -rw-r--r--  1 www  www    30 Apr 16  2009 index.php
    drwxr-xr-x  4 www  www  4096 Apr  9  2020 kill-429
    drwxr-xr-x  6 www  www  4096 Dec  5  2019 light
    drwxr-xr-x  5 www  www  4096 Mar 31 10:44 nimble-builder
    drwxr-xr-x  6 www  www  4096 Mar  9 09:44 regenerate-thumbnails
    drwxr-xr-x  6 www  www  4096 Mar 11 10:27 syntaxhighlighter
    drwxr-xr-x  2 www  www  4096 Dec  5  2019 wp-cumulus
    drwxr-xr-x  3 www  www  4096 Feb 24 10:06 wp-pagenavi
    
    
    
    
    4、设置目录 gutenberg 的用户与用户组为 www。如图3
    设置目录 gutenberg 的用户与用户组为 www。
    图3
    
    
    [root@iZ23wv7v5ggZ plugins]# chown -R www:www gutenberg
    [root@iZ23wv7v5ggZ plugins]# ls -l
    total 68
    drwxr-xr-x  4 www www 4096 Mar  8 10:03 akismet
    drwxr-xr-x 10 www www 4096 Mar  9 09:44 backupwordpress
    drwxr-xr-x  3 www www 4096 Aug 13  2020 classic-editor
    drwxr-xr-x  7 www www 4096 Mar  1 15:31 contact-form-7
    drwxr-xr-x  2 www www 4096 Dec  5  2019 disable-google-fonts
    drwxr-xr-x  2 www www 4096 Dec  5  2019 golang-brush-for-syntaxhighlighter-evolved
    drwxr-xr-x  6 www www 4096 Apr  1 21:11 gutenberg
    drwxr-xr-x  2 www www 4096 Dec  5  2019 hello-dolly
    drwxr-xr-x  6 www www 4096 Feb 19 11:30 hueman-addons
    -rw-r--r--  1 www www   30 Apr 16  2009 index.php
    drwxr-xr-x  4 www www 4096 Apr  9  2020 kill-429
    drwxr-xr-x  6 www www 4096 Dec  5  2019 light
    drwxr-xr-x  5 www www 4096 Mar 31 10:44 nimble-builder
    drwxr-xr-x  6 www www 4096 Mar  9 09:44 regenerate-thumbnails
    drwxr-xr-x  6 www www 4096 Mar 11 10:27 syntaxhighlighter
    drwxr-xr-x  2 www www 4096 Dec  5  2019 wp-cumulus
    drwxr-xr-x  3 www www 4096 Feb 24 10:06 wp-pagenavi
    [root@iZ23wv7v5ggZ plugins]#
    
    
    
    5、再次更新Gutenberg,成功更新。如图4
    再次更新Gutenberg,成功更新。
    图4
  • ./yii 无输出的排查分析

    ./yii 无输出的排查分析

    1、参考网址:https://www.shuijingwanwq.com/2021/04/15/4859/ 。基于 Composer 更新 Yii 2 至最新版本,将 Yii Framework 从 2.0.35 版本升级到 2.0.41.1。./yii 无输出。如图1

    参考网址:https://www.shuijingwanwq.com/2021/04/15/4859/ 。基于 Composer 更新 Yii 2 至最新版本,将 Yii Framework 从 2.0.35 版本升级到 2.0.41.1。./yii 无输出。
    图1
    
    [root@api-78b4b688b4-l26vd ccp_api]# ./yii
    [root@api-78b4b688b4-l26vd ccp_api]# 
    
    
    

    2、./yii 有输出的正常情况。如图2

    ./yii 有输出的正常情况。
    图2

    3、编辑 ./yii 文件,有输出:0。如图3

    编辑 ./yii 文件,有输出:0。
    图3
    #!/usr/bin/env php
    <?php
    /**
     * Yii console bootstrap file.
     */
     
    defined('YII_DEBUG') or define('YII_DEBUG', true);
    defined('YII_ENV') or define('YII_ENV', 'dev');
    echo 0;
    exit;
    require __DIR__ . '/vendor/autoload.php';
    require __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
    require __DIR__ . '/common/config/bootstrap.php';
    require __DIR__ . '/console/config/bootstrap.php';
    $config = yii\helpers\ArrayHelper::merge(
        require __DIR__ . '/common/config/main.php',
        require __DIR__ . '/common/config/main-local.php',
        require __DIR__ . '/console/config/main.php',
        require __DIR__ . '/console/config/main-local.php'
    );
     
    $application = new yii\console\Application($config);
    $exitCode = $application->run();
    exit($exitCode);
     
    

    4、编辑 ./yii 文件,无输出。可以确定与 /vendor 存在关系了。

    <?php
    /**
     * Yii console bootstrap file.
     */
     
    defined('YII_DEBUG') or define('YII_DEBUG', true);
    defined('YII_ENV') or define('YII_ENV', 'dev');
    require __DIR__ . '/vendor/autoload.php';
    echo 1;
    exit;
    require __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
    require __DIR__ . '/common/config/bootstrap.php';
    require __DIR__ . '/console/config/bootstrap.php';
    $config = yii\helpers\ArrayHelper::merge(
        require __DIR__ . '/common/config/main.php',
        require __DIR__ . '/common/config/main-local.php',
        require __DIR__ . '/console/config/main.php',
        require __DIR__ . '/console/config/main-local.php'
    );
     
    $application = new yii\console\Application($config);
    $exitCode = $application->run();
    exit($exitCode);
    

    5、在本地环境中是正常的。如图4

    在本地环境中是正常的。
    图4

    6、对比开发环境与本地环境,/vendor 的差异。因为 /vendor 是放在 Git 中的。chore:再次添加 /vendor。./yii 有输出。如图5

    对比开发环境与本地环境,/vendor 的差异。因为 /vendor 是放在 Git 中的。chore:再次添加 /vendor。./yii 有输出。
    图5

    7、在另外一个工程中,即使按照如上的方式处理后,仍然无输出。如图6

    在另外一个工程中,即使按照如上的方式处理后,仍然无输出。
    图6
    
    [root@api-6b9cd4ddb5-hcrks pcs_api]# ./yii
    [root@api-6b9cd4ddb5-hcrks pcs_api]# 
    
    
    

    8、删除 /vendor,删除 composer.lock,提交。添加 /vendor,添加 composer.lock,提交。./yii 有输出。如图7

    删除 /vendor,删除 composer.lock,提交。添加 /vendor,添加 composer.lock,提交。./yii 有输出。
    图7
    
    [root@api-747859c976-7zj7g pcs_api]# ./yii
    
    This is Yii version 2.0.41.1.
    
    The following commands are available:
    
    - asset                        Allows you to combine and compress your JavaScript and CSS files.
        asset/compress (default)   Combines and compresses the asset files according to the given configuration.
        asset/template             Creates template of configuration file for [[actionCompress]].
    
    - cache                        Allows you to flush cache.
        cache/flush                Flushes given cache components.
        cache/flush-all            Flushes all caches registered in the system.
        cache/flush-schema         Clears DB schema cache for a given connection component.
        cache/index (default)      Lists the caches that can be flushed.
    
    
    

     

  • 基于 Composer 更新 Yii 2 至最新版本,将 Yii Framework 从 2.0.35 版本升级到 2.0.41.1

    基于 Composer 更新 Yii 2 至最新版本,将 Yii Framework 从 2.0.35 版本升级到 2.0.41.1

    1、之前已安装 Composer,为确保使用最新版本。可以通过运行 composer self-update 来更新 Composer 至版本 2.0.12,如图1

    之前已安装 Composer,为确保使用最新版本。可以通过运行 composer self-update 来更新 Composer 至版本 2.0.12
    图1
    
    PS E:\> composer self-update
    Updating to version 2.0.12 (stable channel).
       Downloading (100%)
    Use composer self-update --rollback to return to version 1.10.6
    
    
    

    2、通过运行 composer update 来更新 Yii 2 至最新版本,已将 Yii Framework 从 2.0.35 版本升级到 2.0.41.1,如图2

    通过运行 composer update 来更新 Yii 2 至最新版本,已将 Yii Framework 从 2.0.35 版本升级到 2.0.41.1
    图2
    
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer update
    The "fxp/composer-asset-plugin" plugin (installed globally) was skipped because it requires a Plugin API version ("^1.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
    Loading composer repositories with package information
    Updating dependencies
    Lock file operations: 1 install, 68 updates, 1 removal
      - Removing fzaninotto/faker (v1.9.1)
      - Upgrading behat/gherkin (v4.6.2 => v4.8.0)
      - Upgrading bower-asset/jquery (3.4.1 => 3.5.1)
      - Upgrading codeception/codeception (4.1.5 => 4.1.20)
      - Upgrading codeception/lib-asserts (1.12.0 => 1.13.2)
      - Upgrading codeception/lib-innerbrowser (1.3.1 => 1.4.2)
      - Upgrading codeception/module-asserts (1.2.1 => 1.3.1)
      - Upgrading codeception/module-filesystem (1.0.2 => 1.0.3)
      - Upgrading codeception/module-yii2 (1.1.0 => 1.1.2)
      - Upgrading codeception/phpunit-wrapper (8.1.2 => 8.1.4)
      - Upgrading codeception/stub (3.6.1 => 3.7.0)
      - Upgrading doctrine/instantiator (1.3.1 => 1.4.0)
      - Upgrading egulias/email-validator (2.1.17 => 3.1.1)
      - Upgrading ezyang/htmlpurifier (v4.12.0 => v4.13.0)
      - Locking fakerphp/faker (v1.14.1)
      - Upgrading guzzlehttp/psr7 (1.6.1 => 1.8.1)
      - Upgrading myclabs/deep-copy (1.9.5 => 1.10.2)
      - Upgrading opis/closure (3.5.3 => 3.6.2)
      - Upgrading paragonie/random_compat (v2.0.18 => v2.0.19)
      - Upgrading phar-io/manifest (1.0.3 => 2.0.1)
      - Upgrading phar-io/version (2.0.1 => 3.1.0)
      - Upgrading phpdocumentor/reflection-common (2.1.0 => 2.2.0)
      - Upgrading phpdocumentor/reflection-docblock (5.1.0 => 5.2.2)
      - Upgrading phpdocumentor/type-resolver (1.1.0 => 1.4.0)
      - Upgrading phpspec/php-diff (v1.1.0 => v1.1.3)
      - Upgrading phpspec/prophecy (v1.10.3 => 1.13.0)
      - Upgrading phpunit/php-code-coverage (7.0.10 => 7.0.14)
      - Upgrading phpunit/php-file-iterator (2.0.2 => 2.0.3)
      - Upgrading phpunit/php-timer (2.1.2 => 2.1.3)
      - Upgrading phpunit/php-token-stream (3.1.1 => 4.0.4)
      - Upgrading phpunit/phpunit (8.5.5 => 8.5.15)
      - Upgrading psr/container (1.0.0 => 1.1.1)
      - Upgrading sebastian/code-unit-reverse-lookup (1.0.1 => 1.0.2)
      - Upgrading sebastian/comparator (3.0.2 => 3.0.3)
      - Upgrading sebastian/diff (3.0.2 => 3.0.3)
      - Upgrading sebastian/environment (4.2.3 => 4.2.4)
      - Upgrading sebastian/exporter (3.1.2 => 3.1.3)
      - Upgrading sebastian/global-state (3.0.0 => 3.0.1)
      - Upgrading sebastian/object-enumerator (3.0.3 => 3.0.4)
      - Upgrading sebastian/object-reflector (1.1.1 => 1.1.2)
      - Upgrading sebastian/recursion-context (3.0.0 => 3.0.1)
      - Upgrading sebastian/resource-operations (2.0.1 => 2.0.2)
      - Upgrading sebastian/type (1.1.3 => 1.1.4)
      - Upgrading swiftmailer/swiftmailer (v6.2.3 => v6.2.7)
      - Upgrading symfony/console (v5.1.0 => v5.2.6)
      - Upgrading symfony/css-selector (v5.1.0 => v5.2.4)
      - Upgrading symfony/deprecation-contracts (v2.1.2 => v2.2.0)
      - Upgrading symfony/dom-crawler (v4.4.9 => v4.4.20)
      - Upgrading symfony/event-dispatcher (v5.1.0 => v5.2.4)
      - Upgrading symfony/event-dispatcher-contracts (v2.1.2 => v2.2.0)
      - Upgrading symfony/finder (v5.1.0 => v5.2.4)
      - Upgrading symfony/polyfill-ctype (v1.17.0 => v1.22.1)
      - Upgrading symfony/polyfill-iconv (v1.17.0 => v1.22.1)
      - Upgrading symfony/polyfill-intl-grapheme (v1.17.0 => v1.22.1)
      - Upgrading symfony/polyfill-intl-idn (v1.17.0 => v1.22.1)
      - Upgrading symfony/polyfill-intl-normalizer (v1.17.0 => v1.22.1)
      - Upgrading symfony/polyfill-mbstring (v1.17.0 => v1.22.1)
      - Upgrading symfony/polyfill-php72 (v1.17.0 => v1.22.1)
      - Upgrading symfony/polyfill-php73 (v1.17.0 => v1.22.1)
      - Upgrading symfony/polyfill-php80 (v1.17.0 => v1.22.1)
      - Upgrading symfony/service-contracts (v2.1.2 => v2.2.0)
      - Upgrading symfony/string (v5.1.0 => v5.2.6)
      - Upgrading symfony/yaml (v5.1.0 => v5.2.5)
      - Upgrading theseer/tokenizer (1.1.3 => 1.2.0)
      - Upgrading webmozart/assert (1.8.0 => 1.10.0)
      - Upgrading yiisoft/yii2 (2.0.35 => 2.0.41.1)
      - Upgrading yiisoft/yii2-composer (2.0.9 => 2.0.10)
      - Upgrading yiisoft/yii2-debug (2.1.13 => 2.1.16)
      - Upgrading yiisoft/yii2-faker (2.0.4 => 2.0.5)
      - Upgrading yiisoft/yii2-httpclient (2.0.12 => 2.0.13)
    Writing lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 1 install, 68 updates, 1 removal
      - Downloading yiisoft/yii2-composer (2.0.10)
      - Downloading behat/gherkin (v4.8.0)
      - Downloading bower-asset/jquery (3.5.1)
      - Downloading sebastian/diff (3.0.3)
      - Downloading sebastian/recursion-context (3.0.1)
      - Downloading sebastian/exporter (3.1.3)
      - Downloading sebastian/comparator (3.0.3)
      - Downloading sebastian/type (1.1.4)
      - Downloading sebastian/resource-operations (2.0.2)
      - Downloading sebastian/object-reflector (1.1.2)
      - Downloading sebastian/object-enumerator (3.0.4)
      - Downloading sebastian/global-state (3.0.1)
      - Downloading sebastian/environment (4.2.4)
      - Downloading phpunit/php-timer (2.1.3)
      - Downloading phpunit/php-file-iterator (2.0.3)
      - Downloading theseer/tokenizer (1.2.0)
      - Downloading phpunit/php-token-stream (4.0.4)
      - Downloading phpunit/php-code-coverage (7.0.14)
      - Downloading phpspec/prophecy (1.13.0)
      - Downloading phar-io/version (3.1.0)
      - Downloading phar-io/manifest (2.0.1)
      - Downloading phpunit/phpunit (8.5.15)
      - Downloading codeception/phpunit-wrapper (8.1.4)
      - Downloading codeception/lib-asserts (1.13.2)
      - Downloading symfony/deprecation-contracts (v2.2.0)
      - Downloading symfony/yaml (v5.2.5)
      - Downloading symfony/finder (v5.2.4)
      - Downloading symfony/event-dispatcher-contracts (v2.2.0)
      - Downloading symfony/event-dispatcher (v5.2.4)
      - Downloading symfony/css-selector (v5.2.4)
      - Downloading symfony/string (v5.2.6)
      - Downloading symfony/console (v5.2.6)
      - Downloading guzzlehttp/psr7 (1.8.1)
      - Downloading codeception/stub (3.7.0)
      - Downloading codeception/codeception (4.1.20)
      - Downloading codeception/module-asserts (1.3.1)
      - Downloading codeception/module-filesystem (1.0.3)
      - Downloading symfony/dom-crawler (v4.4.20)
      - Downloading codeception/lib-innerbrowser (1.4.2)
      - Downloading codeception/module-yii2 (1.1.2)
      - Downloading symfony/polyfill-php72 (v1.22.1)
      - Downloading symfony/polyfill-intl-idn (v1.22.1)
      - Downloading egulias/email-validator (3.1.1)
      - Downloading ezyang/htmlpurifier (v4.13.0)
      - Downloading yiisoft/yii2 (2.0.41.1)
      - Downloading yiisoft/yii2-httpclient (2.0.13)
      - Downloading paragonie/random_compat (v2.0.19)
      - Downloading symfony/polyfill-iconv (v1.22.1)
      - Downloading opis/closure (3.6.2)
      - Downloading yiisoft/yii2-debug (2.1.16)
      - Downloading fakerphp/faker (v1.14.1)
      - Downloading yiisoft/yii2-faker (2.0.5)
      - Downloading phpspec/php-diff (v1.1.3)
      - Downloading swiftmailer/swiftmailer (v6.2.7)
      - Removing fzaninotto/faker (v1.9.1)
      - Upgrading yiisoft/yii2-composer (2.0.9 => 2.0.10): Extracting archive
      - Upgrading behat/gherkin (v4.6.2 => v4.8.0): Extracting archive
      - Upgrading bower-asset/jquery (3.4.1 => 3.5.1): Extracting archive
      - Upgrading sebastian/diff (3.0.2 => 3.0.3): Extracting archive
      - Upgrading sebastian/recursion-context (3.0.0 => 3.0.1): Extracting archive
      - Upgrading sebastian/exporter (3.1.2 => 3.1.3): Extracting archive
      - Upgrading sebastian/comparator (3.0.2 => 3.0.3): Extracting archive
      - Upgrading sebastian/type (1.1.3 => 1.1.4): Extracting archive
      - Upgrading sebastian/resource-operations (2.0.1 => 2.0.2): Extracting archive
      - Upgrading sebastian/object-reflector (1.1.1 => 1.1.2): Extracting archive
      - Upgrading sebastian/object-enumerator (3.0.3 => 3.0.4): Extracting archive
      - Upgrading sebastian/global-state (3.0.0 => 3.0.1): Extracting archive
      - Upgrading sebastian/environment (4.2.3 => 4.2.4): Extracting archive
      - Upgrading phpunit/php-timer (2.1.2 => 2.1.3): Extracting archive
      - Upgrading phpunit/php-file-iterator (2.0.2 => 2.0.3): Extracting archive
      - Upgrading theseer/tokenizer (1.1.3 => 1.2.0): Extracting archive
      - Upgrading sebastian/code-unit-reverse-lookup (1.0.1 => 1.0.2): Extracting archive
      - Upgrading phpunit/php-token-stream (3.1.1 => 4.0.4): Extracting archive
      - Upgrading phpunit/php-code-coverage (7.0.10 => 7.0.14): Extracting archive
      - Upgrading symfony/polyfill-ctype (v1.17.0 => v1.22.1): Extracting archive
      - Upgrading webmozart/assert (1.8.0 => 1.10.0): Extracting archive
      - Upgrading phpdocumentor/reflection-common (2.1.0 => 2.2.0): Extracting archive
      - Upgrading phpdocumentor/type-resolver (1.1.0 => 1.4.0): Extracting archive
      - Upgrading phpdocumentor/reflection-docblock (5.1.0 => 5.2.2): Extracting archive
      - Upgrading doctrine/instantiator (1.3.1 => 1.4.0): Extracting archive
      - Upgrading phpspec/prophecy (v1.10.3 => 1.13.0): Extracting archive
      - Upgrading phar-io/version (2.0.1 => 3.1.0): Extracting archive
      - Upgrading phar-io/manifest (1.0.3 => 2.0.1): Extracting archive
      - Upgrading myclabs/deep-copy (1.9.5 => 1.10.2): Extracting archive
      - Upgrading phpunit/phpunit (8.5.5 => 8.5.15): Extracting archive
      - Upgrading codeception/phpunit-wrapper (8.1.2 => 8.1.4): Extracting archive
      - Upgrading codeception/lib-asserts (1.12.0 => 1.13.2): Extracting archive
      - Upgrading symfony/deprecation-contracts (v2.1.2 => v2.2.0): Extracting archive
      - Upgrading symfony/yaml (v5.1.0 => v5.2.5): Extracting archive
      - Upgrading symfony/finder (v5.1.0 => v5.2.4): Extracting archive
      - Upgrading symfony/polyfill-php80 (v1.17.0 => v1.22.1): Extracting archive
      - Upgrading symfony/event-dispatcher-contracts (v2.1.2 => v2.2.0): Extracting archive
      - Upgrading symfony/event-dispatcher (v5.1.0 => v5.2.4): Extracting archive
      - Upgrading symfony/css-selector (v5.1.0 => v5.2.4): Extracting archive
      - Upgrading symfony/polyfill-mbstring (v1.17.0 => v1.22.1): Extracting archive
      - Upgrading symfony/polyfill-intl-normalizer (v1.17.0 => v1.22.1): Extracting archive
      - Upgrading symfony/polyfill-intl-grapheme (v1.17.0 => v1.22.1): Extracting archive
      - Upgrading symfony/string (v5.1.0 => v5.2.6): Extracting archive
      - Upgrading psr/container (1.0.0 => 1.1.1): Extracting archive
      - Upgrading symfony/service-contracts (v2.1.2 => v2.2.0): Extracting archive
      - Upgrading symfony/polyfill-php73 (v1.17.0 => v1.22.1): Extracting archive
      - Upgrading symfony/console (v5.1.0 => v5.2.6): Extracting archive
      - Upgrading guzzlehttp/psr7 (1.6.1 => 1.8.1): Extracting archive
      - Upgrading codeception/stub (3.6.1 => 3.7.0): Extracting archive
      - Upgrading codeception/codeception (4.1.5 => 4.1.20): Extracting archive
      - Upgrading codeception/module-asserts (1.2.1 => 1.3.1): Extracting archive
      - Upgrading codeception/module-filesystem (1.0.2 => 1.0.3): Extracting archive
      - Upgrading symfony/dom-crawler (v4.4.9 => v4.4.20): Extracting archive
      - Upgrading codeception/lib-innerbrowser (1.3.1 => 1.4.2): Extracting archive
      - Upgrading codeception/module-yii2 (1.1.0 => 1.1.2): Extracting archive
      - Upgrading symfony/polyfill-php72 (v1.17.0 => v1.22.1): Extracting archive
      - Upgrading symfony/polyfill-intl-idn (v1.17.0 => v1.22.1): Extracting archive
      - Upgrading egulias/email-validator (2.1.17 => 3.1.1): Extracting archive
      - Upgrading ezyang/htmlpurifier (v4.12.0 => v4.13.0): Extracting archive
      - Upgrading yiisoft/yii2 (2.0.35 => 2.0.41.1): Extracting archive
      - Upgrading yiisoft/yii2-httpclient (2.0.12 => 2.0.13): Extracting archive
      - Upgrading paragonie/random_compat (v2.0.18 => v2.0.19): Extracting archive
      - Upgrading symfony/polyfill-iconv (v1.17.0 => v1.22.1): Extracting archive
      - Upgrading opis/closure (3.5.3 => 3.6.2): Extracting archive
      - Upgrading yiisoft/yii2-debug (2.1.13 => 2.1.16): Extracting archive
      - Installing fakerphp/faker (v1.14.1): Extracting archive
      - Upgrading yiisoft/yii2-faker (2.0.4 => 2.0.5): Extracting archive
      - Upgrading phpspec/php-diff (v1.1.0 => v1.1.3): Extracting archive
      - Upgrading swiftmailer/swiftmailer (v6.2.3 => v6.2.7): Extracting archive
    Package flow/jsonpath is abandoned, you should avoid using it. Use softcreatr/jsonpath instead.
    Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
    Generating autoload files
    47 packages you are using are looking for funding.
    Use the `composer fund` command to find out more!
    
      Seems you have upgraded Yii Framework from version 2.0.35 to 2.0.41.1.
    
      Please check the upgrade notes for possible incompatible changes
      and adjust your application code accordingly.
    
      Upgrade from Yii 2.0.40
      -----------------------
    
      * The methods `getAuthKey()` and `validateAuthKey()` of `yii\web\IdentityInterface` are now also used to validate active
        sessions (previously these methods were only used for cookie-based login). If your identity class does not properly
        implement these methods yet, you should update it accordingly (an example can be found in the guide under
        `Security` -> `Authentication`). Alternatively, you can simply return `null` in the `getAuthKey()` method to keep
        the old behavior (that is, no validation of active sessions). Applications that change the underlying `authKey` of
        an authenticated identity, should now call `yii\web\User::switchIdentity()`, `yii\web\User::login()`
        or `yii\web\User::logout()` to recreate the active session with the new `authKey`.
    
      Upgrade from Yii 2.0.39.3
      -------------------------
    
      * Priority of processing `yii\base\Arrayable`, and `JsonSerializable` data has been reversed (`Arrayable` data is checked
        first now) in `yii\base\Model`, and `yii\rest\Serializer`. If your application relies on the previous priority you need
        to fix it manually based on the complexity of desired (de)serialization result.
    
      Upgrade from Yii 2.0.38
      -----------------------
    
      * The storage structure of the file cache has been changed when you use `\yii\caching\FileCache::$keyPrefix`.
      It is worth warming up the cache again if there is a logical dependency when working with the file cache.
    
      * `yii\web\Session` now respects the 'session.use_strict_mode' ini directive.
        In case you use a custom `Session` class and have overwritten the `Session::openSession()` and/or
        `Session::writeSession()` functions changes might be required:
        * When in strict mode the `openSession()` function should check if the requested session id exists
          (and mark it for forced regeneration if not).
          For example, the `DbSession` does this at the beginning of the function as follows:
          ```php
          if ($this->getUseStrictMode()) {
              $id = $this->getId();
              if (!$this->getReadQuery($id)->exists()) {
                  //This session id does not exist, mark it for forced regeneration
                  $this->_forceRegenerateId = $id;
              }
          }
          // ... normal function continues ...
          ```
        * When in strict mode the `writeSession()` function should ignore writing the session under the old id.
          For example, the `DbSession` does this at the beginning of the function as follows:
          ```php
          if ($this->getUseStrictMode() &amp;&amp; $id === $this->_forceRegenerateId) {
              //Ignore write when forceRegenerate is active for this id
              return true;
          }
          // ... normal function continues ...
          ```
        > Note: The sample code above is specific for the `yii\web\DbSession` class.
          Make sure you use the correct implementation based on your parent class,
          e.g. `yii\web\CacheSession`, `yii\redis\Session`, `yii\mongodb\Session`, etc.
    
        > Note: In case your custom functions call their `parent` functions, there are probably no changes needed to your
          code if those parents implement the `useStrictMode` checks.
    
        > Warning: in case `openSession()` and/or `writeSession()` functions do not implement the `useStrictMode` code
          the session could be stored under a malicious id without warning even if `useStrictMode` is enabled.
    
      Upgrade from Yii 2.0.37
      -----------------------
    
      * Resolving DI references inside of arrays in dependencies was made optional and turned off by default. In order
        to turn it on, set `resolveArrays` of container instance to `true`.
    
      Upgrade from Yii 2.0.36
      -----------------------
    
      * `yii\db\Exception::getCode()` now returns full PDO code that is SQLSTATE string. If you have relied on comparing code
        with an integer value, adjust your code.
    
      Upgrade from Yii 2.0.35
      -----------------------
    
      * Inline validator signature has been updated with 4th parameter `current`:
    
        ```php
        /**
         * @param mixed $current the currently validated value of attribute
         */
        function ($attribute, $params, $validator, $current)
        ```
    
      * Behavior of inline validator used as a rule of `EachValidator` has been changed - `$attribute` now refers to original
        model's attribute and not its temporary counterpart:
    
        ```php
        public $array_attribute = ['first', 'second'];
    
        public function rules()
        {
            return [
                ['array_attribute', 'each', 'rule' => ['customValidatingMethod']],
            ];
        }
    
        public function customValidatingMethod($attribute, $params, $validator, $current)
        {
            // $attribute === 'array_attribute' (as before)
    
            // now: $this->$attribute === ['first', 'second'] (on every iteration)
            // previously:
            // $this->$attribute === 'first' (on first iteration)
            // $this->$attribute === 'second' (on second iteration)
    
            // use now $current instead
            // $current === 'first' (on first iteration)
            // $current === 'second' (on second iteration)
        }
        ```
    
      * `$this` in an inline validator defined as closure now refers to model instance. If you need to access the object registering
        the validator, pass its instance through use statement:
    
        ```php
        $registrar = $this;
        $validator = function($attribute, $params, $validator, $current) use ($registrar) {
            // ...
        }
        ```
    
      * Validator closure callbacks should not be declared as static.
    
      * If you have any controllers that override the `init()` method, make sure they are calling `parent::init()` at
        the beginning, as demonstrated in the [component guide](https://www.yiiframework.com/doc/guide/2.0/en/concept-components).
    
      You can find the upgrade notes for all versions online at:
      https://github.com/yiisoft/yii2/blob/2.0.41.1/framework/UPGRADE.md
    
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced>
    
    
    

    3、先解决与 “fxp/composer-asset-plugin” 相关的提示信息。如图3

    先解决与 "fxp/composer-asset-plugin" 相关的提示信息。
    图3
    
    The "fxp/composer-asset-plugin" plugin (installed globally) was skipped because it requires a Plugin API version ("^1.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
    
    
    

    4、参考网址:https://www.yiiframework.com/doc/guide/2.0/zh-cn/structure-assets 。注意: 从 2.0.13 开始,基本和高级应用程序模板都默认配置使用 asset-packagist。决定全局删除 “fxp/composer-asset-plugin”。如图4

    参考网址:https://www.yiiframework.com/doc/guide/2.0/zh-cn/structure-assets 。注意: 从 2.0.13 开始,基本和高级应用程序模板都默认配置使用 asset-packagist。决定全局删除 "fxp/composer-asset-plugin"。
    图4
    
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer global remove fxp/composer-asset-plugin
    Changed current directory to C:/Users/Administrator/AppData/Roaming/Composer
    The "fxp/composer-asset-plugin" plugin was skipped because it requires a Plugin API version ("^1.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
    fxp/composer-asset-plugin is not required in your composer.json and has not been removed
    ./composer.json has been updated
    The "fxp/composer-asset-plugin" plugin was skipped because it requires a Plugin API version ("^1.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
    Running composer update fxp/composer-asset-plugin
    Loading composer repositories with package information
    Updating dependencies
    Lock file operations: 0 installs, 0 updates, 1 removal
      - Removing fxp/composer-asset-plugin (v1.4.4)
    Writing lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 0 installs, 0 updates, 1 removal
      - Removing fxp/composer-asset-plugin (v1.4.4)
    Generating autoload files
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced>
    
    
    

    5、再次运行 composer update 来更新 Yii 2 至最新版本,未再报错与 “fxp/composer-asset-plugin” 相关的提示信息。但是,仍然存在其他的提示信息。如图5

    再次运行 composer update 来更新 Yii 2 至最新版本,未再报错与 "fxp/composer-asset-plugin" 相关的提示信息。但是,仍然存在其他的提示信息。
    图5
    
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer update
    Loading composer repositories with package information
    Updating dependencies
    Nothing to modify in lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 0 installs, 0 updates, 0 removals
    Package flow/jsonpath is abandoned, you should avoid using it. Use softcreatr/jsonpath instead.
    Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
    Generating autoload files
    47 packages you are using are looking for funding.
    Use the `composer fund` command to find out more!
    
    
    

    6、包 flow/jsonpath 被放弃了,您应该避免使用它。请改用 softcreatr/jsonpath。决定卸载 flow/jsonpath ,安装 softcreatr/jsonpath。如图6

    包 flow/jsonpath 被放弃了,您应该避免使用它。请改用 softcreatr/jsonpath。决定卸载 flow/jsonpath ,安装 softcreatr/jsonpath。
    图6
    
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer remove flow/jsonpath
    ./composer.json has been updated
    Running composer update flow/jsonpath
    Loading composer repositories with package information
    Updating dependencies
    Lock file operations: 0 installs, 0 updates, 1 removal
      - Removing flow/jsonpath (0.5.0)
    Writing lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 0 installs, 0 updates, 1 removal
      - Removing flow/jsonpath (0.5.0)
    Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
    Generating autoload files
    47 packages you are using are looking for funding.
    Use the `composer fund` command to find out more!
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer require --prefer-dist softcreatr/jsonpath
    Using version ^0.7.3 for softcreatr/jsonpath
    ./composer.json has been updated
    Running composer update softcreatr/jsonpath
    Loading composer repositories with package information
    Updating dependencies
    Lock file operations: 1 install, 0 updates, 0 removals
      - Locking softcreatr/jsonpath (0.7.3)
    Writing lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 1 install, 0 updates, 0 removals
      - Downloading softcreatr/jsonpath (0.7.3)
      - Installing softcreatr/jsonpath (0.7.3): Extracting archive
    Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
    Generating autoload files
    48 packages you are using are looking for funding.
    Use the `composer fund` command to find out more!
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced>
    
    
    

    7、软件包 phpunit/php-token-stream 被放弃了,您应该避免使用它。没有建议更换。使用 依赖性检测 depends 命令可以查出已安装在你项目中的某个包,是否正在被其它的包所依赖,并列出他们。得出结论:phpunit/php-code-coverage 依赖于 phpunit/php-token-stream,codeception/phpunit-wrapper、phpunit/phpunit 依赖于 phpunit/php-code-coverage,codeception/codeception、codeception/lib-asserts、codeception/verify 依赖于 codeception/phpunit-wrapper,层层依赖。决定保持此提示,暂时无解决方案。如图7

    软件包 phpunit/php-token-stream 被放弃了,您应该避免使用它。没有建议更换。使用 依赖性检测 depends 命令可以查出已安装在你项目中的某个包,是否正在被其它的包所依赖,并列出他们。得出结论:phpunit/php-code-coverage 依赖于 phpunit/php-token-stream,codeception/phpunit-wrapper、phpunit/phpunit 依赖于 phpunit/php-code-coverage,codeception/codeception、codeception/lib-asserts、codeception/verify 依赖于 codeception/phpunit-wrapper,层层依赖。决定保持此提示,暂时无解决方案。
    图7
    
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer depends phpunit/php-token-stream
    phpunit/php-code-coverage  7.0.14  requires  phpunit/php-token-stream (^3.1.1 || ^4.0)
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer depends phpunit/php-code-coverage
    codeception/phpunit-wrapper  8.1.4   requires  phpunit/php-code-coverage (^7.0)    
    phpunit/phpunit              8.5.15  requires  phpunit/php-code-coverage (^7.0.12) 
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer depends codeception/phpunit-wrapper
    codeception/codeception  4.1.20  requires  codeception/phpunit-wrapper (>6.0.15 &lt;6.1.0 | ^6.6.1 | ^7.7.1 | ^8.1.1 | ^9.0)
    codeception/lib-asserts  1.13.2  requires  codeception/phpunit-wrapper (>6.0.15 &lt;6.1.0 | ^6.6.1 | ^7.7.1 | ^8.0.3 | ^9.0)
    codeception/verify       1.1.0   requires  codeception/phpunit-wrapper (>6.0.15 &lt;6.1.0 | ^6.6.1 | ^7.7.1 | ^8.0.4)
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer depends codeception/codeception
    shuijingwan/yii2-app-advanced  dev-master  requires (for development)  codeception/codeception (^4.0)
    codeception/lib-innerbrowser   1.4.2       requires                    codeception/codeception (*@dev)
    codeception/module-asserts     1.3.1       requires                    codeception/codeception (*@dev)
    codeception/module-filesystem  1.0.3       requires                    codeception/codeception (^4.0)
    codeception/module-yii2        1.1.2       requires                    codeception/codeception (^4.0)
    PS E:\wwwroot\github-shuijingwan-yii2-app-advanced> composer depends phpunit/phpunit
    codeception/phpunit-wrapper  8.1.4  requires  phpunit/phpunit (^8.0)
    codeception/stub             3.7.0  requires  phpunit/phpunit (^8.4 | ^9.0)
    codeception/verify           1.1.0  requires  phpunit/phpunit (> 6.0)
    
    
    

    8、在线查看 Yii Framework 2.0 升级说明:https://github.com/yiisoft/yii2/blob/2.0.41.1/framework/UPGRADE.md ,了解可能不兼容的更改,比如,扩展了某些类,而这些类的属性与方法在新版本中有所调整。

     

  • 在 Yii 2.0 中报错:Malformed UTF-8 characters, possibly incorrectly encoded. 的排查分析

    在 Yii 2.0 中报错:Malformed UTF-8 characters, possibly incorrectly encoded. 的排查分析

    1、在 Yii 2.0 中报错:Malformed UTF-8 characters, possibly incorrectly encoded.

    
    {
        "name": "Exception",
        "message": "Malformed UTF-8 characters, possibly incorrectly encoded.",
        "code": 5,
        "type": "yii\\base\\InvalidArgumentException",
        "file": "E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\helpers\\BaseJson.php",
        "line": 133,
        "stack-trace": [
            "#0 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\helpers\\BaseJson.php(67): yii\\helpers\\BaseJson::handleJsonError(5)",
            "#1 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\web\\JsonResponseFormatter.php(119): yii\\helpers\\BaseJson::encode('SQLSTATE[HY000]...', 320)",
            "#2 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\web\\JsonResponseFormatter.php(104): yii\\web\\JsonResponseFormatter->formatJson(Object(yii\\web\\Response))",
            "#3 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\web\\Response.php(1070): yii\\web\\JsonResponseFormatter->format(Object(yii\\web\\Response))",
            "#4 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\web\\Response.php(337): yii\\web\\Response->prepare()",
            "#5 E:\\wwwroot\\pcs-api-feature-base-3.0\\vendor\\yiisoft\\yii2\\base\\Application.php(392): yii\\web\\Response->send()",
            "#6 E:\\wwwroot\\pcs-api-feature-base-3.0\\api\\web\\index.php(17): yii\\base\\Application->run()",
            "#7 {main}"
        ]
    }
    
    
    

    2、查看代码如下

    <?php
     
    namespace api\rests\check_status;
     
    use Yii;
    use yii\web\HttpException;
    use yii\base\Exception;
    use yii\data\ActiveDataProvider;
    use yii\data\DataFilter;
     
    class IndexAction extends \yii\rest\IndexAction
    {
        /**
         * @return int|string|ActiveDataProvider|DataFilter|null
         */
        public function run()
        {
            try {
                Yii::$app->db->open();
                if (!Yii::$app->redis->ping()){
                    throw new HttpException(500, 'Redis is unavailable.');
                } elseif (!Yii::$app->db->getIsActive()){
                    throw new HttpException(500, 'Database is unavailable.');
                } else {
                    return 200;
                }
            } catch (Exception $e) {
                $res = Yii::$app->response;
                $res->statusCode = 500;
                return $e->getMessage();
            }
        }
    }
     
    

    3、打印输出 $e->getMessage(),其中包含乱码。如图1

    打印输出 $e->getMessage(),其中包含乱码。
    图1
    
    SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: ��֪��������������
    
    
    

    4、编辑代码,mb_convert_encoding — 转换字符的编码。响应状态码为:500,响应体为:”SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。 “。如图2

    编辑代码,mb_convert_encoding — 转换字符的编码。响应状态码为:500,响应体为:"SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。 "。
    图2
    <?php
     
    namespace api\rests\check_status;
     
    use Yii;
    use yii\web\HttpException;
    use yii\base\Exception;
    use yii\data\ActiveDataProvider;
    use yii\data\DataFilter;
     
    class IndexAction extends \yii\rest\IndexAction
    {
        /**
         * @return array|false|int|string|string[]|ActiveDataProvider|DataFilter|null
         */
        public function run()
        {
            try {
                Yii::$app->db->open();
                if (!Yii::$app->redis->ping()){
                    throw new HttpException(500, 'Redis is unavailable.');
                } elseif (!Yii::$app->db->getIsActive()){
                    throw new HttpException(500, 'Database is unavailable.');
                } else {
                    return 200;
                }
            } catch (Exception $e) {
                Yii::$app->response->statusCode = 500;
                $message = mb_convert_encoding($e->getMessage(), "UTF-8", ["UTF-8", "GBK", "GB2312", "BIG5"]);
                return $message;
            }
        }
    }
    

    5、初步推测,不知道这样的主机是由 Windows 10 系统返回的。与是否是中文无甚关系,而是与中文本身的编码存在关系。因为 message 为:”Failed to open redis DB connection (tcp://localhost:63799, database=57): 10061 – 由于目标计算机积极拒绝,无法连接。\r\n” 时,未转换字符的编码也是可以正常运行的。

  • CakePHP 2.x 版本的部署,Warning: SplFileInfo::openFile(/app/tmp/cache/persistent/myapp_cake_core_file_map): failed to open stream: Permission denied in /lib/Cake/Cache/Engine/FileEngine.php on line 356

    CakePHP 2.x 版本的部署,Warning: SplFileInfo::openFile(/app/tmp/cache/persistent/myapp_cake_core_file_map): failed to open stream: Permission denied in /lib/Cake/Cache/Engine/FileEngine.php on line 356

    1、CakePHP 2.x 版本的部署,Warning: SplFileInfo::openFile(/mcloud/creditshop_back/creditshopback/app/tmp/cache/persistent/myapp_cake_core_file_map): failed to open stream: Permission denied in /mcloud/creditshop_back/creditshopback/lib/Cake/Cache/Engine/FileEngine.php on line 356。如图1
    CakePHP 2.x 版本的部署,Warning: SplFileInfo::openFile(/mcloud/creditshop_back/creditshopback/app/tmp/cache/persistent/myapp_cake_core_file_map): failed to open stream: Permission denied in /mcloud/creditshop_back/creditshopback/lib/Cake/Cache/Engine/FileEngine.php on line 356。
    图1
    2、进入目录:/mcloud/creditshop_back/creditshopback/app/tmp/cache/persistent,查看所属用户与用户组,皆为:root。如图2
    进入目录:/mcloud/creditshop_back/creditshopback/app/tmp/cache/persistent,查看所属用户与用户组,皆为:root。
    图2
    
    
    [root@back-86667bcfcb-p95js /]# cd /mcloud/creditshop_back/creditshopback/app/tmp/cache/persistent
    [root@back-86667bcfcb-p95js persistent]# ls -l
    total 20
    -rw-rw-r-- 1 root  root    43 Apr  7 20:15 myapp_cake_core_cake_console_zho
    -rw-rw-r-- 1 root  root    43 Apr  7 20:15 myapp_cake_core_cake_dev_zho
    -rw-rw-r-- 1 nginx nginx  225 Apr  8 10:06 myapp_cake_core_default_zho
    -rw-rw-r-- 1 root  root  3239 Apr  7 20:15 myapp_cake_core_file_map
    -rw-rw-r-- 1 nginx nginx  633 Apr  8 10:06 myapp_cake_core_method_cache
    [root@back-86667bcfcb-p95js persistent]# 
    
    
    
    3、参考网址:https://book.cakephp.org/2/zh/installation.html 。设置访问权限。app/tmp 目录及其子目录必须同时能够被 web 服务器和命令行用户写入。
    
    
    HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1`
    setfacl -R -m u:${HTTPDUSER}:rwx app/tmp
    setfacl -R -d -m u:${HTTPDUSER}:rwx app/tmp
    
    
    
    4、编辑 Dockerfile。确保在 CakePHP 安装中 app/tmp 目录及其全部子目录可以被 web 服务器用户 写入。
    
    
        chown -R 775 /mcloud/creditshop_back/creditshopback/app/tmp/ && \
    
    
    
    
    
        cd /mcloud/creditshop_back/creditshopback &&\
        HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1` &&\
        setfacl -R -m u:${HTTPDUSER}:rwx app/tmp &&\
        setfacl -R -d -m u:${HTTPDUSER}:rwx app/tmp &&\
    
    
    
    5、升级后,Nginx 用户写入成功,访问正常。  
  • MySQL 表注释、字段注释、值皆为乱码的解决

    MySQL 表注释、字段注释、值皆为乱码的解决

    1、表的注释乱码。如图1
    表的注释乱码。
    图1
    2、字段的注释乱码。如图2
    字段的注释乱码。
    图2
    3、表中的值乱码。如图3
    表中的值乱码。
    图3
    4、在 SQL 文件的最开头添加:SET NAMES utf8mb4;
    
    
    SET NAMES utf8mb4;
    
    
    
    5、表注释、字段注释、值皆不再乱码。如图4
    表注释、字段注释、值皆不再乱码。
    图4
  • 在 Yii 2.0 的数据库迁移时报错:Exception: Redis error: ERR Client sent AUTH, but no password is set

    在 Yii 2.0 的数据库迁移时报错:Exception: Redis error: ERR Client sent AUTH, but no password is set

    1、在 Yii 2.0 的数据库迁移时报错:Exception: Redis error: ERR Client sent AUTH, but no password is set。如图1

    在 Yii 2.0 的数据库迁移时报错:Exception: Redis error: ERR Client sent AUTH, but no password is set。
    图1
    
    *** applying m191113_084655_sync_redis_wx_auth_data_to_mysql
    Exception: Redis error: ERR Client sent AUTH, but no password is set
    Redis command was: AUTH Redis (E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2-redis\src\Connection.php:821)
    #0 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2-redis\src\Connection.php(789): yii\redis\Connection->parseResponse(Array, '*2\r\n$4\r\nAUTH\r\n$...')
    #1 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2-redis\src\Connection.php(772): yii\redis\Connection->sendCommandInternal('*2\r\n$4\r\nAUTH\r\n$...', Array)
    #2 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2-redis\src\Connection.php(634): yii\redis\Connection->executeCommand('AUTH', Array)
    #3 E:\wwwroot\channel-pub-api\console\migrations\m191113_084655_sync_redis_wx_auth_data_to_mysql.php(27): yii\redis\Connection->open()
    #4 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\db\Migration.php(114): m191113_084655_sync_redis_wx_auth_data_to_mysql->safeUp()
    #5 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(725): yii\db\Migration->up()
    #6 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(200): yii\console\controllers\BaseMigrateController->migrateUp('m191113_084655_...')
    #7 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
    #8 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
    #9 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
    #10 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\console\Controller.php(164): yii\base\Controller->runAction('', Array)
    #11 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('', Array)
    #12 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate', Array)
    #13 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('migrate', Array)
    #14 E:\wwwroot\channel-pub-api\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
    #15 E:\wwwroot\channel-pub-api\yii(23): yii\base\Application->run()
    #16 {main}
    *** failed to apply m191113_084655_sync_redis_wx_auth_data_to_mysql (time: 0.011s)
    
    
    
    

    2、打开终端并连接 redis-cli,测试 AUTH Redis。报错:(error) ERR Client sent AUTH, but no password is set

    
    PS E:\wwwroot\channel-pub-api> redis-cli
    127.0.0.1:6379> AUTH Redis
    (error) ERR Client sent AUTH, but no password is set
    127.0.0.1:6379>
    
    
    

    3、编辑 redis.windows.conf 与 redis.windows-service.conf ,添加 requirepass Redis。

    
    ################################## SECURITY ###################################
    
    # Require clients to issue AUTH  before processing any other
    # commands.  This might be useful in environments in which you do not trust
    # others with access to the host running redis-server.
    #
    # This should stay commented out for backward compatibility and because most
    # people do not need auth (e.g. they run their own servers).
    # 
    # Warning: since Redis is pretty fast an outside user can try up to
    # 150k passwords per second against a good box. This means that you should
    # use a very strong password otherwise it will be very easy to break.
    #
    requirepass Redis
    
    
    

    4、在 Windows 10 中,停止与启动 Redis

    
    PS E:\wwwroot\channel-pub-api> redis-server --service-stop
    [29528] 30 Mar 14:04:24.076 # Redis service successfully stopped.
    PS E:\wwwroot\channel-pub-api> redis-server --service-start
    [28132] 30 Mar 14:04:34.748 # Redis service successfully started.
    
    
    

    5、打开终端并连接 redis-cli,测试 AUTH Redis。响应 OK。如图2

    打开终端并连接 redis-cli,测试 AUTH Redis。响应 OK。
    图2
    
    PS E:\wwwroot\channel-pub-api> redis-cli
    127.0.0.1:6379> AUTH Redis
    OK
    127.0.0.1:6379>
    
    
    

    6、在 Yii 2.0 的数据库迁移时迁移成功。如图3

    在 Yii 2.0 的数据库迁移时迁移成功。
    图3
    
    *** applying m191113_084655_sync_redis_wx_auth_data_to_mysql
    *** applied m191113_084655_sync_redis_wx_auth_data_to_mysql (time: 0.266s)