Skip to content

Instantly share code, notes, and snippets.

@volandku
Created February 10, 2020 13:15
Show Gist options
  • Save volandku/15d7a697cc82ccefe03ce28e09bebd43 to your computer and use it in GitHub Desktop.
Save volandku/15d7a697cc82ccefe03ce28e09bebd43 to your computer and use it in GitHub Desktop.
joomla seblod import cli
<?php
/**
* @package ${NAMESPACE}
* @subpackage
*
* @copyright A copyright
* @license A "Slug" license name e.g. GPL2
*/
require_once __DIR__."/helpers/xml.seblod.php";
use Joomla\Registry\Registry;
use ws_xml_import\XMLExport;
const _JEXEC = 1;
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
// Load system defines
//if (file_exists(dirname(__DIR__) . '/defines.php'))
//{
// require_once dirname(__DIR__) . '/defines.php';
//}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__).'/../..');
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';
// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';
class wsImportSeblod extends JApplicationCli
{
public $helper = null;
public $plugins = null;
public $starttime = null;
public function __construct()
{
parent::__construct();
$this->db = JFactory::getDbo();
// Set JFactory::$application object to avoid system using incorrect defaults
//JFactory::$application = $this;
}
// public function getTemplate($params = false)
// {
// $template = new \stdClass;
//
// $template->template = 'system';
// $template->params = new Registry;
//
// if ($params)
// {
// return $template;
// }
//
// return $template->template;
// }
public function doExecute()
{
$links = array();
//$p=getopt('u:');
//$url=$p['u'];
if (!isset($url)) $url=__DIR__."/0920.xml";
$app = JFactory::getApplication('administrator'); //Вот только плевать на переданные параметры!!
// $app->loadSession();
//$app=&$this;
date_default_timezone_set('UTC');
$this->starttime = time();
$db = JFactory::getDbo();
if (isset($url))
{
$export = new XMLExport;
$export->imit=TRUE; // пока дебажим
$export->cli=TRUE;
$export->loadJsonConfig(__DIR__."/0920.json");
//var_dump($export->config);
if (true) {
$ru = $export->langFull[0]; // Не обязательно русский
// Build our language object
$lang = \JLanguage::getInstance($ru);
// Load the language to the API
$app->loadLanguage($lang);
// Register the language object with \JFactory
\JFactory::$language = $app->getLanguage();
// Load the library language files
$app->getLanguage()->load('lib_joomla', JPATH_ADMINISTRATOR);
}
if (false) {
$ru = $export->langFull[0];
$lang = JFactory::getLanguage();
$lang = \JLanguage::getInstance($ru);
$lang->load('lib_joomla', JPATH_ADMINISTRATOR);
}
if ($export->loadURL($url))
{
//$export->parseCategories();
//$export->getCategories();
// ну вот нет в данном проекте категорий, плоская структура однако
// die();
//$export->writeCategories();
$export->usleep=5;
$export->parseFrom();
$export->writeTo();
// $export->parseAndWriteProducts();
$export->log("message","Теперь памяти используется ".round(memory_get_usage(TRUE)/1000000)." Мб");
$export->log('message','Времени ушло '.round(time()-$this->starttime));
}
}
else
{
echo "Не задан параметр -u для адреса xml-файла";
}
}
}
JApplicationCli::getInstance('wsImportSeblod')->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment