Files
interblue.pl/modules/pshowimporter/pshowimporter.php
2024-10-25 14:16:28 +02:00

166 lines
7.2 KiB
PHP

<?php
/**
* File from http://PrestaShow.pl
*
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @authors PrestaShow.pl <kontakt@prestashow.pl>
* @copyright 2015 PrestaShow.pl
* @license http://PrestaShow.pl/license
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require_once dirname(__FILE__) . "/config.php";
class PShowImporter extends PShowModule
{
/**
* Module controller with tab in admin menu
*/
public $admin_menu_tab = 'PShowImporterMain';
/**
* Module controllers without tab in admin menu
*/
public $controllers = array(
'PShowImporterBackup',
'PShowImporterUpdate',
'PShowImporterReportBug',
'PShowImporterHook',
'PShowImporterImport',
'PShowImporterConfig',
'PShowImporterSettings'
);
/**
* Append here all new versions which has got update functions
*
* example:
* $moduleVersionPath = array('1.0.0', '1.1.0', '1.2.0')
* during update from 1.0.0 to 1.2.0 functions with be called(if exists):
* update_from_1_1()
* update_from_1_2()
*/
public $moduleVersionPath = array();
/**
* Primary configuration
*/
public $name = 'pshowimporter';
public $tab = 'other';
public $version = '2.204.0';
public $ps_versions_compliancy = array('min' => '1.5', 'max' => _PS_VERSION_);
public $trusted = true;
/**
* constructor
*/
public function __construct()
{
parent::__construct();
$this->displayName = $this->l('PShow Importer');
$this->description = $this->l('Professional importing module for e-commerce system - PrestaShop.');
$version_tmp = preg_replace('~([^0-9]+)~', null, $this->version);
// add column `import` to the products table
Product::$definition['fields']['import'] = array('type' => ObjectModel::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool');
if (!Configuration::get('PShowImpProImpS' . $version_tmp)) {
try {
$q = "ALTER TABLE `" . _DB_PREFIX_ . "product` ADD COLUMN `import` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1; ";
Db::getInstance()->execute($q);
$q = "ALTER TABLE `" . _DB_PREFIX_ . "product_shop` ADD COLUMN `import` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1; ";
Db::getInstance()->execute($q);
} catch (PrestaShopDatabaseException $e) {
file_put_contents(
PShowUpdateNew::getInstance(__FILE__)->getModulePath() . 'exceptions.log', "[" . date('d-m-Y H:i:s') . "]" . $e->getMessage() . "\n\n", FILE_APPEND
);
}
Configuration::updateValue('PShowImpProImpS' . $version_tmp, 1);
if (defined('_PS_ADMIN_DIR_')) {
$this->adminDisplayInformation($this->l('Updated database schema for field Product->import.'));
}
}
// add columns to the combinations table
Combination::$definition['fields']['width'] = array('type' => ObjectModel::TYPE_FLOAT, 'validate' => 'isUnsignedFloat');
Combination::$definition['fields']['height'] = array('type' => ObjectModel::TYPE_FLOAT, 'validate' => 'isUnsignedFloat');
Combination::$definition['fields']['depth'] = array('type' => ObjectModel::TYPE_FLOAT, 'validate' => 'isUnsignedFloat');
Combination::$definition['fields']['description'] = array('type' => ObjectModel::TYPE_HTML, 'size' => 1000000);
if (!Configuration::get('PShowImpCombDim' . $version_tmp)) {
try {
$q = "ALTER TABLE `" . _DB_PREFIX_ . "product_attribute` ADD COLUMN `description` TEXT NOT NULL; ";
Db::getInstance()->execute($q);
$q = "ALTER TABLE `" . _DB_PREFIX_ . "product_attribute` ADD COLUMN `width` DECIMAL(20, 6) NOT NULL DEFAULT 0.000000; ";
Db::getInstance()->execute($q);
$q = "ALTER TABLE `" . _DB_PREFIX_ . "product_attribute` ADD COLUMN `height` DECIMAL(20, 6) NOT NULL DEFAULT 0.000000; ";
Db::getInstance()->execute($q);
$q = "ALTER TABLE `" . _DB_PREFIX_ . "product_attribute` ADD COLUMN `depth` DECIMAL(20, 6) NOT NULL DEFAULT 0.000000; ";
Db::getInstance()->execute($q);
} catch (PrestaShopDatabaseException $e) {
file_put_contents(
PShowUpdateNew::getInstance(__FILE__)->getModulePath() . 'exceptions.log', "[" . date('d-m-Y H:i:s') . "]" . $e->getMessage() . "\n\n", FILE_APPEND
);
}
Configuration::updateValue('PShowImpCombDim' . $version_tmp, 1);
if (defined('_PS_ADMIN_DIR_')) {
$this->adminDisplayInformation($this->l('Updated database schema for combination dimension fields.'));
}
}
/**
* Save PHP command to file
*/
$get_php_command_content = '<?php $command = "%s"; if (php_sapi_name() === "cli") echo $command; else return $command;';
$get_php_command_path = PShowUpdateNew::getInstance(__FILE__)->getModulePath() . 'get_php_command.php';
$php_command = PShow_Settings::getInstance(__FILE__)->get('php_command');
if (!$php_command || empty($php_command)) {
PShow_Settings::getInstance(__FILE__)->set('php_command', 'php');
file_put_contents($get_php_command_path, sprintf($get_php_command_content, "php"));
} elseif (!file_exists($get_php_command_path)) {
file_put_contents($get_php_command_path, sprintf($get_php_command_content, $php_command));
} else {
$get_php_command = require $get_php_command_path;
if ($php_command != $get_php_command) {
file_put_contents($get_php_command_path, sprintf($get_php_command_content, $php_command));
}
}
/**
* Save CPU limit to file
*/
$cpu_limit_content = '<?php $command = "%s"; if (php_sapi_name() === "cli") echo $command; else return $command;';
$cpu_limit_path = PShowUpdateNew::getInstance(__FILE__)->getModulePath() . 'get_cpu_limit.php';
$cpu_limit = (int) PShow_Settings::getInstance(__FILE__)->get('cpu_limit');
if ((!$cpu_limit || empty($cpu_limit) || $cpu_limit <= 0) && file_exists($cpu_limit_path)) {
unlink($cpu_limit_path);
} elseif (!file_exists($cpu_limit_path) && $cpu_limit > 0) {
file_put_contents($cpu_limit_path, sprintf($cpu_limit_content, $cpu_limit));
} elseif (file_exists($cpu_limit_path)) {
$cpu_limit_ = require $cpu_limit_path;
if ($cpu_limit_ != $cpu_limit) {
file_put_contents($cpu_limit_path, sprintf($cpu_limit_content, $cpu_limit));
}
}
}
public function hookDisplayBackOfficeTop()
{
if (Tools::getValue('controller') == 'PShowImporterImport') {
return;
}
if ((bool) PShow_Settings::getInstance(__FILE__)->get('mod_combination_dimensions')) {
$this->context->controller->addJS(__PS_BASE_URI__ . 'modules/pshowimporter/views/js/admin_combination_sizes.js');
}
return parent::hookDisplayBackOfficeTop();
}
}