diff --git a/Model/Import/AbstractImport.php b/Model/Import/AbstractImport.php index ec1c30dd..720d87ce 100644 --- a/Model/Import/AbstractImport.php +++ b/Model/Import/AbstractImport.php @@ -98,11 +98,6 @@ abstract class AbstractImport extends \Magento\Framework\Model\AbstractModel */ protected $_storeManager; - /** - * @var \Laminas\Db\Adapter\Adapter - */ - protected $dbAdapter; - /** * @var \Magefan\BlogAuthor\Model\AuthorFactory */ @@ -113,6 +108,21 @@ abstract class AbstractImport extends \Magento\Framework\Model\AbstractModel */ protected $productRepository; + /** + * @var \Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactory + */ + protected $connectionFactory; + + /** + * @var \Magento\Framework\Filesystem + */ + protected $fileSystem; + + /** + * @var \Magento\Framework\Filesystem\Io\File + */ + protected $file; + /** * AbstractImport constructor. * @param \Magento\Framework\Model\Context $context @@ -122,6 +132,9 @@ abstract class AbstractImport extends \Magento\Framework\Model\AbstractModel * @param \Magefan\Blog\Model\TagFactory $tagFactory * @param \Magefan\Blog\Model\CommentFactory $commentFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactory $connectionFactory + * @param \Magento\Framework\Filesystem $filesystem + * @param \Magento\Framework\Filesystem\Io\File $file * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param array $data @@ -136,6 +149,7 @@ public function __construct( \Magefan\Blog\Model\TagFactory $tagFactory, \Magefan\Blog\Model\CommentFactory $commentFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactory $connectionFactory, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Filesystem\Io\File $file, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, @@ -149,6 +163,7 @@ public function __construct( $this->_tagFactory = $tagFactory; $this->_commentFactory = $commentFactory; $this->_storeManager = $storeManager; + $this->connectionFactory = $connectionFactory; $this->fileSystem = $filesystem; $this->file = $file; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); @@ -237,47 +252,36 @@ protected function prepareIdentifier($identifier) */ public function getPrefix() { - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); + + $_pref = ''; + if ($this->getData('prefix')) { - $_pref = $adapter->getPlatform()->quoteValue( - $this->getData('prefix') - ); + $_pref = $connection->quote($this->getData('prefix')); $_pref = trim($_pref, "'"); - } else { - $_pref = ''; } return $_pref; } /** - * @return \Laminas\Db\Adapter\Adapter + * @return \Magento\Framework\DB\Adapter\AdapterInterface */ - protected function getDbAdapter() + protected function getDbConnection() { - if (null === $this->dbAdapter) { - $connectionConf = [ - 'driver' => 'Pdo_Mysql', - 'database' => $this->getData('dbname'), - 'username' => $this->getData('uname'), - 'password' => $this->getData('pwd'), - 'charset' => 'utf8', - ]; - - if ($this->getData('dbhost')) { - $connectionConf['host'] = $this->getData('dbhost'); - } - - $this->dbAdapter = new \Laminas\Db\Adapter\Adapter($connectionConf); - - try { - $this->dbAdapter->query('SELECT 1')->execute(); - } catch (\Exception $e) { - throw new \Exception("Failed connect to the database."); - } - + $connectionConf = [ + 'driver' => 'Pdo_Mysql', + 'dbname' => $this->getData('dbname'), + 'username' => $this->getData('uname'), + 'password' => $this->getData('pwd'), + 'charset' => 'utf8', + ]; + + if ($this->getData('dbhost')) { + $connectionConf['host'] = $this->getData('dbhost'); } - return $this->dbAdapter; + + return $this->connectionFactory->create($connectionConf); } protected function getFeaturedImgBySrc($src) @@ -287,6 +291,7 @@ protected function getFeaturedImgBySrc($src) $this->file->mkdir($mediaPath, 0775); $imageName = explode('?', $src); + $imageName = explode('#', $src); $imageName = explode('/', $imageName[0]); $imageName = end($imageName); $imageName = str_replace(['%20', ' '], '-', $imageName); @@ -302,7 +307,13 @@ protected function getFeaturedImgBySrc($src) if (!$hasFormat) { $imageName .= '.jpg'; } - + + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $formatIdentifier = $objectManager->get(\Magefan\Blog\Model\ResourceModel\PageIdentifierGenerator::class); + $imageNameWithoutFormat = explode('.', $imageName); + $preparedImageName = $formatIdentifier->formatIdentifier($imageNameWithoutFormat[0]); + $imageName = $preparedImageName . '.' . $imageNameWithoutFormat[1]; + $imagePath = $mediaPath . '/' . $imageName; $imageSource = false; if (!$this->file->fileExists($imagePath)) { @@ -323,4 +334,67 @@ protected function getFeaturedImgBySrc($src) return false; } } + + protected function parseContent($content) + { + $content = str_replace('', '', $content); + + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + + $fileSystem = $objectManager->create(\Magento\Framework\Filesystem::class); + $mediaPath = $fileSystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->getAbsolutePath() . '/wysiwyg/blog'; + @mkdir($mediaPath, 0777, true); + + foreach (['/src="(.*)"/Ui', '/src=\'(.*)\'/Ui'] as $patern) { + + $matches = []; + preg_match_all($patern, $content, $matches); + + + if (!empty($matches[1])) { + + foreach ($matches[1] as $src) { + //$src = $matches[1]; + $imageName = explode('?', $src); + $imageName = explode('#', $src); + $imageName = explode('/', $imageName[0]); + $imageName = end($imageName); + $imageName = str_replace(['%20', ' '], '-', $imageName); + $imageName = urldecode($imageName); + $imagePath = $mediaPath . '/' . $imageName; + if (!file_exists($imagePath)) { + + if ($imageSource = @file_get_contents($src)) { + file_put_contents( + $imagePath, + $imageSource + ); + } + } else { + $imageSource = true; + } + + if ($imageSource) { + $content = str_replace($src, '{{media url=\'wysiwyg/blog/' . $imageName . '\'}}', $content); + } else { + $content = str_replace($src, 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==', $content); + } + } + } + + } + + $content = preg_replace( + '/(srcset=".*")/Ui', + 's', + $content + ); + $content = preg_replace( + '/(srcset=\'.*\')/Ui', + 's', + $content + ); + + return $content; + } } diff --git a/Model/Import/Aw.php b/Model/Import/Aw.php index ae9aafe3..f4e30183 100644 --- a/Model/Import/Aw.php +++ b/Model/Import/Aw.php @@ -19,12 +19,14 @@ class Aw extends AbstractImport public function execute() { - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); $_pref = $this->getPrefix(); - $sql = 'SELECT * FROM '.$_pref.'aw_blog_cat LIMIT 1'; + $select = $connection->select() + ->from($_pref.'aw_blog_cat')->limit(1); + try { - $adapter->query($sql)->execute(); + $connection->fetchAll($select); } catch (\Exception $e) { throw new \Exception(__('AheadWorks Blog Extension not detected.'), 1); } @@ -35,23 +37,28 @@ public function execute() $oldCategories = []; /* Import categories */ - $sql = 'SELECT - t.cat_id as old_id, - t.title as title, - t.identifier as identifier, - t.sort_order as position, - t.meta_keywords as meta_keywords, - t.meta_description as meta_description - FROM '.$_pref.'aw_blog_cat t'; - - $result = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from(['t' => $_pref . 'aw_blog_cat'],[ + 'old_id' => 'cat_id', + 'title' => 'title', + 'identifier' => 'identifier', + 'position' => 'sort_order', + 'meta_keywords' => 'meta_keywords', + 'meta_description' => 'meta_description' + ]); + $result = $connection->fetchAll($select); foreach ($result as $data) { /* Prepare category data */ /* Find store ids */ $data['store_ids'] = []; - $s_sql = 'SELECT store_id FROM '.$_pref.'aw_blog_cat_store WHERE cat_id = "'.$data['old_id'].'"'; - $s_result = $adapter->query($s_sql)->execute(); + + $s_select = $connection->select() + ->from($_pref . 'aw_blog_cat_store', ['store_id']) + ->where('cat_id = ?', (int)$data['old_id']); + $s_result = $connection->fetchAll($s_select); + foreach ($s_result as $s_data) { $data['store_ids'][] = $s_data['store_id']; } @@ -92,12 +99,13 @@ public function execute() $oldTags = []; $existingTags = []; - $sql = 'SELECT - t.id as old_id, - t.tag as title - FROM '.$_pref.'aw_blog_tags t'; + $select = $connection->select() + ->from(['t' => $_pref . 'aw_blog_tags'], [ + 'old_id' => 'id', + 'title' => 'tag' + ]); + $result = $connection->fetchAll($select); - $result = $adapter->query($sql)->execute(); foreach ($result as $data) { /* Prepare tag data */ /* @@ -132,15 +140,22 @@ public function execute() } /* Import posts */ - $sql = 'SELECT * FROM '.$_pref.'aw_blog'; - $result = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from($_pref . 'aw_blog'); + $result = $connection->fetchAll($select); foreach ($result as $data) { /* Find post categories*/ $postCategories = []; - $c_sql = 'SELECT cat_id as category_id FROM '. - $_pref.'aw_blog_post_cat WHERE post_id = "'.$data['post_id'].'"'; - $c_result = $adapter->query($c_sql)->execute(); + + $c_select = $connection->select() + ->from($_pref . 'aw_blog_post_cat', ['category_id' => 'cat_id']) + ->where('post_id = ?', (int)$data['post_id']); + ; + + $c_result = $connection->fetchAll($c_select); + foreach ($c_result as $c_data) { $oldId = $c_data['category_id']; if (isset($oldCategories[$oldId])) { @@ -151,8 +166,13 @@ public function execute() /* Find store ids */ $data['store_ids'] = []; - $s_sql = 'SELECT store_id FROM '.$_pref.'aw_blog_store WHERE post_id = "'.$data['post_id'].'"'; - $s_result = $adapter->query($s_sql)->execute(); + + $s_select = $connection->select() + ->from($_pref . 'aw_blog_store', ['store_id']) + ->where('post_id = ?', (int)$data['post_id']); + + $s_result = $connection->fetchAll($s_select); + foreach ($s_result as $s_data) { $data['store_ids'][] = $s_data['store_id']; } @@ -193,8 +213,11 @@ public function execute() $post->setData($data)->save(); /* find post comment s*/ - $sql = 'SELECT * FROM '.$_pref.'aw_blog_comment WHERE `post_id` = ' . $post->getOldId(); - $resultComments = $adapter->query($sql)->execute(); + $select = $connection->select(); + $select->from($_pref . 'aw_blog_comment') + ->where('post_id = ?', $post->getOldId()); + + $resultComments = $connection->fetchAll($select); foreach ($resultComments as $comments) { $commentParentId = 0; @@ -244,6 +267,5 @@ public function execute() unset($post); } /* end */ - $adapter->getDriver()->getConnection()->disconnect(); } } diff --git a/Model/Import/Aw2.php b/Model/Import/Aw2.php index 0b34e6fa..297edc92 100644 --- a/Model/Import/Aw2.php +++ b/Model/Import/Aw2.php @@ -20,12 +20,14 @@ class Aw2 extends AbstractImport public function execute() { - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); $_pref = $this->getPrefix(); - $sql = 'SELECT * FROM '.$_pref.'aw_blog_category LIMIT 1'; + $select = $connection->select() + ->from($_pref . 'aw_blog_category')->limit(1); + try { - $adapter->query($sql)->execute(); + $connection->fetchAll($select); } catch (\Exception $e) { throw new \Exception(__('AheadWorks Blog Extension not detected.'), 1); } @@ -35,27 +37,31 @@ public function execute() $oldCategories = []; /* Import categories */ - $sql = 'SELECT - t.id as old_id, - t.name as title, - t.url_key as identifier, - t.sort_order as position, - t.meta_description as meta_description - FROM '.$_pref.'aw_blog_category t'; - $result = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from(['t' => $_pref . 'aw_blog_category'],[ + 'old_id' => 'id', + 'title' => 'name', + 'identifier' => 'url_key', + 'position' => 'sort_order', + 'meta_description' => 'meta_description' + ]) + ->columns(); + + $result = $connection->fetchAll($select); foreach ($result as $data) { /* Prepare category data */ /* Find store ids */ $data['store_ids'] = []; - $s_sql = 'SELECT - `store_id` - FROM - '.$_pref.'`aw_blog_category_store` - WHERE - `category_id` = '. ((int)$data['old_id']) . ";"; - $s_result = $adapter->query($s_sql)->execute(); + + $s_select = $connection->select() + ->from($_pref . 'aw_blog_category_store', ['store_id']) + ->where('category_id = ?', (int)$data['old_id']); + + $s_result = $connection->fetchAll($s_select); + foreach ($s_result as $s_data) { $data['store_ids'][] = $s_data['store_id']; } @@ -96,12 +102,14 @@ public function execute() $oldTags = []; $existingTags = []; - $sql = 'SELECT - t.id as old_id, - t.name as title - FROM '.$_pref.'aw_blog_tag t'; + $select = $connection->select() + ->from(['t' => $_pref . 'aw_blog_tag'], [ + 'old_id' => 'id', + 'title' => 'name' + ]); + + $result = $connection->fetchAll($select); - $result = $adapter->query($sql)->execute(); foreach ($result as $data) { /* Prepare tag data */ /* @@ -136,14 +144,22 @@ public function execute() } /* Import posts */ - $sql = 'SELECT * FROM '.$_pref.'aw_blog_post'; - $result = $adapter->query($sql)->execute(); + + $select = $connection->select(); + $select->from($_pref . 'aw_blog_post', ['*']); + + $result = $connection->fetchAll($select); foreach ($result as $data) { /* Find post categories*/ $postCategories = []; - $c_sql = 'SELECT category_id FROM '.$_pref.'aw_blog_post_category WHERE post_id = "'.$data['id'].'"'; - $c_result = $adapter->query($c_sql)->execute(); + + $c_select = $connection->select() + ->from($_pref . 'aw_blog_post_category', ['category_id']) + ->where('post_id = ?', (int)$data['id']); + + $c_result = $connection->fetchAll($c_select); + foreach ($c_result as $c_data) { $oldId = $c_data['category_id']; if (isset($oldCategories[$oldId])) { @@ -154,8 +170,13 @@ public function execute() /* Find store ids */ $data['store_ids'] = []; - $s_sql = 'SELECT store_id FROM '.$_pref.'aw_blog_post_store WHERE post_id = "'.$data['id'].'"'; - $s_result = $adapter->query($s_sql)->execute(); + + $s_select = $connection->select() + ->from($_pref . 'aw_blog_post_store', ['store_id']) + ->where('post_id = ?', (int)$data['id']); + + $s_result = $connection->fetchAll($s_select); + foreach ($s_result as $s_data) { $data['store_ids'][] = $s_data['store_id']; } @@ -207,6 +228,5 @@ public function execute() unset($post); } /* end */ - $adapter->getDriver()->getConnection()->disconnect(); } } diff --git a/Model/Import/Mageplaza.php b/Model/Import/Mageplaza.php index 973dec7f..aab96934 100644 --- a/Model/Import/Mageplaza.php +++ b/Model/Import/Mageplaza.php @@ -18,12 +18,13 @@ class Mageplaza extends AbstractImport public function execute() { - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); $_pref = $this->getPrefix(); - $sql = 'SELECT * FROM ' . $_pref . 'mageplaza_blog_category LIMIT 1'; + $select = $connection->select()->from($_pref . 'mageplaza_blog_category') + ->limit(1); try { - $adapter->query($sql)->execute(); + $connection->fetchAll($select); } catch (\Exception $e) { throw new \Exception(__('Mageplaza Blog Extension not detected.'), 1); } @@ -32,22 +33,19 @@ public function execute() $oldCategories = []; /* Import categories */ - $sql = 'SELECT - t.category_id as old_id, - t.name as title, - t.url_key as identifier, - t.position as position, ' . - /* - t.meta_title as meta_title, - t.meta_keywords as meta_keywords, - t.meta_description as meta_description, - */ - 't.description as content, - t.parent_id as parent_id, - t.enabled as is_active, - t.store_ids as store_ids - FROM ' . $_pref . 'mageplaza_blog_category t'; - $result = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from(['t' => $_pref . 'mageplaza_blog_category'], [ + 'old_id' => 'category_id', + 'title' => 'name', + 'identifier' => 'url_key', + 'position' => 'position', + 'content' => 'description', + 'parent_id' => 'parent_id', + 'is_active' => 'enabled', + 'store_ids' => 'store_ids', + ]); + $result = $connection->fetchAll($select);; foreach ($result as $data) { /* Prepare category data */ @@ -113,20 +111,17 @@ public function execute() $oldTags = []; $existingTags = []; - $sql = 'SELECT - t.tag_id as old_id, - t.name as title, - t.url_key as identifier, - t.description as content, ' . - /* - t.meta_title as meta_title, - t.meta_description as meta_description, - t.meta_keywords as meta_keywords, - */ - 't.enabled as is_active - FROM ' . $_pref . 'mageplaza_blog_tag t'; + $select = $connection->select() + ->from(['t' => $_pref . 'mageplaza_blog_tag'], [ + 'old_id' => 'tag_id', + 'title' => 'name', + 'identifier' => 'url_key', + 'content' => 'description', + 'is_active' => 'enabled' + ]); + + $result = $connection->fetchAll($select); - $result = $adapter->query($sql)->execute(); foreach ($result as $data) { /* Prepare tag data */ /* @@ -161,14 +156,19 @@ public function execute() } /* Import posts */ - $sql = 'SELECT * FROM ' . $_pref . 'mageplaza_blog_post'; - $result = $adapter->query($sql)->execute(); + + $select = $connection->select()->from($_pref . 'mageplaza_blog_post'); + $result = $connection->fetchAll($select); + foreach ($result as $data) { /* Find post categories*/ $postCategories = []; - $c_sql = 'SELECT category_id FROM ' . $_pref . - 'mageplaza_blog_post_category WHERE post_id = "'.$data['post_id'].'"'; - $c_result = $adapter->query($c_sql)->execute(); + + $select = $connection->select() + ->from($_pref . 'mageplaza_blog_post_category',['category_id']) + ->where('post_id = ?', $data['post_id']); + $c_result = $connection->fetchAll($select); + foreach ($c_result as $c_data) { $oldId = $c_data['category_id']; if (isset($oldCategories[$oldId])) { @@ -179,9 +179,9 @@ public function execute() /* Find post tags*/ $postTags = []; - $t_sql = 'SELECT tag_id FROM ' . $_pref . 'mageplaza_blog_post_tag WHERE post_id = "'.$data['post_id'].'"'; - - $t_result = $adapter->query($t_sql)->execute(); + $t_select = $connection->select()->from($_pref . 'mageplaza_blog_post_tag',['tag_id']) + ->where('post_id = ?', $data['post_id']); + $t_result = $connection->fetchAll($t_select); foreach ($t_result as $t_data) { $oldId = $t_data['tag_id']; @@ -222,9 +222,10 @@ public function execute() $post->setData($data)->save(); /* find post comment s*/ - $sql = 'SELECT * FROM ' . $_pref . - 'mageplaza_blog_comment WHERE `post_id` = ' . $post->getOldId(); - $resultComments = $adapter->query($sql)->execute(); + + $select = $connection->select()->from($_pref . 'mageplaza_blog_comment') + ->where('post_id = ?' , $post->getOldId()); + $resultComments = $connection->fetchAll($select); foreach ($resultComments as $comments) { $commentData = [ @@ -272,6 +273,5 @@ public function execute() unset($post); } /* end */ - $adapter->getDriver()->getConnection()->disconnect(); } } diff --git a/Model/Import/Mageplaza1.php b/Model/Import/Mageplaza1.php index cf5b1b63..ca20523d 100644 --- a/Model/Import/Mageplaza1.php +++ b/Model/Import/Mageplaza1.php @@ -30,12 +30,13 @@ class Mageplaza1 extends AbstractImport */ public function execute() { - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); $_pref = $this->getPrefix(); - $sql = 'SELECT * FROM ' . $_pref . 'mageplaza_betterblog_post LIMIT 1'; + $select = $connection->select()->from($_pref . 'mageplaza_betterblog_post')->limit(1); + try { - $adapter->query($sql)->execute(); + $connection->fetchAll($select); } catch (\Exception $e) { throw new \Exception(__('Mageplaza Blog Extension not detected.'), 1); } @@ -44,19 +45,21 @@ public function execute() $oldCategories = []; /* Import categories */ - $sql = 'SELECT - t.entity_id as old_id, - t.name as title, - t.url_key as identifier, - t.position as position, - t.meta_title as meta_title, - t.meta_keywords as meta_keywords, - t.meta_description as meta_description, - t.description as content, - t.parent_id as parent_id, - t.status as is_active - FROM ' . $_pref . 'mageplaza_betterblog_category t'; - $result = $adapter->query($sql)->execute(); + + $select = $connection->select()->from(['t' => $_pref . 'mageplaza_betterblog_category'], [ + 'old_id' => 'entity_id', + 'title' => 'name', + 'identifier' => 'url_key', + 'position' => 'position', + 'meta_title' => 'meta_title', + 'meta_keywords' => 'meta_keywords', + 'meta_description' => 'meta_description', + 'content' => 'description', + 'parent_id' => 'parent_id', + 'is_active' => 'status', + ]); + $result = $connection->fetchAll($select); + foreach ($result as $data) { /* Prepare category data */ @@ -70,8 +73,13 @@ public function execute() /* Find store ids */ $data['store_ids'] = []; - $s_sql = 'SELECT store_id FROM '.$_pref.'mageplaza_betterblog_category_store WHERE category_id = "'.$data['old_id'].'"'; - $s_result = $adapter->query($s_sql)->execute(); + + $s_select = $connection->select()->from($_pref . 'mageplaza_betterblog_category_store', ['store_id']) + ->columns() + ->where('category_id = ?', (int)$data['old_id']); + + $s_result = $connection->fetchAll($s_select); + foreach ($s_result as $s_data) { $data['store_ids'][] = $s_data['store_id']; } @@ -132,18 +140,19 @@ public function execute() $oldTags = []; $existingTags = []; - $sql = 'SELECT - t.entity_id as old_id, - t.name as title, - t.url_key as identifier, - t.description as content, - t.meta_title as meta_title, - t.meta_description as meta_description, - t.meta_keywords as meta_keywords, - t.status as is_active - FROM ' . $_pref . 'mageplaza_betterblog_tag t'; - - $result = $adapter->query($sql)->execute(); + $select = $connection->select()->from(['t' => $_pref . 'mageplaza_betterblog_tag'], [ + 'old_id' => 'entity_id', + 'title' => 'name', + 'identifier' => 'url_key', + 'content' => 'description', + 'meta_title' => 'meta_title', + 'meta_description' => 'meta_description', + 'meta_keywords' => 'meta_keywords', + 'is_active' => 'status', + ]); + + $result = $connection->fetchAll($select); + foreach ($result as $data) { if (!$data['title']) { @@ -153,8 +162,12 @@ public function execute() /* Find store ids */ $data['store_ids'] = []; - $s_sql = 'SELECT store_id FROM '.$_pref.'mageplaza_betterblog_tag_store WHERE tag_id = "'.$data['old_id'].'"'; - $s_result = $adapter->query($s_sql)->execute(); + + $select = $connection->select()->from($_pref . 'mageplaza_betterblog_tag_store', ['store_id']) + ->where('tag_id = ?', (int)$data['old_id']); + + $s_result = $connection->fetchAll($select); + foreach ($s_result as $s_data) { $data['store_ids'][] = $s_data['store_id']; } @@ -179,14 +192,26 @@ public function execute() } /* Import posts */ - $sql = 'SELECT entity_id as post_id, created_at, updated_at FROM ' . $_pref . 'mageplaza_betterblog_post'; - $result = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from($_pref . 'mageplaza_betterblog_post', [ + 'post_id' => 'entity_id', + 'created_at', + 'updated_at' + ]); + + $result = $connection->fetchAll($select); + foreach ($result as $data) { /* Find post categories*/ $postCategories = []; - $c_sql = 'SELECT category_id FROM ' . $_pref . - 'mageplaza_betterblog_post_category WHERE post_id = "'.$data['post_id'].'"'; - $c_result = $adapter->query($c_sql)->execute(); + + $select = $connection->select() + ->from($_pref . 'mageplaza_betterblog_post_category', ['category_id']) + ->where('post_id = ?', (int)$data['post_id']); + + $c_result = $connection->fetchAll($select); + foreach ($c_result as $c_data) { $oldId = $c_data['category_id']; if (isset($oldCategories[$oldId])) { @@ -197,9 +222,11 @@ public function execute() /* Find post tags*/ $postTags = []; - $t_sql = 'SELECT tag_id FROM ' . $_pref . 'mageplaza_betterblog_post_tag WHERE post_id = "'.$data['post_id'].'"'; - $t_result = $adapter->query($t_sql)->execute(); + $select = $connection->select()->from($_pref . 'mageplaza_betterblog_post_tag', ['tag_id']) + ->where('post_id = ?', (int)$data['post_id']); + + $t_result = $connection->fetchAll($select); foreach ($t_result as $t_data) { $oldId = $t_data['tag_id']; @@ -240,9 +267,11 @@ public function execute() $post->setData($data)->save(); /* find post comment s*/ - $sql = 'SELECT * FROM ' . $_pref . - 'mageplaza_betterblog_post_comment WHERE `post_id` = ' . $post->getOldId(); - $resultComments = $adapter->query($sql)->execute(); + + $select = $connection->select()->from($_pref . 'mageplaza_betterblog_post_comment', ['*']) + ->where('post_id = ?', (int)$post->getOldId()); + + $resultComments = $connection->fetchAll($select); foreach ($resultComments as $comments) { $commentData = [ @@ -283,7 +312,6 @@ public function execute() unset($post); } /* end */ - $adapter->getDriver()->getConnection()->disconnect(); } /** @@ -294,14 +322,18 @@ public function execute() */ private function getPostAttrValue($postId, $attributeCode) { - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); $_pref = $this->getPrefix(); $attribute = $this->getBlogAttributeId($attributeCode); - $sql = 'SELECT value FROM ' . $_pref . 'mageplaza_betterblog_post_' . $attribute['backend_type'] . ' WHERE entity_id = "' . ((int)$postId) . '" - AND attribute_id = "' . ((int)$attribute['attribute_id']) . '" LIMIT 1'; - $result = $adapter->query($sql)->execute(); + $select = $connection->select()->from($_pref . 'mageplaza_betterblog_post_' . $attribute['backend_type'], ['value']) + ->where('entity_id = ?', (int)$postId) + ->where('attribute_id = ?', (int)$attribute['attribute_id']) + ->limit(1); + + $result = $connection->fetchAll($select); + foreach ($result as $data) { return $data['value']; } @@ -316,11 +348,15 @@ private function getPostAttrValue($postId, $attributeCode) private function getBlogEntityId() { if (null === $this->blogEntityId) { - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); $_pref = $this->getPrefix(); - $sql = 'SELECT entity_type_id FROM ' . $_pref . 'eav_entity_type WHERE entity_type_code = "mageplaza_betterblog_post" LIMIT 1'; - $result = $adapter->query($sql)->execute(); + $select = $connection->select()->from($_pref . 'eav_entity_type', ['entity_type_id']) + ->where('entity_type_code = ?', 'mageplaza_betterblog_post') + ->limit(1); + + $result = $connection->fetchAll($select); + foreach ($result as $data) { $this->blogEntityId = (int)$data['entity_type_id']; break; @@ -343,12 +379,17 @@ private function getBlogAttributeId($attributeCode) if (!isset($this->blogAttributes[$attributeCode])) { $this->blogAttributes[$attributeCode] = []; - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); $_pref = $this->getPrefix(); - $sql = 'SELECT * FROM ' . $_pref . 'eav_attribute WHERE entity_type_id = "' . $this->getBlogEntityId() . '" - AND attribute_code = "' . $attributeCode . '" LIMIT 1'; - $result = $adapter->query($sql)->execute(); + $select = $connection->select() + ->from($_pref . 'eav_attribute') + ->where('entity_type_id = ?', $this->getBlogEntityId()) + ->where('attribute_code = ?', $attributeCode) + ->limit(1); + + $result = $connection->fetchAll($select); + foreach ($result as $data) { $this->blogAttributes[$attributeCode] = $data; break; diff --git a/Model/Import/Mirasvit.php b/Model/Import/Mirasvit.php index 48f27653..f04b5d28 100644 --- a/Model/Import/Mirasvit.php +++ b/Model/Import/Mirasvit.php @@ -21,12 +21,14 @@ class Mirasvit extends AbstractImport public function execute() { - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); $_pref = $this->getPrefix(); - $sql = 'SELECT * FROM ' . $_pref . 'mst_blog_post_entity LIMIT 1'; + $select = $connection->select() + ->from($_pref . 'mst_blog_post_entity')->limit(1); + try { - $adapter->query($sql)->execute(); + $connection->fetchAll($select); } catch (\Exception $e) { throw new \Exception(__('Mirasvit Blog Extension not detected.'), 1); } @@ -35,12 +37,15 @@ public function execute() $oldCategories = []; /* Import categories */ - $sql = 'SELECT - t.entity_id as old_id, - t.position as position, - t.parent_id as parent_id - FROM ' . $_pref . 'mst_blog_category_entity t'; - $result = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from(['t' => $_pref . 'mst_blog_category_entity'], [ + 'old_id' => 'entity_id', + 'position' => 'position', + 'parent_id' => 'parent_id' + ]); + $result = $connection->fetchAll($select); + foreach ($result as $data) { /* Prepare category data */ @@ -117,14 +122,16 @@ public function execute() $oldTags = []; $existingTags = []; - $sql = 'SELECT - t.tag_id as old_id, - t.name as title, - t.url_key as identifier, - 1 as is_active - FROM ' . $_pref . 'mst_blog_tag t'; + $select = $connection->select() + ->from(['t' => $_pref . 'mst_blog_tag'], [ + 'old_id' => 'tag_id', + 'title' => 'name', + 'identifier' => 'url_key', + 'is_active' => new \Zend_Db_Expr('1') + ]); + + $result = $connection->fetchAll($select); - $result = $adapter->query($sql)->execute(); foreach ($result as $data) { /* Prepare tag data */ /* @@ -159,15 +166,20 @@ public function execute() } /* Import posts */ - $sql = 'SELECT - t.entity_id as old_id, - t.author_id as author_id, - t.created_at as creation_time, - t.created_at as publish_time, - t.updated_at as update_time - FROM ' . $_pref . 'mst_blog_post_entity t WHERE type="post"'; - - $result = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from(['t' => $_pref . 'mst_blog_post_entity'], [ + 'old_id' => 'entity_id', + 'author_id' => 'author_id', + 'creation_time' => 'created_at', + 'publish_time' => 'created_at', + 'update_time' => 'updated_at', + ]) + ->where('type = ?', 'post'); + + $result = $connection->fetchAll($select); + + foreach ($result as $data) { $map = [ @@ -202,13 +214,13 @@ public function execute() /* Find post categories*/ $postCategories = []; - $c_sql = 'SELECT - category_id - FROM - ' . $_pref . 'mst_blog_category_post - WHERE - post_id = "'.$data['old_id'].'"'; - $c_result = $adapter->query($c_sql)->execute(); + + $c_select = $connection->select() + ->from(['c' => $_pref . 'mst_blog_category_post'], ['category_id']) + ->where('post_id = ?', $data['old_id']); + + $c_result = $connection->fetchAll($c_select); + foreach ($c_result as $c_data) { $oldId = $c_data['category_id']; if (isset($oldCategories[$oldId])) { @@ -220,9 +232,12 @@ public function execute() /* Find post tags*/ $postTags = []; - $t_sql = 'SELECT tag_id FROM ' . $_pref . 'mst_blog_tag_post WHERE post_id = "'.$data['old_id'].'"'; - $t_result = $adapter->query($t_sql)->execute(); + $t_select = $connection->select() + ->from(['tp' => $_pref . 'mst_blog_tag_post'], ['tag_id']) + ->where('post_id = ?', $data['old_id']); + + $t_result = $connection->fetchAll($t_select); foreach ($t_result as $t_data) { $oldId = $t_data['tag_id']; @@ -236,9 +251,12 @@ public function execute() /* Find post products*/ $data['links'] = []; $postProducts = []; - $t_sql = 'SELECT product_id FROM ' . $_pref . 'mst_blog_post_product WHERE post_id = "'.$data['old_id'].'"'; - $t_result = $adapter->query($t_sql)->execute(); + $t_select = $connection->select() + ->from($_pref . 'mst_blog_post_product', ['product_id']) + ->where('post_id = ?', $data['old_id']); + + $t_result = $connection->fetchAll($t_select); foreach ($t_result as $t_data) { $id = $t_data['product_id']; @@ -251,8 +269,12 @@ public function execute() /* Find store ids */ $storeIds = []; - $sql2 = 'SELECT store_id FROM ' . $_pref . 'mst_blog_store_post WHERE post_id=' . $data['old_id']; - $result2 = $adapter->query($sql2)->execute(); + + $select2 = $connection->select() + ->from($_pref . 'mst_blog_store_post', ['store_id']) + ->where('post_id = ?', $data['old_id']); + + $result2 = $connection->fetchAll($select2); foreach ($result2 as $data2) { $storeIds[] = $data2['store_id']; } @@ -270,20 +292,21 @@ public function execute() unset($post); } /* end */ - $adapter->getDriver()->getConnection()->disconnect(); } protected function getAttributValue($entitytTypeCode, $entitytId, $attributeCode) { - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); $_pref = $this->getPrefix(); if (!isset($this->entityTypeId[$entitytTypeCode])) { - $sql = 'SELECT - entity_type_id - FROM ' . $_pref . 'eav_entity_type WHERE entity_type_code="' . $entitytTypeCode . '"'; - $result = $adapter->query($sql)->execute(); + $select = $connection->select() + ->from($_pref . 'eav_entity_type', ['entity_type_id']) + ->where('entity_type_code = ?', $entitytTypeCode); + + $result = $connection->fetchAll($select); + if (count($result)) { foreach ($result as $data) { $this->entityTypeId[$entitytTypeCode] = $data['entity_type_id']; @@ -302,10 +325,13 @@ protected function getAttributValue($entitytTypeCode, $entitytId, $attributeCode if (!isset($this->entityTypeAttributes[$entitytTypeCode])) { $this->entityTypeAttributes[$entitytTypeCode] = []; - $sql = 'SELECT - * - FROM ' . $_pref . 'eav_attribute WHERE entity_type_id=' . $entityTypeId; - $result = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from($_pref . 'eav_attribute') + ->where('entity_type_id = ?', $entityTypeId); + + $result = $connection->fetchAll($select); + foreach ($result as $data) { $this->entityTypeAttributes[$entitytTypeCode][$data['attribute_code']] = $data; } @@ -317,12 +343,14 @@ protected function getAttributValue($entitytTypeCode, $entitytId, $attributeCode $attribute = $this->entityTypeAttributes[$entitytTypeCode][$attributeCode]; - $sql = 'SELECT - value - FROM ' . $_pref . 'mst_'.$entitytTypeCode.'_entity_' . $attribute['backend_type'] . ' WHERE store_id = 0 - AND attribute_id = ' . $attribute['attribute_id'] . ' - AND entity_id=' . $entitytId; - $result = $adapter->query($sql)->execute(); + $select = $connection->select() + ->from($_pref . 'mst_' . $entitytTypeCode . '_entity_' . $attribute['backend_type'], ['value']) + ->where('store_id = ?', 0) + ->where('attribute_id = ?', $attribute['attribute_id']) + ->where('entity_id = ?', $entitytId); + + $result = $connection->fetchAll($select); + if (count($result)) { foreach ($result as $data) { return $data['value']; diff --git a/Model/Import/Wordpress.php b/Model/Import/Wordpress.php index d1722c14..fc60bd09 100644 --- a/Model/Import/Wordpress.php +++ b/Model/Import/Wordpress.php @@ -17,23 +17,28 @@ class Wordpress extends AbstractImport public function execute() { - $adapter = $this->getDbAdapter(); + $connection = $this->getDbConnection(); $_pref = $this->getPrefix(); $categories = []; $oldCategories = []; /* Import categories */ - $sql = 'SELECT - t.term_id as old_id, - t.name as title, - t.slug as identifier, - tt.parent as parent_id - FROM '.$_pref.'terms t - LEFT JOIN '.$_pref.'term_taxonomy tt on t.term_id = tt.term_id - WHERE tt.taxonomy = "category" AND t.slug <> "uncategorized"'; - - $result = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from(['t' => $_pref.'terms'], [ + 'old_id' => 'term_id', + 'title' => 'name', + 'identifier' => 'slug' + ]) + ->joinLeft( + ['tt' => $_pref.'term_taxonomy'], + 't.term_id = tt.term_id', + ['parent_id' => 'parent'] + ) + ->where('tt.taxonomy = ?', 'category') + ->where('t.slug != ?', 'uncategorized'); + $result = $connection->fetchAll($select); foreach ($result as $data) { /* Prepare category data */ /* @@ -104,16 +109,22 @@ public function execute() $tags = []; $oldTags = []; - $sql = 'SELECT - t.term_id as old_id, - t.name as title, - t.slug as identifier, - tt.parent as parent_id - FROM '.$_pref.'terms t - LEFT JOIN '.$_pref.'term_taxonomy tt on t.term_id = tt.term_id - WHERE tt.taxonomy = "post_tag" AND t.slug <> "uncategorized"'; - $result = $adapter->query($sql)->execute(); + $select = $connection->select() + ->from(['t' => $_pref.'terms'], [ + 'old_id' => 'term_id', + 'title' => 'name', + 'identifier' => 'slug' + ]) + ->joinLeft( + ['tt' => $_pref.'term_taxonomy'], + 't.term_id = tt.term_id', + ['parent_id' => 'parent'] + ) + ->where('tt.taxonomy = ?', 'post_tag') + ->where('t.slug != ?', 'uncategorized'); + + $result = $connection->fetchAll($select); foreach ($result as $data) { /* Prepare tag data */ /* @@ -146,19 +157,70 @@ public function execute() } } + /* Import authors */ + $oldAuthors = []; + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + if ($objectManager->get(\Magento\Framework\Module\Manager::class)->isEnabled('Magefan_BlogAuthor')) { + $select = $connection->select() + ->from(['p' => $_pref . 'posts'], [ + 'post_author' + ]) + ->joinLeft( + ['u' => $_pref . 'users'], + 'p.post_author = u.ID', [ + 'identifier' => 'user_nicename', + 'email' => 'user_email', + 'display_name', + ] + ) + ->where('p.post_type = ?', 'post') + ->group('p.post_author'); + + $result = $connection->fetchAll($select); + foreach ($result as $data) { + /* Prepare author data */ + if (!empty($data['display_name'])) { + $data['display_name'] = explode(' ', $data['display_name'], 2); + $data['firstname'] = !empty($data['display_name'][0]) ? $data['display_name'][0] : ''; + $data['lastname'] = !empty($data['display_name'][1]) ? $data['display_name'][1] : ''; + } + + $data['identifier'] = $this->prepareIdentifier($data['identifier']); + $author = $this->_authorFactory->create(); + try { + /* Initial saving */ + $author->setData($data)->save(); + $this->_importedAuthorsCount++; + $oldAuthors[$data['post_author']] = $author; + } catch (\Magento\Framework\Exception\LocalizedException $e) { + unset($author); + $this->_logger->debug('Blog Author Import [' . $data['identifier'] . ']: ' . $e->getMessage()); + } + } + } + /* Import posts */ - $sql = 'SELECT * FROM '.$_pref.'posts WHERE `post_type` = "post"'; - $result = $adapter->query($sql)->execute(); + $select = $connection->select() + ->from($_pref.'posts') + ->where('post_type = ?', 'post'); + + $result = $connection->fetchAll($select); foreach ($result as $data) { /* find post categories*/ $postCategories = []; - $sql = 'SELECT tt.term_id as term_id FROM '.$_pref.'term_relationships tr - LEFT JOIN '.$_pref.'term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id - WHERE tr.`object_id` = "'.$data['ID'].'" AND tt.taxonomy = "category"'; - - $result2 = $adapter->query($sql)->execute(); + $select2 = $connection->select() + ->from(['tr' => $_pref . 'term_relationships'], ['term_id' => 'tt.term_id']) + ->join( + ['tt' => $_pref . 'term_taxonomy'], + 'tr.term_taxonomy_id = tt.term_taxonomy_id', + [] + ) + ->where('tr.object_id = ?', $data['ID']) + ->where('tt.taxonomy = ?', 'category'); + + $result2 = $connection->fetchAll($select2); foreach ($result2 as $data2) { $oldTermId = $data2['term_id']; if (isset($oldCategories[$oldTermId])) { @@ -169,11 +231,17 @@ public function execute() /* find post tags*/ $postTags = []; - $sql = 'SELECT tt.term_id as term_id FROM '.$_pref.'term_relationships tr - LEFT JOIN '.$_pref.'term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id - WHERE tr.`object_id` = "'.$data['ID'].'" AND tt.taxonomy = "post_tag"'; - - $result2 = $adapter->query($sql)->execute(); + $select2 = $connection->select() + ->from(['tr' => $_pref . 'term_relationships'],['term_id' => 'tt.term_id']) + ->join( + ['tt' => $_pref . 'term_taxonomy'], + 'tr.term_taxonomy_id = tt.term_taxonomy_id', + [] + ) + ->where('tr.object_id = ?', $data['ID']) + ->where('tt.taxonomy = ?', 'post_tag'); + + $result2 = $connection->fetchAll($select2); foreach ($result2 as $data2) { $oldTermId = $data2['term_id']; if (isset($oldTags[$oldTermId])) { @@ -183,30 +251,23 @@ public function execute() $data['featured_img'] = ''; - $sql = 'SELECT wm2.meta_value as featured_img - FROM - '.$_pref.'posts p1 - LEFT JOIN - '.$_pref.'postmeta wm1 - ON ( - wm1.post_id = p1.id - AND wm1.meta_value IS NOT NULL - AND wm1.meta_key = "_thumbnail_id" - ) - LEFT JOIN - '.$_pref.'postmeta wm2 - ON ( - wm1.meta_value = wm2.post_id - AND wm2.meta_key = "_wp_attached_file" - AND wm2.meta_value IS NOT NULL - ) - WHERE - p1.ID="'.$data['ID'].'" - AND p1.post_type="post" - ORDER BY - p1.post_date DESC'; - - $result2 = $adapter->query($sql)->execute(); + $select2 = $connection->select() + ->from(['p1' => $_pref . 'posts'],['featured_img' => 'wm2.meta_value']) + ->join( + ['wm1' => $_pref . 'postmeta'], + 'wm1.post_id = p1.id AND wm1.meta_value IS NOT NULL AND wm1.meta_key = "_thumbnail_id"', + [] + ) + ->join( + ['wm2' => $_pref . 'postmeta'], + 'wm1.meta_value = wm2.post_id AND wm2.meta_key = "_wp_attached_file" AND wm2.meta_value IS NOT NULL', + [] + ) + ->where('p1.ID = ?', $data['ID']) + ->where('p1.post_type = ?', 'post') + ->order('p1.post_date DESC'); + + $result2 = $connection->fetchAll($select2); foreach ($result2 as $data2) { if ($data2['featured_img']) { $data['featured_img'] = \Magefan\Blog\Model\Post::BASE_MEDIA_PATH . '/' . $data2['featured_img']; @@ -216,23 +277,18 @@ public function execute() if (empty($data['featured_img'])) { - $sql = 'SELECT wm1.meta_value as featured_img - FROM - '.$_pref.'posts p1 - LEFT JOIN - '.$_pref.'postmeta wm1 - ON ( - wm1.post_id = p1.id - AND wm1.meta_value IS NOT NULL - AND wm1.meta_key = "dfiFeatured" - ) - WHERE - p1.ID="'.$data['ID'].'" - AND p1.post_type="post" - ORDER BY - p1.post_date DESC'; - - $result2 = $adapter->query($sql)->execute(); + $select2 = $connection->select() + ->from(['p1' => $_pref . 'posts'], ['featured_img' => 'wm1.meta_value']) + ->join( + ['wm1' => $_pref . 'postmeta'], + 'wm1.post_id = p1.id AND wm1.meta_value IS NOT NULL AND wm1.meta_key = "dfiFeatured"', + [] + ) + ->where('p1.ID = ?', $data['ID']) + ->where('p1.post_type = ?', 'post') + ->order('p1.post_date DESC'); + + $result2 = $connection->fetchAll($select2); foreach ($result2 as $data2) { if ($data2['featured_img']) { $serializeInterface = \Magento\Framework\App\ObjectManager::getInstance() @@ -255,8 +311,12 @@ public function execute() } /* Find Meta Data */ - $sql = 'SELECT * FROM `'.$_pref.'postmeta` WHERE `post_id` = ' . ((int)$data['ID']); - $metaResult = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from($_pref . 'postmeta') + ->where('post_id = ?', (int)$data['ID']); + + $metaResult = $connection->fetchAll($select); foreach ($metaResult as $metaData) { $metaValue = trim(isset($metaData['meta_value']) ? $metaData['meta_value'] : ''); @@ -287,7 +347,7 @@ public function execute() $creationTime = strtotime((string)$data['post_date_gmt']); $content = $data['post_content']; - $content = str_replace('', '', $content); + $content = $this->parseContent($content); $content = preg_replace( '/src=[\'"]((http:\/\/|https:\/\/|\/\/)(.*)|(\s|"|\')|(\/[\d\w_\-\.]*))\/wp-content\/uploads(.*)((\.jpg|\.jpeg|\.gif|\.png|\.tiff|\.tif|\.svg)|(\s|"|\'))[\'"\s]/Ui', @@ -315,6 +375,7 @@ public function execute() 'categories' => $postCategories, 'tags' => $postTags, 'featured_img' => $data['featured_img'], + 'author_id' => (isset($data['post_author']) && isset($oldAuthors[$data['post_author']])) ? $oldAuthors[$data['post_author']]->getId() : null, ]; $data['identifier'] = $this->prepareIdentifier($data['identifier']); @@ -325,15 +386,14 @@ public function execute() $post->setData($data)->save(); /* find post comment s*/ - $sql = 'SELECT - * - FROM - '.$_pref.'comments - WHERE - `comment_approved`=1 - AND - `comment_post_ID` = ' . $wordpressPostId; - $resultComments = $adapter->query($sql)->execute(); + + $select = $connection->select() + ->from($_pref . 'comments') + ->where('comment_approved = ?', 1) + ->where('comment_post_ID = ?', $wordpressPostId); + + $resultComments = $connection->fetchAll($select); + $commentParents = []; foreach ($resultComments as $comments) { @@ -383,8 +443,6 @@ public function execute() unset($post); } /* end */ - - $adapter->getDriver()->getConnection()->disconnect(); } protected function wordpressOutoutWrap($pee, $br = true)