Skip to content

Commit 6bbcdd5

Browse files
author
Bohdan Berezhniy
committed
compatibility for customers that already configured lazy laod
1 parent cbe2fe4 commit 6bbcdd5

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
9+
declare(strict_types = 1);
10+
11+
namespace Magefan\LazyLoad\Setup\Patch\Data;
12+
13+
use Magento\Framework\Setup\Patch\DataPatchInterface;
14+
use Magento\Framework\Setup\ModuleDataSetupInterface;
15+
use Magefan\LazyLoad\Model\Config as Config;
16+
use Magento\Framework\App\Config\Storage\WriterInterface;
17+
use Magento\Framework\App\Config\ScopeConfigInterface;
18+
use Magefan\LazyLoad\Model\Config\Source\Method as LazyLoadMethod;
19+
use Magefan\LazyLoad\Model\Config\Source\BlocksToLazyLoad;
20+
21+
class SaveDefaultLazyLoadMethod implements DataPatchInterface
22+
{
23+
/**
24+
* @var ModuleDataSetupInterface
25+
*/
26+
private $moduleDataSetup;
27+
28+
/**
29+
* @var Config
30+
*/
31+
private $config;
32+
33+
/**
34+
* @var WriterInterface
35+
*/
36+
private $configWriter;
37+
38+
/**
39+
* @param ModuleDataSetupInterface $moduleDataSetup
40+
* @param Config $config
41+
* @param WriterInterface $configWriter
42+
*/
43+
public function __construct(
44+
ModuleDataSetupInterface $moduleDataSetup,
45+
Config $config,
46+
WriterInterface $configWriter
47+
) {
48+
$this->moduleDataSetup = $moduleDataSetup;
49+
$this->config = $config;
50+
$this->configWriter = $configWriter;
51+
}
52+
53+
/**
54+
* Set Default Lazy Load Method as JS to keep existing lazy load config for customers that configured lazy laod.
55+
*
56+
* @return void
57+
*/
58+
public function apply()
59+
{
60+
$this->moduleDataSetup->startSetup();
61+
62+
$connection = $this->moduleDataSetup->getConnection();
63+
$tableName = $this->moduleDataSetup->getTable('core_config_data');
64+
65+
if ($this->config->getBlocksInfo()) {
66+
$query = $connection->select()
67+
->from($tableName, ['config_id', 'value'])
68+
->where('path = ?', Config::XML_PATH_LAZY_METHOD);
69+
70+
// if lazy load was installed previusly and lazy laod method not set yet, set js lazy load as a default method
71+
if (!$connection->fetchAll($query)) {
72+
$this->configWriter->save(Config::XML_PATH_LAZY_METHOD, LazyLoadMethod::JAVASCRIPT);
73+
$this->configWriter->save(Config::XML_PATH_LAZY_BLOCKS_TO_LAZY_LOAD, BlocksToLazyLoad::SELECTED);
74+
}
75+
}
76+
77+
$this->moduleDataSetup->endSetup();
78+
}
79+
80+
/**
81+
* @return array|string[]
82+
*/
83+
public static function getDependencies()
84+
{
85+
return [];
86+
}
87+
88+
/**
89+
* @return array|string[]
90+
*/
91+
public function getAliases()
92+
{
93+
return [];
94+
}
95+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"magefan/module-rocketjavascript": "Install Rocket JavaScript to optimize JS loading."
1010
},
1111
"type": "magento2-module",
12-
"version": "2.0.23.1",
12+
"version": "2.1.0",
1313
"authors": [
1414
{
1515
"name": "Magefan",

0 commit comments

Comments
 (0)