Skip to content

Commit 32761c6

Browse files
committed
fix import issues
1 parent 8a7bbac commit 32761c6

File tree

6 files changed

+265
-239
lines changed

6 files changed

+265
-239
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# 1.0.10 - 08/17/2021
2-
- Release Lof_ElasticsuiteBlog: a Smile_ElasticSuite addon
2+
- Release Lof_ElasticsuiteBlog: a Smile_ElasticSuite addon
3+
4+
# 1.0.12 - 01/25/2024
5+
- Compatible magento 2.4.x, PHP 8.1, PHP 8.2
6+
- Remove Addthis widget (social share settings)

Controller/Adminhtml/Importer/Edit.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22
/**
33
* Venustheme
4-
*
4+
*
55
* NOTICE OF LICENSE
6-
*
6+
*
77
* This source file is subject to the Venustheme.com license that is
88
* available through the world-wide-web at this URL:
99
* http://www.venustheme.com/license-agreement.html
10-
*
10+
*
1111
* DISCLAIMER
12-
*
12+
*
1313
* Do not edit or add to this file if you wish to upgrade this extension to newer
1414
* version in the future.
15-
*
15+
*
1616
* @category Venustheme
1717
* @package Ves_Blog
1818
* @copyright Copyright (c) 2016 Venustheme (http://www.venustheme.com/)
@@ -36,6 +36,11 @@ class Edit extends \Magento\Backend\App\Action
3636
*/
3737
protected $resultPageFactory;
3838

39+
/**
40+
* @var \Ves\Blog\Model\ImporterFactory
41+
*/
42+
protected $importerFactory;
43+
3944
/**
4045
* @param Action\Context
4146
* @param \Magento\Framework\View\Result\PageFactory
@@ -44,9 +49,11 @@ class Edit extends \Magento\Backend\App\Action
4449
public function __construct(
4550
Action\Context $context,
4651
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
47-
\Magento\Framework\Registry $registry
52+
\Magento\Framework\Registry $registry,
53+
\Ves\Blog\Model\ImporterFactory $importerFactory
4854
) {
4955
$this->resultPageFactory = $resultPageFactory;
56+
$this->importerFactory = $importerFactory;
5057
$this->_coreRegistry = $registry;
5158
parent::__construct($context);
5259
}
@@ -85,7 +92,7 @@ public function execute()
8592
{
8693
// 1. Get ID and create model
8794
$id = $this->getRequest()->getParam('importer_id');
88-
$model = $this->_objectManager->create('Ves\Blog\Model\Importer');
95+
$model = $this->importerFactory->create();
8996

9097
// 2. Initial checking
9198
if ($id) {

Model/Import/AbstractImport.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22
/**
33
* Venustheme
4-
*
4+
*
55
* NOTICE OF LICENSE
6-
*
6+
*
77
* This source file is subject to the Venustheme.com license that is
88
* available through the world-wide-web at this URL:
99
* http://www.venustheme.com/license-agreement.html
10-
*
10+
*
1111
* DISCLAIMER
12-
*
12+
*
1313
* Do not edit or add to this file if you wish to upgrade this extension to newer
1414
* version in the future.
15-
*
15+
*
1616
* @category Venustheme
1717
* @package Ves_Blog
1818
* @copyright Copyright (c) 2016 Venustheme (http://www.venustheme.com/)
@@ -65,6 +65,8 @@ abstract class AbstractImport extends \Magento\Framework\Model\AbstractModel
6565
* @param \Magento\Framework\App\ResourceConnection\ConnectionFactory $connectionFactory
6666
* @param \Magento\Framework\Filesystem\Io\File $file
6767
* @param \Magento\Framework\Filesystem\DirectoryList $dir
68+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null
69+
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null
6870
* @param array $data
6971
*/
7072
public function __construct(
@@ -78,13 +80,13 @@ public function __construct(
7880
\Magento\Framework\ObjectManagerInterface $objectManager,
7981
\Magento\Backend\Model\Auth\Session $authSession,
8082
\Ves\Blog\Helper\Data $helper,
81-
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
82-
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
8383
\Magento\Framework\App\ResourceConnection\ConnectionFactory $connectionFactory,
8484
\Magento\Framework\Filesystem\Io\File $file,
8585
\Magento\Framework\Filesystem\DirectoryList $dir,
86+
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
87+
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
8688
array $data = []
87-
) {
89+
) {
8890
$this->_postFactory = $postFactory;
8991
$this->_categoryFactory = $categoryFactory;
9092
$this->_commentFactory = $commentFactory;
@@ -99,6 +101,9 @@ public function __construct(
99101
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
100102
}
101103

104+
/**
105+
* @inheritdoc
106+
*/
102107
protected function _connect()
103108
{
104109
$con = '';
@@ -109,7 +114,7 @@ protected function _connect()
109114
$dbhost = $this->getData('dbhost');
110115
$charset = $this->getData('connect_charset');
111116
$charset = $charset?$charset:'utf8mb4';
112-
117+
113118
if($dbname=='' || $uname=='' || $pwd=='' || $dbhost==''){
114119
throw new \Exception(__("Some fields are required"));
115120
}
@@ -118,7 +123,7 @@ protected function _connect()
118123
'dbname' => $dbname,
119124
'username' => $uname,
120125
'password' => $pwd,
121-
'active' => '1',
126+
'active' => '1',
122127
));
123128
$con->query("SET character_set_results = '".$charset."', character_set_client = '".$charset."', character_set_connection = '".$charset."', character_set_database = '".$charset."', character_set_server = '".$charset."'");
124129
} catch (\Exception $e) {
@@ -138,7 +143,8 @@ protected function getImageImportFolder($path)
138143
return $images . '/';
139144
}
140145

141-
public function getConnection(){
146+
public function getConnection()
147+
{
142148
if(!$this->_connect){
143149
$this->_connect();
144150
}

Model/Import/Wordpress.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22
/**
33
* Venustheme
4-
*
4+
*
55
* NOTICE OF LICENSE
6-
*
6+
*
77
* This source file is subject to the Venustheme.com license that is
88
* available through the world-wide-web at this URL:
99
* http://www.venustheme.com/license-agreement.html
10-
*
10+
*
1111
* DISCLAIMER
12-
*
12+
*
1313
* Do not edit or add to this file if you wish to upgrade this extension to newer
1414
* version in the future.
15-
*
15+
*
1616
* @category Venustheme
1717
* @package Ves_Blog
1818
* @copyright Copyright (c) 2016 Venustheme (http://www.venustheme.com/)
@@ -25,6 +25,9 @@ class Wordpress extends AbstractImport
2525
protected $_oldCategories = [];
2626
protected $_catCount = 0;
2727

28+
/**
29+
* @inheritdoc
30+
*/
2831
public function execute()
2932
{
3033
$importPosts = $this->getData('import_posts');
@@ -65,7 +68,7 @@ public function execute()
6568
$data[$i]['name'] = $cat['name'];
6669
$data[$i]['parent_id'] = $cat['parent'];
6770
$data[$i]['stores'] = [$this->_storeManager->getDefaultStoreView()->getStoreId()];
68-
$i++;
71+
$i++;
6972
}
7073
}
7174
if($data){
@@ -79,7 +82,7 @@ public function execute()
7982
$_cat['category_id'] = $category->getId();
8083
$_cat['image'] = $_cat['layout_type'] = $_cat['orderby'] = $_cat['comments'] = $_cat['item_per_page'] = $_cat['lg_column_item'] = $_cat['md_column_item'] = $_cat['sm_column_item'] = $_cat['xs_column_item'] = $_cat['page_layout'] = $_cat['page_title'] = $_cat['canonical_url'] = $_cat['layout_update_xml'] = $_cat['meta_keywords'] = $_cat['meta_description'] = $_cat['posts_style'] = $_cat['posts_template'] = $_cat['post_template'] = '';
8184
}
82-
$_cat['importing'] = true;
85+
$_cat['importing'] = true;
8386
$category->setData($_cat)->save();
8487
$cats[] = $this->drawItems($data, $_cat, 0, $category->getId());
8588
$oldCategories = $this->_oldCategories;
@@ -126,12 +129,12 @@ public function execute()
126129
// Image
127130
$image = '';
128131
$real_image_url = '';
129-
$sql = "SELECT ( SELECT guid FROM " . $prefix . "posts WHERE id = m.meta_value ) AS url
132+
$sql = "SELECT ( SELECT guid FROM " . $prefix . "posts WHERE id = m.meta_value ) AS url
130133
FROM " . $prefix . "posts p, " . $prefix . "postmeta m
131134
WHERE p.post_type = 'post'
132135
AND p.post_status = 'publish'
133136
AND p.id = m.post_id
134-
AND m.meta_key = '_thumbnail_id'
137+
AND m.meta_key = '_thumbnail_id'
135138
AND p.id = '" . $data['ID'] . "'" ;
136139
$result3 = $this->_mysqliQuery($sql);
137140
if($result3){
@@ -146,8 +149,8 @@ public function execute()
146149
}
147150
}
148151
}
149-
150-
152+
153+
151154
// Tags
152155
$postTags = [];
153156
if($importTags){
@@ -257,7 +260,11 @@ public function execute()
257260
}
258261
}
259262

260-
public function decodeImg($str){
263+
public function decodeImg($str)
264+
{
265+
if (!$str) {
266+
return $str;
267+
}
261268
$count = substr_count($str, "<img");
262269
$tmpImg = '';
263270
for ($i=0; $i < $count; $i++) {
@@ -276,12 +283,14 @@ public function decodeImg($str){
276283
return $str;
277284
}
278285

279-
public function getCategory($cat_id = 0){
286+
public function getCategory($cat_id = 0)
287+
{
280288
$category = $this->_categoryFactory->create();
281289
return $category->load((int)$cat_id);
282290
}
283291

284-
public function drawItems($collection, $cat, $level = 0, $parentId = ''){
292+
public function drawItems($collection, $cat, $level = 0, $parentId = '')
293+
{
285294
$overwrite = $this->getData('overwrite');
286295
$oldCategories = $this->_oldCategories;
287296
foreach ($collection as $_cat) {
@@ -312,4 +321,4 @@ public function drawItems($collection, $cat, $level = 0, $parentId = ''){
312321

313322
return $cat;
314323
}
315-
}
324+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"venustheme/module-all":"1.0.*"
66
},
77
"type": "magento2-module",
8-
"version": "1.0.11",
8+
"version": "1.0.12",
99
"license": [
1010
"OSL-3.0",
1111
"AFL-3.0"

0 commit comments

Comments
 (0)