Laravel 6 – 永夜 https://www.shuijingwanwq.com 没有不值得去解决的问题,也没有不值得去学习的技术! Thu, 21 May 2026 11:33:06 +0000 zh-Hans hourly 1 https://wordpress.org/?v=7.0 在 Laravel 6 ,队列任务失败后,异常信息未写入表 failed_jobs 中 https://www.shuijingwanwq.com/2023/12/21/8293/ https://www.shuijingwanwq.com/2023/12/21/8293/#respond Thu, 21 Dec 2023 03:30:51 +0000 location]]> https://www.shuijingwanwq.com/?p=8293 Post Views: 88 1、当一个队列任务失败后,执行到 任务失败后清理 failed 方法。抛出异常,发现与 telescope 有关


[2023-11-20 17:25:42] local.ERROR: file_get_contents(E:\wwwroot\object\storage\app\theme_downloads\2023\11\20\1700472319.9435.1423840798\migrations\migrate_settings_data.php): failed to open stream: No such file or directory {
    "exception": "[object] (ErrorException(code: 0): file_get_contents(E:\\wwwroot\\wshop\\platform\\storage\\app\\theme_downloads\\2023\\11\\20\\1700472319.9435.1423840798\\migrations\\migrate_settings_data.php): failed to open stream: No such file or directory at E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\telescope\\src\\ExceptionContext.php:45)
[stacktrace]
#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'file_get_conten...', 'E:\\\\wwwroot\\\\wsho...', 45, Array)
#1 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\telescope\\src\\ExceptionContext.php(45): file_get_contents('E:\\\\wwwroot\\\\wsho...')
#2 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\telescope\\src\\ExceptionContext.php(19): Laravel\\Telescope\\ExceptionContext::getFileContext(Object(ErrorException))
#3 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\telescope\\src\\Watchers\\JobWatcher.php(108): Laravel\\Telescope\\ExceptionContext::get(Object(ErrorException))
#4 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Events\\Dispatcher.php(369): Laravel\\Telescope\\Watchers\\JobWatcher->recordFailedJob(Object(Illuminate\\Queue\\Events\\JobFailed))
#5 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Events\\Dispatcher.php(218): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}('Illuminate\\\\Queu...', Array)
#6 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Jobs\\Job.php(185): Illuminate\\Events\\Dispatcher->dispatch('Illuminate\\\\Queu...')
#7 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(482): Illuminate\\Queue\\Jobs\\Job->fail(Object(ErrorException))
#8 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(469): Illuminate\\Queue\\Worker->failJob(Object(Illuminate\\Queue\\Jobs\\RedisJob), Object(ErrorException))
#9 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(399): Illuminate\\Queue\\Worker->markJobAsFailedIfWillExceedMaxAttempts('redis', Object(Illuminate\\Queue\\Jobs\\RedisJob), 1, Object(ErrorException))
#10 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(372): Illuminate\\Queue\\Worker->handleJobException('redis', Object(Illuminate\\Queue\\Jobs\\RedisJob), Object(Illuminate\\Queue\\WorkerOptions), Object(ErrorException))
#11 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(314): Illuminate\\Queue\\Worker->process('redis', Object(Illuminate\\Queue\\Jobs\\RedisJob), Object(Illuminate\\Queue\\WorkerOptions))
#12 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(134): Illuminate\\Queue\\Worker->runJob(Object(Illuminate\\Queue\\Jobs\\RedisJob), 'redis', Object(Illuminate\\Queue\\WorkerOptions))
#13 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Console\\WorkCommand.php(112): Illuminate\\Queue\\Worker->daemon('redis', 'default', Object(Illuminate\\Queue\\WorkerOptions))
#14 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Console\\WorkCommand.php(96): Illuminate\\Queue\\Console\\WorkCommand->runWorker('redis', 'default')
#15 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle()
#16 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Util.php(37): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#17 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#18 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#19 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(590): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#20 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(134): Illuminate\\Container\\Container->call(Array)
#21 E:\\wwwroot\\wshop\\platform\\vendor\\symfony\\console\\Command\\Command.php(255): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#22 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#23 E:\\wwwroot\\wshop\\platform\\vendor\\symfony\\console\\Application.php(1021): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#24 E:\\wwwroot\\wshop\\platform\\vendor\\symfony\\console\\Application.php(275): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#25 E:\\wwwroot\\wshop\\platform\\vendor\\symfony\\console\\Application.php(149): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#26 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Application.php(93): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#27 E:\\wwwroot\\wshop\\platform\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(131): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#28 E:\\wwwroot\\wshop\\platform\\artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#29 {main}
"
} 


2、使用 queue:work Artisan 命令运行处理器,发现队列任务一直未结束,也未失败。如图1
使用 queue:work Artisan 命令运行处理器,发现队列任务一直未结束,也未失败

图1



PS E:\wwwroot\object> php artisan queue:work
[2023-11-20 17:25:19][4kBhJcMDrWBEuf8ZWskA9ikQlGbu9kBL] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb


3、查看表 failed_jobs 中,也未新增加记录。如图2
查看表 failed_jobs 中,也未新增加记录

图2

4、在 .env 文件,禁用 telescope ,再次执行队列任务,表 failed_jobs 中已经成功增加新记录。如图3
在 .env 文件,禁用 telescope ,再次执行队列任务,表 failed_jobs 中已经成功增加新记录

图3



TELESCOPE_ENABLED=false


5、还原第 4 步骤,根源应该在于执行了 View::addLocation($this->location); 方法所导致,也执行了方法 View::flushFinderCache(); 。然后又删除掉了目录 $this->location。决定不再删除目录 $this->location。使用 queue:work Artisan 命令运行处理器,发现队列任务已经失败。且 表 failed_jobs 中,也已经新增加记录。如图4
还原第 4 步骤,根源应该在于执行了 View::addLocation($this->location); 方法所导致,也执行了方法 View::flushFinderCache(); 。然后又删除掉了目录 $this->location。决定不再删除目录 $this->location。使用 queue:work Artisan 命令运行处理器,发现队列任务已经失败。且 表 failed_jobs 中,也已经新增加记录。

图4

]]>
https://www.shuijingwanwq.com/2023/12/21/8293/feed/ 0
在 Laravel 6 中,在队列执行过程中,一些视图文件未执行的排查分析 https://www.shuijingwanwq.com/2023/12/19/8288/ https://www.shuijingwanwq.com/2023/12/19/8288/#respond Tue, 19 Dec 2023 03:17:28 +0000 https://www.shuijingwanwq.com/?p=8288 Post Views: 83 1、参考:在 Laravel 6 中,在队列执行过程中,每一个任务的执行,皆会执行 View::addLocation($location);,然而每一个任务皆只会取第 1 个任务的 $location 。但是发现后续在生产环境中仍然存在问题。在队列执行过程中,一些视图文件未执行(”setting_migrations”:[])。如图1
在队列执行过程中,一些视图文件未执行("setting_migrations":[])

图1



INSERT INTO "" ("source_db", "store_name", "id", "theme_installation_id", "theme_installation_version_preset_id", "from_version", "to_version", "processing", "processing_failed", "step", "failed_message", "extra", "created_at", "updated_at") VALUES ('aws_db12', 'buglcexk30', 5, 5, 5, 'v2.11.1', 'v3.4.0', 0, 0, 7, '', '{"setting_migrations":[],"theme_download_paths":{"zip_path":"/theme_downloads/2023/11/07/1699423025.8743.1229090882.zip","destination":"/theme_downloads/2023/11/07/1699423025.8743.1229090882"}}', '2023-11-08 05:57:02', '2023-11-08 05:57:13');
INSERT INTO "" ("source_db", "store_name", "id", "theme_installation_id", "theme_installation_version_preset_id", "from_version", "to_version", "processing", "processing_failed", "step", "failed_message", "extra", "created_at", "updated_at") VALUES ('aws_db18', 'carver10', 7, 7, 7, 'v2.11.1', 'v3.4.0', 0, 0, 7, '', '{"setting_migrations":[{"file":"v3.0.0/migrate_product_detail.php","exec_at":"2023-11-08 05:57:11"},{"file":"2023_07_11_10_custom_mobile_layout/migrate_product_detail.php","exec_at":"2023-11-08 05:57:11"}],"theme_download_paths":{"zip_path":"/theme_downloads/2023/11/07/1699423022.7951.958836417.zip","destination":"/theme_downloads/2023/11/07/1699423022.7951.958836417"}}', '2023-11-08 05:57:01', '2023-11-08 05:57:11');
INSERT INTO "" ("source_db", "store_name", "id", "theme_installation_id", "theme_installation_version_preset_id", "from_version", "to_version", "processing", "processing_failed", "step", "failed_message", "extra", "created_at", "updated_at") VALUES ('aws_db3', 'cisfioadre59', 8, 8, 8, 'v2.11.1', 'v3.4.0', 0, 0, 7, '', '{"setting_migrations":[],"theme_download_paths":{"zip_path":"/theme_downloads/2023/11/07/1699423022.7315.1637916782.zip","destination":"/theme_downloads/2023/11/07/1699423022.7315.1637916782"}}', '2023-11-08 05:57:01', '2023-11-08 05:57:11');


2、由于在测试环境一直未复现,最后决定尽量模拟生产环境的部署方式。从单机部署为集群,在 Raccher 的工作负载中,点击 Pod 可用副本数 右侧的 +,添加一个 Pod。尝试复现此缺陷。如图2
由于在测试环境一直未复现,最后决定尽量模拟生产环境的部署方式。从单机部署为集群,在 Raccher 的工作负载中,点击 Pod 可用副本数 右侧的 +,添加一个 Pod。尝试复现此缺陷

图2

3、最后发现原因在于队列服务器为集群模式,在集群模式下,队列任务之间存在一定的依赖关系被破坏。我举例说明一下,在 A 机器上执行了队列 InstallThemeToDb ,那么在这台机器上存在解压缩后的主题包文件。但是在队列 InstallThemeToDb执行完成后,会触发下一个队列 MigrateThemeSettings 的执行,但是这个队列可能在 B 机器 上执行了。此时,这个队列的执行依赖于之前解压缩后的主题包文件,可是 ,B 机器上不存在。进而导致主题迁移文件未执行到。 4、现在存在3种解决方案: (1)将 2 个 Job 合并为 1 个; (2)想办法强制让两个 job 在同一台机器上执行; (3)不同的机器共享一个存储,然后解压缩的主题包文件都放在共享存储上。这种方案要保证没有时间上的延迟才行了; 5、最终决定采用第 2 个方案:想办法强制让两个 job 在同一台机器上执行。如果您想立即(同步)执行队列任务,可以使用 dispatchNow 方法。使用此方法时,队列任务将不会排队,并立即在当前进程中运行。


MigrateThemeSettings::dispatchNow($this->themeInstallationTask);


6、当在 队列 MigrateThemeSettings 中抛出异常时,并未执行 MigrateThemeSettings 中的 failed 方法,而是执行的 InstallThemeToDb 中的 failed 方法。符合预期。如图3
当在 队列 MigrateThemeSettings 中抛出异常时,并未执行 MigrateThemeSettings 中的 failed 方法,而是执行的 InstallThemeToDb 中的 failed 方法。符合预期

图3

7、当在 队列 MigrateThemeSettings 中查找 解压缩后的主题包文件 时,不再出现找不到的情况,符合预期。]]>
https://www.shuijingwanwq.com/2023/12/19/8288/feed/ 0
基于 数组相关函数 操作数组后,同样的输入,在不同执行顺序下的差异的分析(include、引用) https://www.shuijingwanwq.com/2023/10/20/8125/ https://www.shuijingwanwq.com/2023/10/20/8125/#respond Fri, 20 Oct 2023 01:45:11 +0000 https://www.shuijingwanwq.com/?p=8125 Post Views: 88 1、参考:在 Laravel 6 中,基于 数组相关函数 操作数组后,同样的输入,在不同执行顺序下的差异的分析(include、引用)。https://www.shuijingwanwq.com/2023/06/13/7716/ 2、当时的解决方案:将 $value 替换为 $sectionSettingValue,临时规避掉引用的变量名重名的问题 3、之后又存在类似的问题,需要能够快速定位是哪些变量重名导致的问题。决定将执行有误的文件中的变量都在文件开头打印出来。最后将打印结果中不为 null 的,全部 unset() 掉。


\Illuminate\Support\Facades\Log::info(
    'schema.v2.1.80',
    [
        '$sectionKey' => $sectionKey ?? null,
        '$section' => $section ?? null,
        '$blockKey' => $blockKey ?? null,
        '$block' => $block ?? null,
        '$blockOrderKey' => $blockOrderKey ?? null,
        '$blocks' => $blocks ?? null,
    ]
);


4、打印结果如下,确认在上一次的执行后,变量:$sectionKey、$section、$blockKey、$block、$blockOrderKey、$type 皆不为 null,全部需要销毁掉。


[2023-09-04 10:43:45] local.INFO: schema.v2.1.80 {
    "$sectionKey": "image-1",
    "$section": {
        "type": "image",
        "disabled": false,
        "settings": {
            "heading": "",
            "heading_align": "center"
        },
        "blocks": {
            "column-0": {
                "type": "column",
                "settings": {
                    "image": "https://xxx-s3.s3.us-east-2.amazonaws.com/image/736589fac73c7dfdbf61efadb49a95fb9af16efb.jpeg",
                    "mobile_image": "https://cdn.xxx.com/image/2022/03/200062b82e8cbae7cf7c48b425a33260686fd4aa3e6ed656901cb4cc7a283487.jpeg",
                    "url": "/"
                }
            },
            "column-1": {
                "type": "column",
                "settings": {
                    "image": "https://xxx-s3.s3.us-east-2.amazonaws.com/image/736589fac73c7dfdbf61efadb49a95fb9af16efb.jpeg",
                    "mobile_image": "https://cdn.xxx.com/image/2022/03/200062b82e8cbae7cf7c48b425a33260686fd4aa3e6ed656901cb4cc7a283487.jpeg",
                    "url": "/"
                }
            }
        }
    },
    "$blockKey": "column-1",
    "$block": {
        "type": "column",
        "settings": {
            "image": "https://xxx-s3.s3.us-east-2.amazonaws.com/image/736589fac73c7dfdbf61efadb49a95fb9af16efb.jpeg",
            "mobile_image": "https://cdn.xxx.com/image/2022/03/200062b82e8cbae7cf7c48b425a33260686fd4aa3e6ed656901cb4cc7a283487.jpeg",
            "url": "/"
        }
    },
    "$blockOrderKey": 8,
    "$type": [
        "search",
        "all_collections"
    ]
} 


5、销毁变量的代码如下


unset($sectionKey, $section, $blockKey, $block, $blockOrderKey, $type);


]]>
https://www.shuijingwanwq.com/2023/10/20/8125/feed/ 0
在 Laravel 6 中,查询出倒数第 2 条记录的实现 https://www.shuijingwanwq.com/2023/10/11/8101/ https://www.shuijingwanwq.com/2023/10/11/8101/#respond Wed, 11 Oct 2023 01:43:59 +0000 https://www.shuijingwanwq.com/?p=8101 Post Views: 58 1、在 Laravel 6 中,需要查询出倒数第 2 条记录。如图1
在 Laravel 6 中,需要查询出倒数第 2 条记录

图1

2、基于倒序排列,使用 limit,代码实现如下


$themeSaasTask = ThemeSaasTask::orderByDesc('id')->limit(2)->get();

print_r($themeSaasTask->last());
exit;


3、打印结果符合预期。如图2
打印结果符合预期

图2

]]>
https://www.shuijingwanwq.com/2023/10/11/8101/feed/ 0
在 Laravel 6 中,在队列执行过程中,每一个任务的执行,皆会执行 View::addLocation($location);,然而每一个任务皆只会取第 1 个任务的 $location https://www.shuijingwanwq.com/2023/08/29/7991/ https://www.shuijingwanwq.com/2023/08/29/7991/#comments Tue, 29 Aug 2023 01:16:59 +0000 views]]> paths]]> https://www.shuijingwanwq.com/?p=7991 Post Views: 118 1、参考:filemtime(): stat failed for /var/www/object/storage/app/theme_downloads/2023/07/19/1689733510.7774.265283535/migrations/migrate_cart.blade.php 2、参考:在 Laravel 6 中,在服务容器中绑定一个单例后,如何在解析时重新设置单例的构造方法的参数? 3、发现报错的根源在于,在队列执行过程中,每一个任务的执行,皆会执行 View::addLocation($location);,然而皆会取第 1 个 $location,而此时第 1 个 $location 所对应的目录已经被删除了。期望能够取到本次任务的 $location。 4、打印日志实现,发现在每一个任务中,单例的构造方法的参数 是在变化的。单例中的属性也是在变化的。


    public function __construct(string $defaultMigrationsLocation)
    {
        Log::info(
            '$defaultMigrationsLocation',
            [$defaultMigrationsLocation]
        );
        $this->location = $defaultMigrationsLocation;
        Log::info(
            '$this->location',
            [$this->location]
        );
        View::addLocation($this->location);
    }




[2023-07-19 17:38:59] local.INFO: $parameters {
    "migrationsLocation": "E:\\wwwroot\\xxx\\storage\\app/theme_downloads/2023/07/19/1689759452.2556.1081754280/migrations"
} 
[2023-07-19 17:38:59] local.INFO: $defaultMigrationsLocation [
    "E:\\wwwroot\\xxx\\storage\\app/theme_downloads/2023/07/19/1689759452.2556.1081754280/migrations"
] 
[2023-07-19 17:38:59] local.INFO: $this->location [
    "E:\\wwwroot\\xxx\\storage\\app/theme_downloads/2023/07/19/1689759452.2556.1081754280/migrations"
] 
[2023-07-19 17:42:15] local.INFO: $parameters {
    "migrationsLocation": "E:\\wwwroot\\xxx\\storage\\app/theme_downloads/2023/07/19/1689759545.3404.1736703749/migrations"
} 
[2023-07-19 17:42:15] local.INFO: $defaultMigrationsLocation [
    "E:\\wwwroot\\xxx\\storage\\app/theme_downloads/2023/07/19/1689759545.3404.1736703749/migrations"
] 
[2023-07-19 17:42:15] local.INFO: $this->location [
    "E:\\wwwroot\\xxx\\storage\\app/theme_downloads/2023/07/19/1689759545.3404.1736703749/migrations"
] 
[2023-07-19 17:42:18] local.INFO: $parameters {
    "migrationsLocation": "E:\\wwwroot\\xxx\\storage\\app/theme_downloads/2023/07/19/1689759640.9956.389729755/migrations"
} 
[2023-07-19 17:42:18] local.INFO: $defaultMigrationsLocation [
    "E:\\wwwroot\\xxx\\storage\\app/theme_downloads/2023/07/19/1689759640.9956.389729755/migrations"
] 
[2023-07-19 17:42:18] local.INFO: $this->location [
    "E:\\wwwroot\\xxx\\storage\\app/theme_downloads/2023/07/19/1689759640.9956.389729755/migrations"
] 
[2023-07-19 17:42:25] local.ERROR: filemtime(): stat failed for E:\wwwroot\object\storage\app\theme_downloads\2023\07\19\1689759452.2556.1081754280\migrations/migrate_cart.blade.php {
    "exception": "[object] (ErrorException(code: 0): filemtime(): stat failed for E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\19\\1689759452.2556.1081754280\\migrations/migrate_cart.blade.php at E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Filesystem\\Filesystem.php:356)
[stacktrace]
#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'filemtime(): st...', 'E:\\\\wwwroot\\\\wsho...', 356, Array)
#1 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Filesystem\\Filesystem.php(356): filemtime('E:\\\\wwwroot\\\\wsho...')
#2 E:\\wwwroot\\xxx\\Modules\\Theme\\View\\FileViewStorage.php(40): Illuminate\\Filesystem\\Filesystem->lastModified('E:\\\\wwwroot\\\\wsho...')
#3 E:\\wwwroot\\xxx\\Modules\\View\\Compiler\\BladeCompiler.php(31): Modules\\Theme\\View\\FileViewStorage->lastModified('E:\\\\wwwroot\\\\wsho...')
#4 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Engines\\CompilerEngine.php(50): Modules\\View\\Compiler\\BladeCompiler->isExpired('E:\\\\wwwroot\\\\wsho...')
#5 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\View\\View.php(143): Illuminate\\View\\Engines\\CompilerEngine->get('E:\\\\wwwroot\\\\wsho...', Array)
#6 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\View\\View.php(126): Illuminate\\View\\View->getContents()
#7 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\View\\View.php(91): Illuminate\\View\\View->renderContents()
#8 E:\\wwwroot\\xxx\\Modules\\ThemeStoreDb\\ThemeSetting\\ThemeSettingMigrator.php(324): Illuminate\\View\\View->render()
#9 E:\\wwwroot\\xxx\\Modules\\ThemeStoreDb\\ThemeSetting\\ThemeSettingMigrator.php(185): Modules\\ThemeStoreDb\\ThemeSetting\\ThemeSettingMigrator->migrateBladeTemplate('migrate_cart', Object(Modules\\ThemeStoreDb\\Models\\ThemeInstallationTask))
#10 E:\\wwwroot\\xxx\\Modules\\ThemeStoreDb\\ThemeSetting\\ThemeSettingMigrator.php(61): Modules\\ThemeStoreDb\\ThemeSetting\\ThemeSettingMigrator->migrateTemplate(Object(Modules\\ThemeStoreDb\\Models\\ThemeInstallation), Object(Modules\\ThemeStoreDb\\Models\\ThemeInstallationTask), Array)
#11 E:\\wwwroot\\xxx\\Modules\\ThemeStoreDb\\Jobs\\MigrateThemeSettings.php(148): Modules\\ThemeStoreDb\\ThemeSetting\\ThemeSettingMigrator->migrateThemeSettings(Object(Modules\\ThemeStoreDb\\Models\\ThemeInstallation), Object(Modules\\ThemeStoreDb\\Models\\ThemeInstallationTask))
#12 E:\\wwwroot\\xxx\\Modules\\ThemeStoreDb\\Jobs\\MigrateThemeSettings.php(72): Modules\\ThemeStoreDb\\Jobs\\MigrateThemeSettings->migrateThemeSettings()
#13 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(36): Modules\\ThemeStoreDb\\Jobs\\MigrateThemeSettings->handle()
#14 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Util.php(37): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#15 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#16 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#17 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(590): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#18 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Bus\\Dispatcher.php(94): Illuminate\\Container\\Container->call(Array)
#19 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(130): Illuminate\\Bus\\Dispatcher->Illuminate\\Bus\\{closure}(Object(Modules\\ThemeStoreDb\\Jobs\\MigrateThemeSettings))
#20 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Modules\\ThemeStoreDb\\Jobs\\MigrateThemeSettings))
#21 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Bus\\Dispatcher.php(98): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#22 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\CallQueuedHandler.php(83): Illuminate\\Bus\\Dispatcher->dispatchNow(Object(Modules\\ThemeStoreDb\\Jobs\\MigrateThemeSettings), false)
#23 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(130): Illuminate\\Queue\\CallQueuedHandler->Illuminate\\Queue\\{closure}(Object(Modules\\ThemeStoreDb\\Jobs\\MigrateThemeSettings))
#24 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Modules\\ThemeStoreDb\\Jobs\\MigrateThemeSettings))
#25 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\CallQueuedHandler.php(85): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#26 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\CallQueuedHandler.php(59): Illuminate\\Queue\\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\\Queue\\Jobs\\RedisJob), Object(Modules\\ThemeStoreDb\\Jobs\\MigrateThemeSettings))
#27 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Jobs\\Job.php(88): Illuminate\\Queue\\CallQueuedHandler->call(Object(Illuminate\\Queue\\Jobs\\RedisJob), Array)
#28 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(368): Illuminate\\Queue\\Jobs\\Job->fire()
#29 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(314): Illuminate\\Queue\\Worker->process('redis', Object(Illuminate\\Queue\\Jobs\\RedisJob), Object(Illuminate\\Queue\\WorkerOptions))
#30 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(134): Illuminate\\Queue\\Worker->runJob(Object(Illuminate\\Queue\\Jobs\\RedisJob), 'redis', Object(Illuminate\\Queue\\WorkerOptions))
#31 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Console\\WorkCommand.php(112): Illuminate\\Queue\\Worker->daemon('redis', 'default', Object(Illuminate\\Queue\\WorkerOptions))
#32 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Console\\WorkCommand.php(96): Illuminate\\Queue\\Console\\WorkCommand->runWorker('redis', 'default')
#33 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle()
#34 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Util.php(37): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#35 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#36 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#37 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(590): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#38 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(134): Illuminate\\Container\\Container->call(Array)
#39 E:\\wwwroot\\xxx\\vendor\\symfony\\console\\Command\\Command.php(255): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#40 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#41 E:\\wwwroot\\xxx\\vendor\\symfony\\console\\Application.php(1009): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#42 E:\\wwwroot\\xxx\\vendor\\symfony\\console\\Application.php(273): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#43 E:\\wwwroot\\xxx\\vendor\\symfony\\console\\Application.php(149): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#44 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Application.php(93): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#45 E:\\wwwroot\\xxx\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(131): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#46 E:\\wwwroot\\xxx\\artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#47 {main}
"
} 


5、继续打印更为详细的日志,编辑 /vendor/laravel/framework/src/Illuminate/View/Factory.php


    public function make($view, $data = [], $mergeData = [])
    {
        $path = $this->finder->find(
            $view = $this->normalizeName($view)
        );
        Log::info(
            '$path',
            [$path]
        );

        // Next, we will create the view instance and call the view creator for the view
        // which can set any data, etc. Then we will return the view instance back to
        // the caller for rendering or performing other view manipulations on this.
        $data = array_merge($mergeData, $this->parseData($data));

        return tap($this->viewInstance($view, $path, $data), function ($view) {
            $this->callCreator($view);
        });
    }


6、继续打印更为详细的日志,编辑 /vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php


    public function find($name)
    {
        Log::info(
            '$this->views',
            [$this->views]
        );
        if (isset($this->views[$name])) {
            return $this->views[$name];
        }

        if ($this->hasHintInformation($name = trim($name))) {
            return $this->views[$name] = $this->findNamespacedView($name);
        }
        Log::info(
            '$this->paths',
            [$this->paths]
        );

        return $this->views[$name] = $this->findInPaths($name, $this->paths);
    }


7、查看打印出的日志信息,得出结论,在最后一次打印的 $this->views 中,仅存在第 1 个任务中的视图文件,即一个视图文件的名称所对应的文件路径已经被缓存在对象属性 $this->views 中。所以才会导致第 2 个任务继续使用第 1 个任务中的视图文件路径,由于第 1 个任务中的视图文件已经被删除,进而导致报错。


[2023-07-21 16:54:54] local.INFO: $this->views [
    []
] 
[2023-07-21 16:54:54] local.INFO: $this->paths [
    [
        "E:\\wwwroot\\xxx\\resources\\views",
        "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations"
    ]
] 
[2023-07-21 16:54:54] local.INFO: $path [
    "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_cart.blade.php"
] 
[2023-07-21 16:54:54] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_cart.blade.php"
    }
] 
[2023-07-21 16:54:54] local.INFO: $this->paths [
    [
        "E:\\wwwroot\\xxx\\resources\\views",
        "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations"
    ]
] 
[2023-07-21 16:54:54] local.INFO: $path [
    "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collections.blade.php"
] 
[2023-07-21 16:54:54] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collections.blade.php"
    }
] 
[2023-07-21 16:54:54] local.INFO: $this->paths [
    [
        "E:\\wwwroot\\xxx\\resources\\views",
        "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations"
    ]
] 
[2023-07-21 16:54:54] local.INFO: $path [
    "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collectiontitem.blade.php"
] 
[2023-07-21 16:54:54] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collectiontitem.blade.php"
    }
] 
[2023-07-21 16:54:54] local.INFO: $this->paths [
    [
        "E:\\wwwroot\\xxx\\resources\\views",
        "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations"
    ]
] 
[2023-07-21 16:54:54] local.INFO: $path [
    "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_index.blade.php"
] 
[2023-07-21 16:54:55] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_index.blade.php"
    }
] 
[2023-07-21 16:54:55] local.INFO: $this->paths [
    [
        "E:\\wwwroot\\xxx\\resources\\views",
        "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations"
    ]
] 
[2023-07-21 16:54:55] local.INFO: $path [
    "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_product_detail.blade.php"
] 
[2023-07-21 16:54:55] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_index.blade.php",
        "migrate_product_detail": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_product_detail.blade.php"
    }
] 
[2023-07-21 16:54:55] local.INFO: $this->paths [
    [
        "E:\\wwwroot\\xxx\\resources\\views",
        "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations"
    ]
] 
[2023-07-21 16:54:55] local.INFO: $path [
    "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_search.blade.php"
] 
[2023-07-21 16:54:58] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_index.blade.php",
        "migrate_product_detail": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_product_detail.blade.php",
        "migrate_search": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_search.blade.php"
    }
] 
[2023-07-21 16:54:58] local.INFO: $path [
    "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689929563.2923.2007177066\\migrations/migrate_cart.blade.php"
]


8、需要在每一次任务开始时,先清理掉上一次任务的视图缓存文件数组列表,即设置 $this->views 为空数组,添加 View::flushFinderCache();


    public function __construct(string $defaultMigrationsLocation)
    {
        $this->location = $defaultMigrationsLocation;
        View::flushFinderCache();
        View::addLocation($this->location);
    }


9、队列任务中不再报错,符合预期。如图1
队列任务中不再报错,符合预期

图1



PS E:\wwwroot\object> php artisan queue:work
[2023-07-21 16:52:43][647NfQYdlkWp0PDUHKoIU4KdS8fXTC8B] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-21 16:53:53][647NfQYdlkWp0PDUHKoIU4KdS8fXTC8B] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-21 16:53:53][1oOabvsCvEz3doAqRiQb5c2ZcruRFRXu] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-21 16:54:54][1oOabvsCvEz3doAqRiQb5c2ZcruRFRXu] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-21 16:54:54][zPRP7HPO8z1yIL1Z2s46YEgHG3tLr35d] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-21 16:54:58][zPRP7HPO8z1yIL1Z2s46YEgHG3tLr35d] Processed:  Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-21 16:54:58][65v2ueRDyIDz69dUeddxljVzWx49F8y7] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-21 16:55:01][65v2ueRDyIDz69dUeddxljVzWx49F8y7] Failed:     Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
PS E:\wwwroot\object> php artisan queue:work
PS E:\wwwroot\object> php artisan queue:work
PS E:\wwwroot\object> php artisan queue:work
[2023-07-21 17:15:08][UzLDgMZEyxxD1D8e6TcZx7dwybSsqVBv] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-21 17:16:06][UzLDgMZEyxxD1D8e6TcZx7dwybSsqVBv] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-21 17:16:06][Kwamfg3C6YC2ZZ7O3aJVypgxTsvnfDe9] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-21 17:17:04][Kwamfg3C6YC2ZZ7O3aJVypgxTsvnfDe9] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-21 17:17:04][JdiepMQdkeiugOnK3p7hDiexoc9HyPkL] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-21 17:18:04][JdiepMQdkeiugOnK3p7hDiexoc9HyPkL] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-21 17:18:04][s0GprGgeeatIPqMigyCW3IgUZoHlKOgH] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-21 17:18:08][s0GprGgeeatIPqMigyCW3IgUZoHlKOgH] Processed:  Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-21 17:18:08][C1vtzAgil1cohbBJNeJywKmTYoTmSHBj] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-21 17:18:11][C1vtzAgil1cohbBJNeJywKmTYoTmSHBj] Processed:  Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-21 17:18:11][jsAPU1nPeLvZoB8wRgqK5CTuYYfjQ4kk] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-21 17:18:14][jsAPU1nPeLvZoB8wRgqK5CTuYYfjQ4kk] Processed:  Modules\ThemeStoreDb\Jobs\MigrateThemeSettings


10、再次查看日志,以确认代码实现逻辑。$this->views 在每一个任务中,已经不再是第 1 个任务的视图文件路径列表了。符合预期。如图2
再次查看日志,以确认代码实现逻辑。$this->views 在每一个任务中,已经不再是第 1 个任务的视图文件路径列表了。符合预期。

图2

 


[2023-07-21 17:18:04] local.INFO: $this->views [
    []
] 
[2023-07-21 17:18:04] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930908.6638.1755291492\\migrations/migrate_cart.blade.php"
    }
] 
[2023-07-21 17:18:05] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930908.6638.1755291492\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930908.6638.1755291492\\migrations/migrate_collections.blade.php"
    }
] 
[2023-07-21 17:18:05] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930908.6638.1755291492\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930908.6638.1755291492\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930908.6638.1755291492\\migrations/migrate_collectiontitem.blade.php"
    }
] 
[2023-07-21 17:18:05] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930908.6638.1755291492\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930908.6638.1755291492\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930908.6638.1755291492\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930908.6638.1755291492\\migrations/migrate_index.blade.php"
    }
] 
[2023-07-21 17:18:08] local.INFO: $this->views [
    []
] 
[2023-07-21 17:18:08] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\21\\1689930966.5702.629335870\\migrations/migrate_cart.blade.php"
    }
] 


11、最后决定还是将清空 $this->views 的操作放在每一个队列任务结束后执行,要更为合理一些。



    /**
     * 任务失败的处理过程
     *
     * @param  Exception  $exception
     * @return void
     */
    public function failed(Exception $exception)
    {
        // ...
        View::flushFinderCache();
    }

	app(ThemeSettingMigrator::class, $parameters)->migrateThemeSettings($this->themeInstallation, $this->themeInstallationTask);

	// 删除 解压缩 ZIP 后的目录及其下所有的文件
	Storage::disk('local')->deleteDirectory(substr($this->themeInstallationTask->getRelativeDestination(), 1));
	View::flushFinderCache();


12、再次查看日志,以确认代码实现逻辑。且同时执行2个监听器进程。$this->views 在每一个任务中,都是独立的视图文件路径列表了。虽然在日志输出的过程中,出现了任务交错执行的情况,但是其顺序皆是从0至5,并未出现任务下的文件路径为别的任务下的目录的情况。符合预期。如图3  
再次查看日志,以确认代码实现逻辑。且同时执行2个监听器进程。$this->views 在每一个任务中,都是独立的视图文件路径列表了。虽然在日志输出的过程中,出现了任务交错执行的情况,但是其顺序皆是从0至5,并未出现任务下的文件路径为别的任务下的目录的情况。符合预期

图3



PS E:\wwwroot\object> php artisan queue:work
[2023-07-24 11:27:19][lduQutB2pi4Omu874hJZ7hDjrjT5GE54] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:28:33][lduQutB2pi4Omu874hJZ7hDjrjT5GE54] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:28:33][vSSRxnipf1yDn6yKHLGFF73aroBYIaw7] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:29:50][vSSRxnipf1yDn6yKHLGFF73aroBYIaw7] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:29:50][CbeGCSOBA7ChovzoZ0EaQq5967C6IXrK] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:31:14][CbeGCSOBA7ChovzoZ0EaQq5967C6IXrK] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:31:14][fdW6XlY5SfPo8aye9OBBVptwELwd0yvQ] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-24 11:31:20][fdW6XlY5SfPo8aye9OBBVptwELwd0yvQ] Processed:  Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-24 11:31:20][wkyphts0jZ8IQbtO8P39vqXpZTPPMiPa] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-24 11:31:25][wkyphts0jZ8IQbtO8P39vqXpZTPPMiPa] Processed:  Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-24 11:31:25][RzKG4cSFi80ERNeulaYUBkT3EGWxel1b] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-24 11:31:30][RzKG4cSFi80ERNeulaYUBkT3EGWxel1b] Processed:  Modules\ThemeStoreDb\Jobs\MigrateThemeSettings




PS E:\wwwroot\object> php artisan queue:work
[2023-07-24 11:27:21][BuPYZVs4KAoN75cmBXTrYXEEs8sXFocA] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:28:35][BuPYZVs4KAoN75cmBXTrYXEEs8sXFocA] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:28:35][SmNvNkh8VBAfxnoZXmvVBEPcumTjjtNO] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:29:52][SmNvNkh8VBAfxnoZXmvVBEPcumTjjtNO] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:29:52][4Fpotr4ft2z95OJRNayQSE1fa5O15VgI] Processing: Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:31:15][4Fpotr4ft2z95OJRNayQSE1fa5O15VgI] Processed:  Modules\ThemeStoreDb\Jobs\InstallThemeToDb
[2023-07-24 11:31:15][FHeFhYlVfISBKjrxL4IX4WpQnVTayveE] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-24 11:31:20][FHeFhYlVfISBKjrxL4IX4WpQnVTayveE] Processed:  Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-24 11:31:20][V05adIgcSOabBFdzZbFAD1o6XwIizkPL] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-24 11:31:25][V05adIgcSOabBFdzZbFAD1o6XwIizkPL] Processed:  Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-24 11:31:25][8LmZOVZVzu3zTHIlArKVNp8XnhMWZZfg] Processing: Modules\ThemeStoreDb\Jobs\MigrateThemeSettings
[2023-07-24 11:31:30][8LmZOVZVzu3zTHIlArKVNp8XnhMWZZfg] Processed:  Modules\ThemeStoreDb\Jobs\MigrateThemeSettings




[2023-07-24 11:31:15] local.INFO: $this->views [
    []
] 
[2023-07-24 11:31:15] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_cart.blade.php"
    }
] 
[2023-07-24 11:31:15] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_collections.blade.php"
    }
] 
[2023-07-24 11:31:15] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_collectiontitem.blade.php"
    }
] 
[2023-07-24 11:31:15] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_index.blade.php"
    }
]
[2023-07-24 11:31:15] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_index.blade.php",
        "migrate_product_detail": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169239.4539.1592596993\\migrations/migrate_product_detail.blade.php"
    }
] 
[2023-07-24 11:31:16] local.INFO: $this->views [
    []
] 
[2023-07-24 11:31:16] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_cart.blade.php"
    }
] 
[2023-07-24 11:31:16] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_collections.blade.php"
    }
] 
[2023-07-24 11:31:16] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_collectiontitem.blade.php"
    }
]
[2023-07-24 11:31:16] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_index.blade.php"
    }
] 
[2023-07-24 11:31:16] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_index.blade.php",
        "migrate_product_detail": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169241.7525.1699877933\\migrations/migrate_product_detail.blade.php"
    }
] 
[2023-07-24 11:31:20] local.INFO: $this->views [
    []
] 
[2023-07-24 11:31:20] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_cart.blade.php"
    }
] 
[2023-07-24 11:31:20] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_collections.blade.php"
    }
] 
[2023-07-24 11:31:20] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_collectiontitem.blade.php"
    }
] 
[2023-07-24 11:31:21] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_index.blade.php"
    }
] 
[2023-07-24 11:31:21] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_index.blade.php",
        "migrate_product_detail": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169313.908.290770737\\migrations/migrate_product_detail.blade.php"
    }
] 
[2023-07-24 11:31:21] local.INFO: $this->views [
    []
]
[2023-07-24 11:31:21] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_cart.blade.php"
    }
]
[2023-07-24 11:31:21] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_collections.blade.php"
    }
]
[2023-07-24 11:31:21] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_collectiontitem.blade.php"
    }
] 
[2023-07-24 11:31:21] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_index.blade.php"
    }
] 
[2023-07-24 11:31:21] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_index.blade.php",
        "migrate_product_detail": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169315.2833.851018770\\migrations/migrate_product_detail.blade.php"
    }
] 
[2023-07-24 11:31:25] local.INFO: $this->views [
    []
] 
[2023-07-24 11:31:25] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_cart.blade.php"
    }
] 
[2023-07-24 11:31:25] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_collections.blade.php"
    }
] 
[2023-07-24 11:31:25] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_collectiontitem.blade.php"
    }
] 
[2023-07-24 11:31:25] local.INFO: $this->views [
    []
]
[2023-07-24 11:31:25] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_index.blade.php"
    }
] 
[2023-07-24 11:31:25] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_cart.blade.php"
    }
] 
[2023-07-24 11:31:25] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_collections.blade.php"
    }
]
[2023-07-24 11:31:25] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_index.blade.php",
        "migrate_product_detail": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169390.5549.32763302\\migrations/migrate_product_detail.blade.php"
    }
] 
[2023-07-24 11:31:25] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_collectiontitem.blade.php"
    }
]
[2023-07-24 11:31:25] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_index.blade.php"
    }
]
[2023-07-24 11:31:26] local.INFO: $this->views [
    {
        "migrate_cart": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_cart.blade.php",
        "migrate_collections": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_collections.blade.php",
        "migrate_collectiontitem": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_collectiontitem.blade.php",
        "migrate_index": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_index.blade.php",
        "migrate_product_detail": "E:\\wwwroot\\xxx\\storage\\app\\theme_downloads\\2023\\07\\24\\1690169392.6276.729637306\\migrations/migrate_product_detail.blade.php"
    }
] 


]]>
https://www.shuijingwanwq.com/2023/08/29/7991/feed/ 2
在 Laravel 6 中,从一系列的文件列表中,取出不重复的特定目录列表 https://www.shuijingwanwq.com/2023/08/11/7952/ https://www.shuijingwanwq.com/2023/08/11/7952/#respond Fri, 11 Aug 2023 01:21:52 +0000 https://www.shuijingwanwq.com/?p=7952 Post Views: 93 1、现在表中的记录。如图1
现在表中的记录

图1

2、查询出文件列表的实现如下


$themeAssets = ThemeAsset::select('asset_key')->where('theme_id', '9994a913-4383-423c-993e-21acde47dbe3')->where('category', ThemeAsset::CATEGORY_MIGRATION)->get();




Illuminate\Database\Eloquent\Collection Object
(
    [items:protected] => Array
        (
            [0] => Modules\ThemeStoreDb\Models\ThemeAsset Object
                (
                    [forceDeleteVersion:protected] => 
                    [table:protected] => theme_asset2
                    [connection:protected] => mysql
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [asset_key] => migrations/migrate_cart.blade.php
                        )

                    [original:protected] => Array
                        (
                            [asset_key] => migrations/migrate_cart.blade.php
                        )

                    [changes:protected] => Array
                        (
                        )

                    [casts:protected] => Array
                        (
                        )

                    [dates:protected] => Array
                        (
                        )

                    [dateFormat:protected] => 
                    [appends:protected] => Array
                        (
                            [0] => created_at
                            [1] => updated_at
                        )

                    [dispatchesEvents:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [relations:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [timestamps] => 1
                    [hidden:protected] => Array
                        (
                        )

                    [visible:protected] => Array
                        (
                        )

                    [guarded:protected] => Array
                        (
                            [0] => *
                        )

                )

            [1] => Modules\ThemeStoreDb\Models\ThemeAsset Object
                (
                    [forceDeleteVersion:protected] => 
                    [table:protected] => theme_asset2
                    [connection:protected] => mysql
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [asset_key] => migrations/migrate_collections.blade.php
                        )

                    [original:protected] => Array
                        (
                            [asset_key] => migrations/migrate_collections.blade.php
                        )

                    [changes:protected] => Array
                        (
                        )

                    [casts:protected] => Array
                        (
                        )

                    [dates:protected] => Array
                        (
                        )

                    [dateFormat:protected] => 
                    [appends:protected] => Array
                        (
                            [0] => created_at
                            [1] => updated_at
                        )

                    [dispatchesEvents:protected] => Array
                        (
                        )

                    [observables:protected] => Array
                        (
                        )

                    [relations:protected] => Array
                        (
                        )

                    [touches:protected] => Array
                        (
                        )

                    [timestamps] => 1
                    [hidden:protected] => Array
                        (
                        )

                    [visible:protected] => Array
                        (
                        )

                    [guarded:protected] => Array
                        (
                            [0] => *
                        )

                )
        )

)



3、由于需要取出文件:migrations/v2.0.28/migrate_settings_data.php 中的 v2.0.28 部分。其中有一些文件:migrations/migrate_cart.blade.php 不存在 v2.0.28 部分,所以需要先过滤掉。先后使用了集合的 filter()、mapToGroups() 方法。


        $grouped = $themeAssets->filter(function ($value) {
            return Str::startsWith(explode('/', $value->asset_key)[1], 'v2');
        })->mapToGroups(function ($value) {
            return [explode('/', $value->asset_key)[1] => $value->asset_key];
        });
        print_r($grouped);
        exit;


4、打印结果如下,符合预期。如图2
打印结果如下,符合预期

图2



Illuminate\Support\Collection Object
(
    [items:protected] => Array
        (
            [v2.0.20] => Illuminate\Database\Eloquent\Collection Object
                (
                    [items:protected] => Array
                        (
                            [0] => migrations/v2.0.20/migrate_settings_data.php
                        )

                )

            [v2.0.21] => Illuminate\Database\Eloquent\Collection Object
                (
                    [items:protected] => Array
                        (
                            [0] => migrations/v2.0.21/migrate_settings_data.php
                        )

                )

            [v2.0.28] => Illuminate\Database\Eloquent\Collection Object
                (
                    [items:protected] => Array
                        (
                            [0] => migrations/v2.0.28/migrate_cart.php
                            [1] => migrations/v2.0.28/migrate_collections.php
                            [2] => migrations/v2.0.28/migrate_collectiontitem.php
                            [3] => migrations/v2.0.28/migrate_index.php
                            [4] => migrations/v2.0.28/migrate_product_detail.php
                            [5] => migrations/v2.0.28/migrate_search.php
                            [6] => migrations/v2.0.28/migrate_settings_data.php
                        )

                )

            [v2.1.1] => Illuminate\Database\Eloquent\Collection Object
                (
                    [items:protected] => Array
                        (
                            [0] => migrations/v2.1.1/migrate_index.php
                        )

                )

            [v2.1.2] => Illuminate\Database\Eloquent\Collection Object
                (
                    [items:protected] => Array
                        (
                            [0] => migrations/v2.1.2/migrate_settings_data.php
                        )

                )

            [v2.1.3] => Illuminate\Database\Eloquent\Collection Object
                (
                    [items:protected] => Array
                        (
                            [0] => migrations/v2.1.3/migrate_cart.php
                            [1] => migrations/v2.1.3/migrate_collections.php
                            [2] => migrations/v2.1.3/migrate_collectiontitem.php
                            [3] => migrations/v2.1.3/migrate_index.php
                            [4] => migrations/v2.1.3/migrate_product_detail.php
                            [5] => migrations/v2.1.3/migrate_search.php
                        )

                )

            [v2.1.30] => Illuminate\Database\Eloquent\Collection Object
                (
                    [items:protected] => Array
                        (
                            [0] => migrations/v2.1.30/migrate_settings_data.php
                        )

                )

            [v2.1.65] => Illuminate\Database\Eloquent\Collection Object
                (
                    [items:protected] => Array
                        (
                            [0] => migrations/v2.1.65/migrate_product_detail.php
                            [1] => migrations/v2.1.65/migrate_settings_data.php
                        )

                )

            [v2.1.70] => Illuminate\Database\Eloquent\Collection Object
                (
                    [items:protected] => Array
                        (
                            [0] => migrations/v2.1.70/migrate_settings_data.php
                        )

                )

            [v2.1.80] => Illuminate\Database\Eloquent\Collection Object
                (
                    [items:protected] => Array
                        (
                            [0] => migrations/v2.1.80/migrate_product_detail.php
                        )

                )

        )

)



5、仅获取集合中的数组的键。如图3
仅获取集合中的数组的键

图3



        print_r(array_keys($grouped->all()));
        exit;




Array
(
    [0] => v2.0.20
    [1] => v2.0.21
    [2] => v2.0.28
    [3] => v2.1.1
    [4] => v2.1.2
    [5] => v2.1.3
    [6] => v2.1.30
    [7] => v2.1.65
    [8] => v2.1.70
    [9] => v2.1.80
)



   ]]>
https://www.shuijingwanwq.com/2023/08/11/7952/feed/ 0
在 Laravel 6 中,在服务容器中绑定一个单例后,如何在解析时重新设置单例的构造方法的参数? https://www.shuijingwanwq.com/2023/08/10/7950/ https://www.shuijingwanwq.com/2023/08/10/7950/#comments Thu, 10 Aug 2023 01:15:33 +0000 app]]> https://www.shuijingwanwq.com/?p=7950 Post Views: 85 1、在服务容器中绑定一个单例,现有的实现如下


$this->app->singleton(ThemeHandler::class, function() {
	return new ThemeHandler(
		base_path('Modules') . '/ThemeStoreDb/Resources/setting_migrations'
	);
});

class ThemeHandler
{
    private $themeSettingMigrator;

    public function __construct(string $defaultMigrationsLocation)
    {
        Log::info(
            '$defaultMigrationsLocation',
            [$defaultMigrationsLocation]
        );
        $this->themeSettingMigrator = new ThemeSettingMigrator($defaultMigrationsLocation);
    }
}

app(ThemeHandler::class)->migrateThemeSettings($this->themeInstallation, $this->themeInstallationTask);


2、现在有需要在解析单例后,可能需要重新设置单例的构造方法的参数。新的实现如下


$this->app->singleton(ThemeHandler::class, function($app, $parameters) {
	return new ThemeHandler(
		$parameters['migrationsLocation'] ?? base_path('Modules') . '/ThemeStoreDb/Resources/setting_migrations'
	);
});

app(ThemeHandler::class, ['migrationsLocation' => 'E:/wwwroot/object/Modules/ThemeStoreDb/Resources/setting_migrations1'])->migrateThemeSettings($this->themeInstallation, $this->themeInstallationTask);


3、app(ThemeHandler::class, []) 与 app(ThemeHandler::class, [‘migrationsLocation’ => ‘E:/wwwroot/object/Modules/ThemeStoreDb/Resources/setting_migrations1’]) 在构造方法中的参数分别输出至日志中,符合预期。



[2023-07-06 15:49:57] local.INFO: $defaultMigrationsLocation [
    "E:\\wwwroot\\object\\Modules/ThemeStoreDb/Resources/setting_migrations"
] 


[2023-07-06 16:16:47] local.INFO: $defaultMigrationsLocation [
    "E:/wwwroot/object/Modules/ThemeStoreDb/Resources/setting_migrations1"
] 


]]>
https://www.shuijingwanwq.com/2023/08/10/7950/feed/ 1
在 Laravel 6 中,将 session 实现替换为对应的 cookie 实现 https://www.shuijingwanwq.com/2023/06/19/7742/ https://www.shuijingwanwq.com/2023/06/19/7742/#respond Mon, 19 Jun 2023 07:14:37 +0000 https://www.shuijingwanwq.com/?p=7742 Post Views: 85 1、在程序中,是否为预览模式,是基于 session 实现的。但是当用户退出登录时,也会自动退出预览模式。如图1
在程序中,是否为预览模式,是基于 session 实现的。但是当用户退出登录时,也会自动退出预览模式

图1

2、退出预览模式的表现便是页面底部的预览横幅已经消失。如图2
退出预览模式的表现便是页面底部的预览横幅已经消失

图2

3、参考:Session 重新生成 Session ID ,如果你使用了内置函数 LoginController,Laravel 会自动重新生成身份认证中的 Session ID。最终决定替换为对应的 cookie 实现 4、替换的代码实现依次如下


// $request->session()->forget(XxxService::THEME_PREVIEW_ID);
Cookie::queue(Cookie::forget(XxxService::THEME_PREVIEW_ID));
// $request->session()->put(XxxService::THEME_PREVIEW_NAME, $themePreviewName);
Cookie::queue(Cookie::make(XxxService::THEME_PREVIEW_NAME, $themePreviewName));

// $request->session()->forget([XxxService::THEME_PREVIEW_ID, XxxService::THEME_PREVIEW_NAME]);
Cookie::queue(Cookie::forget(XxxService::THEME_PREVIEW_ID));
Cookie::queue(Cookie::forget(XxxService::THEME_PREVIEW_NAME));

$request->session()->has(XxxService::THEME_PREVIEW_NAME);
Cookie::has(XxxService::THEME_PREVIEW_NAME);

$request->session()->get(XxxService::THEME_PREVIEW_NAME);
Cookie::get(XxxService::THEME_PREVIEW_NAME);


5、测试功能,符合预期,在跳转后的网页的 Cookie 中已经存在新设置的 Key。如图3
测试功能,符合预期,在跳转后的网页的 Cookie 中已经存在新设置的 Key

图3

]]>
https://www.shuijingwanwq.com/2023/06/19/7742/feed/ 0
在 Laravel 6 中,基于 数组相关函数 操作数组后,同样的输入,在不同执行顺序下的差异的分析(include、引用) https://www.shuijingwanwq.com/2023/06/13/7716/ https://www.shuijingwanwq.com/2023/06/13/7716/#respond Tue, 13 Jun 2023 01:29:39 +0000 https://www.shuijingwanwq.com/?p=7716 Post Views: 108

1、PHP 文件的代码实现如下

<?php
 
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
 
Log::info(
    'v2.1.3_migrate_index.php_schema_0',
    [
        'schema' => $schema
    ]
);
 
$settings = ['text_color', 'mask_opacity', 'button_text_color', 'button_background_color'];
if (Arr::has($schema, 'sections')) {
    foreach ($schema['sections'] as $sectionKey => $section) {
        if (Arr::get($section, 'type') == 'multi-column') {
            foreach ($settings as $setting) {
                if (Arr::has($section, 'settings.' . $setting)) {
                    if ($setting == 'mask_opacity') {
                        $value = (bool)Arr::get($section, 'settings.' . $setting);
                    } else {
                        $value = Arr::get($section, 'settings.' . $setting);
                    }
                    foreach ($section['blocks'] as $blockKey => $block) {
                        Arr::set($schema, 'sections.' . $sectionKey . '.blocks.' . $blockKey . '.settings.' . $setting, $value);
                    }
                    Arr::forget($schema, 'sections.' . $sectionKey . '.settings.' . $setting);
                }
            }
        }
    }
}
 
Log::info(
    'v2.1.3_migrate_index.php_schema_1',
    [
        'schema' => $schema
    ]
);
 
return $schema;

2、初始的 $schema ,即 [2023-05-17 09:45:23] local.INFO: v2.1.3_migrate_index.php_schema_0 ,其值如下


{
  "schema": {
    "sections": {
      "4imagetext_t0upqwh3": {
        "type": "multi-column",
        "disabled": false,
        "settings": {
          "heading": "",
          "heading_align": "center",
          "text_color": "#000",
          "image_size": "auto",
          "mask_opacity": 0,
          "button_text_color": "#000",
          "button_background_color": "#fff",
          "text_align": "center"
        },
        "blocks": {
          "column-0": {
            "type": "column",
            "settings": {
              "heading": "IMAGE WITH TEXT",
              "text": "Use these blocks to share your brand's story. You can focus on a particular collection, a product detail, or even embed a video.",
              "image": "https://cdn.cloudfastin.com/image/cafe2c8e6451a85f66aedbc62af22747f711c3f2.jpeg",
              "mobile_image": "",
              "url": "/",
              "label": "MORE INFO"
            }
          },
          "column-1": {
            "type": "column",
            "settings": {
              "heading": "IMAGE WITH TEXT",
              "text": "Use these blocks to share your brand's story. You can focus on a particular collection, a product detail, or even embed a video.",
              "image": "https://cdn.cloudfastin.com/image/b55803eeb93eba8bb0b8bc4bb4be7ad16df74ad1.jpeg",
              "mobile_image": "",
              "url": "/",
              "label": "MORE INFO"
            }
          },
          "column-2": {
            "type": "column",
            "settings": {
              "heading": "IMAGE WITH TEXT",
              "text": "Use these blocks to share your brand's story. You can focus on a particular collection, a product detail, or even embed a video.",
              "image": "https://cdn.cloudfastin.com/image/083a9e7fbe2b3856aecb84a2387f82eea0bb0f39.jpeg",
              "mobile_image": "",
              "url": "/",
              "label": "MORE INFO"
            }
          }
        },
        "block_order": [
          "column-0",
          "column-1",
          "column-2"
        ]
      }
    },
    "order": [
      "4imagetext_t0upqwh3"
    ]
  }
}


3、但是,返回的 $schema ,即 [2023-05-17 09:45:23] local.INFO: v2.1.3_migrate_index.php_schema_1 ,不符合预期。其数据有丢失。在 sections.4imagetext_t0upqwh3 中的字段:type、settings、block_order 等皆已经丢失。如图1

但是,返回的 $schema ,即 [2023-05-17 09:45:23] local.INFO: v2.1.3_migrate_index.php_schema_1 ,不符合预期。其数据有丢失。在 sections.4imagetext_t0upqwh3 中的字段:type、settings、block_order 等皆已经丢失。

图1


{
    "schema": {
        "sections": {
            "4imagetext_t0upqwh3": {
                "blocks": {
                    "column-0": {
                        "settings": {
                            "button_background_color": "#fff"
                        }
                    },
                    "column-1": {
                        "settings": {
                            "button_background_color": {
                                "blocks": {
                                    "column-0": {
                                        "settings": {
                                            "button_background_color": "#fff"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "column-2": {
                        "settings": {
                            "button_background_color": {
                                "blocks": {
                                    "column-0": {
                                        "settings": {
                                            "button_background_color": "#fff"
                                        }
                                    },
                                    "column-1": {
                                        "settings": {
                                            "button_background_color": {
                                                "blocks": {
                                                    "column-0": {
                                                        "settings": {
                                                            "button_background_color": "Over 15 levels deep, aborting normalization"
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "order": [
            "4imagetext_t0upqwh3"
        ]
    }
} 


4、但是,仅执行此 PHP 文件,返回的 $schema 是符合预期的。第 3 步骤的执行不符合预期,根源应该在于执行此 PHP 文件之前的某处影响到了这个 PHP 文件的执行。


{
    "schema": {
        "schema": {
            "order": [
                "4imagetext_t0upqwh3"
            ],
            "sections": {
                "4imagetext_t0upqwh3": {
                    "type": "multi-column",
                    "blocks": {
                        "column-0": {
                            "type": "column",
                            "settings": {
                                "url": "/",
                                "text": "Use these blocks to share your brand's story. You can focus on a particular collection, a product detail, or even embed a video.",
                                "image": "https://cdn.cloudfastin.com/image/cafe2c8e6451a85f66aedbc62af22747f711c3f2.jpeg",
                                "label": "MORE INFO",
                                "heading": "IMAGE WITH TEXT",
                                "mobile_image": ""
                            }
                        },
                        "column-1": {
                            "type": "column",
                            "settings": {
                                "url": "/",
                                "text": "Use these blocks to share your brand's story. You can focus on a particular collection, a product detail, or even embed a video.",
                                "image": "https://cdn.cloudfastin.com/image/b55803eeb93eba8bb0b8bc4bb4be7ad16df74ad1.jpeg",
                                "label": "MORE INFO",
                                "heading": "IMAGE WITH TEXT",
                                "mobile_image": ""
                            }
                        },
                        "column-2": {
                            "type": "column",
                            "settings": {
                                "url": "/",
                                "text": "Use these blocks to share your brand's story. You can focus on a particular collection, a product detail, or even embed a video.",
                                "image": "https://cdn.cloudfastin.com/image/083a9e7fbe2b3856aecb84a2387f82eea0bb0f39.jpeg",
                                "label": "MORE INFO",
                                "heading": "IMAGE WITH TEXT",
                                "mobile_image": ""
                            }
                        }
                    },
                    "disabled": false,
                    "settings": {
                        "heading": "",
                        "image_size": "auto",
                        "text_align": "center",
                        "text_color": "#000",
                        "mask_opacity": 0,
                        "heading_align": "center",
                        "button_text_color": "#000",
                        "button_background_color": "#fff"
                    },
                    "block_order": [
                        "column-0",
                        "column-1",
                        "column-2"
                    ]
                }
            }
        }
    }
}


5、最终确认了原因,是因为在执行此 PHP 文件之前,执行了另一个 PHP 文件,在另一个 PHP 文件中使用了引用:&$value。两个 PHP 文件的依次执行是使用的 include 。

<?php
 
use Illuminate\Support\Arr;
 
if (Arr::has($schema, 'sections'))
{
    foreach ($schema['sections'] as &$value) {
        // ...
    }
}
 
return $schema;

6、将 $value 替换为 $sectionSettingValue,临时规避掉引用的变量名重名的问题。

]]>
https://www.shuijingwanwq.com/2023/06/13/7716/feed/ 0
在 Laravel 6 中,操作多维数组时,使用引用传递以精简代码实现 https://www.shuijingwanwq.com/2023/06/12/7714/ https://www.shuijingwanwq.com/2023/06/12/7714/#respond Mon, 12 Jun 2023 02:00:32 +0000 https://www.shuijingwanwq.com/?p=7714 Post Views: 99

1、现有的代码实现如下

<?php

use Illuminate\Support\Arr;

if (Arr::has($schema, 'sections')) {
    foreach ($schema['sections'] as $sectionKey => $section) {
        foreach ($section['blocks'] as $blockKey => $block) {
            if ($block['type'] == 'internal/size-chart/blocks/size-chart') {
                Arr::forget($schema, 'sections.' . $sectionKey . '.blocks.' . $blockKey);
                $blockOrderKey = array_search($blockKey, $section['block_order']);
                if ($blockOrderKey !== false) {
                    Arr::forget($schema, 'sections.' . $sectionKey . '.block_order.' . $blockOrderKey);
                }
            }
        }
        Arr::set($schema, 'sections.' . $sectionKey . '.block_order', array_values(Arr::get($schema, 'sections.' . $sectionKey . '.block_order')));
    }
}

return $schema;

2、使用引用传递以精简代码实现,可将 Arr::forget($schema, ‘sections.’ . $sectionKey . ‘.blocks.’ . $blockKey); 替换为:Arr::forget($section, ‘blocks.’ . $blockKey);

<?php
 
use Illuminate\Support\Arr;
 
if (Arr::has($schema, 'sections')) {
    foreach ($schema['sections'] as $sectionKey => &$section) {
        foreach ($section['blocks'] as $blockKey => $block) {
            if ($block['type'] == 'internal/size-chart/blocks/size-chart') {
                Arr::forget($section, 'blocks.' . $blockKey);
                $blockOrderKey = array_search($blockKey, $section['block_order']);
                if ($blockOrderKey !== false) {
                    Arr::forget($section, 'block_order.' . $blockOrderKey);
                }
            }
        }
        Arr::set($section, 'block_order', array_values(Arr::get($section, 'block_order')));
    }
}
 
return $schema;
]]>
https://www.shuijingwanwq.com/2023/06/12/7714/feed/ 0