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

123 lines
3.6 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
*/
ini_set('max_execution_time', 86400);
ini_set('display_errors', 'On');
error_reporting(E_ALL);
define('IMPORTING_NOW', true);
define('_PS_ADMIN_DIR_', true);
require_once "./../../config/config.inc.php";
require_once "./config.php";
ini_set('display_errors', 'On');
error_reporting(E_ALL);
if (file_exists(dirname(__FILE__) . "/direct_import_now")) {
if (!isset($argv) && isset($_GET['stoplastimport'])) {
unlink(dirname(__FILE__) . "/direct_import_now");
$fs = glob(dirname(__FILE__) . "/import-status/*");
foreach ($fs as $f) {
unlink($f);
}
header('location: ?');
}
if (isset($argv)) {
$msg = "last direct import not finished! options:\n"
. "- remove file 'direct_import_now' to stop\n";
if ((isset($argv[1]) && ($key = $argv[1]))) {
$msg .= "- continue import by: ./direct_continue.sh '" . $key . "'";
}
die($msg);
} else {
$msg = "last direct import not finished! options:\n"
. "- remove file 'direct_import_now' to stop\n";
if (($key = Tools::getValue('securekey'))) {
$msg .= "- continue import by: <a href='direct_import_continue.php?securekey=" . $key . "'>click to continue</a>";
}
die($msg);
}
}
if (!Tools::getValue('securekey') || Tools::getValue('securekey') != _IMPORT_SECURE_KEY_) {
if (!Tools::getValue('securekey') && (!isset($argv[1]) || $argv[1] != _IMPORT_SECURE_KEY_)) {
die('direct access denied');
}
}
$queue = PShow_Queue::getInstance();
$i = 0;
while (($fileToImport = Tools::getValue('file' . ++$i))) {
$queue->addToQueue($fileToImport);
}
if (isset($argv) && is_array($argv) && count($argv) > 2) {
$i = 2;
while (isset($argv[$i]) && !empty($argv[$i])) {
$queue->addToQueue($argv[$i]);
++$i;
}
}
$queue->saveToFile();
while (is_string($fileToImport = $queue->getFromQueue())) {
$queue->saveToFile();
if (PShow_Import::getInstance($fileToImport) instanceof PShow_Import) {
file_put_contents(getModulePath(__FILE__) . "/direct_import_now", "1");
do {
if (!file_exists(getModulePath(__FILE__) . "/direct_import_now")) {
echo "<p>IMPORT STOPPED!</p>";
break;
}
PShow_Import::getInstance()->refreshStatus();
$rows_to_import = PShow_Import::getInstance()->config[0]['rowsCount'] - PShow_Import::getInstance()->status['actual_row'];
PShow_Import::getInstance()->importToDatabase();
} while (($rows_to_import - 1) > 0);
// disable maintenance mode
if ((bool) Configuration::get('pshowimporter_maintenance_mode') && PShow_Import::getInstance()->maintenance_mode_enabled) {
PShow_Log::addImportLog("disabled maintenance mode");
Configuration::updateValue('PS_SHOP_ENABLE', '1');
}
PShow_Import::getInstance()->disableProductsNonExistingInTheFile();
PShow_Import::getInstance()->resetQuantityForNonExistingInTheFile();
PShow_Import::getInstance()->fixCategoriesDepth();
sleep(1);
PShow_File::unlink(getModulePath(__FILE__) . "/direct_import_now");
array_map('PShow_File::unlink', glob(_IMPORT_STATUS_PATH_ . "*"));
}
sleep(1);
}
die('IMPORT FINISHED');