date = $date; $this->importType = $importType; $this->_type = $this->_getImportType(); $this->helperData = $helperData; $this->_postFactory = $postFactory; $this->_tagFactory = $tagFactory; $this->_categoryFactory = $categoryFactory; $this->_topicFactory = $topicFactory; $this->_commentFactory = $commentFactory; $this->_userFactory = $userFactory; $this->_customerFactory = $customerFactory; $this->_objectManager = $objectManager; $this->_resourceConnection = $resourceConnection; $this->_authSession = $authSession; $this->_storeManager = $storeManager; $this->_helperImage = $helperImage; $this->authorFactory = $authorFactory; parent::__construct($context, $registry, $resource, $resourceCollection, $data); } /** * Import Post Function * * @param array $data * @param null $connection * * @return mixed */ abstract protected function _importPosts($data, $connection); /** * Import Tag Function * * @param array $data * @param null $connection * * @return mixed */ abstract protected function _importTags($data, $connection); /** * Import Category Function * * @param array $data * @param null $connection * * @return mixed */ abstract protected function _importCategories($data, $connection); /** * Import Comment Function * * @param array $data * @param null $connection * * @return mixed */ abstract protected function _importComments($data, $connection); /** * Import Author Function * * @param array $data * @param null $connection * * @return mixed */ abstract protected function _importAuthors($data, $connection); /** * Get import statistics * * @param string $type * @param int $successCount * @param int $errorCount * @param bool $hasData * * @return array */ protected function _getStatistics($type, $successCount, $errorCount, $hasData) { $statistics = [ 'type' => $type, 'success_count' => $successCount, 'error_count' => $errorCount, 'has_data' => $hasData ]; return $statistics; } /** * Reset statistic record */ protected function _resetRecords() { $this->_errorCount = 0; $this->_successCount = 0; $this->_hasData = false; } /** * Auto generate password * * @param int $length * @param bool $add_dashes * @param string $available_sets * * @return bool|string */ protected function _generatePassword($length = 9, $add_dashes = false, $available_sets = 'luds') { $sets = []; if (strpos($available_sets, 'l') !== false) { $sets[] = 'abcdefghjkmnpqrstuvwxyz'; } if (strpos($available_sets, 'u') !== false) { $sets[] = 'ABCDEFGHJKMNPQRSTUVWXYZ'; } if (strpos($available_sets, 'd') !== false) { $sets[] = '23456789'; } if (strpos($available_sets, 's') !== false) { $sets[] = '!@#$%&*?'; } $all = ''; $password = ''; foreach ($sets as $set) { $password .= $set[array_rand(str_split($set))]; $all .= $set; } $all = str_split($all); // phpcs:disable Generic.CodeAnalysis for ($i = 0; $i < $length - count($sets); $i++) { $password .= $all[array_rand($all)]; } $password = str_shuffle($password); if (!$add_dashes) { return $password; } $dash_len = floor(sqrt($length)); $dash_str = ''; while (strlen($password) > $dash_len) { $dash_str .= substr($password, 0, $dash_len) . '-'; $password = substr($password, $dash_len); } $dash_str .= $password; return $dash_str; } /** * Get import types * * @return array */ protected function _getImportType() { $types = []; foreach ($this->importType->toOptionArray() as $item) { $types[$item['value']] = $item['value']; } return $types; } }