Version Notes
Download this release
Release Info
Developer | Codisto |
Extension | codistoconnect |
Version | 1.90.7 |
Comparing to | |
See all releases |
Code changes from version 1.90.6 to 1.90.7
- app/code/community/Codisto/Sync/Helper/Data.php +350 -4
- app/code/community/Codisto/Sync/Model/Sync.php +461 -15
- app/code/community/Codisto/Sync/controllers/IndexController.php +2 -1
- app/code/community/Codisto/Sync/controllers/SyncController.php +48 -14
- app/code/community/Codisto/Sync/data/codisto_setup/{data-install-1.90.6.php → data-install-1.90.7.php} +0 -0
- app/code/community/Codisto/Sync/etc/config.xml +1 -1
- app/code/community/Codisto/Sync/sql/codisto_setup/{mysql4-install-1.90.6.php → mysql4-install-1.90.7.php} +0 -0
- package.xml +1 -1
app/code/community/Codisto/Sync/Helper/Data.php
CHANGED
@@ -73,7 +73,12 @@ class Codisto_Sync_Helper_Data extends Mage_Core_Helper_Abstract
|
|
73 |
|
74 |
public function getCodistoVersion()
|
75 |
{
|
76 |
-
return (string)
|
|
|
|
|
|
|
|
|
|
|
77 |
}
|
78 |
|
79 |
public function checkRequestHash($key, $server)
|
@@ -144,7 +149,19 @@ class Codisto_Sync_Helper_Data extends Mage_Core_Helper_Abstract
|
|
144 |
{
|
145 |
$createMerchant = false;
|
146 |
|
147 |
-
$lockFile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
for($retry = 0;;$retry++)
|
150 |
{
|
@@ -356,10 +373,339 @@ class Codisto_Sync_Helper_Data extends Mage_Core_Helper_Abstract
|
|
356 |
|
357 |
public function canSyncIncrementally($syncDbPath, $storeId)
|
358 |
{
|
|
|
|
|
359 |
|
|
|
360 |
|
|
|
361 |
|
362 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
}
|
364 |
|
365 |
public function logExceptionCodisto(Exception $e, $endpoint)
|
@@ -436,7 +782,7 @@ class Codisto_Sync_Helper_Data extends Mage_Core_Helper_Abstract
|
|
436 |
return tempnam( $base_path , $path . '-' );
|
437 |
}
|
438 |
|
439 |
-
public function prepareSqliteDatabase($db, $
|
440 |
{
|
441 |
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
442 |
$db->setAttribute(PDO::ATTR_TIMEOUT, $timeout);
|
73 |
|
74 |
public function getCodistoVersion()
|
75 |
{
|
76 |
+
return (string)Mage::getConfig()->getNode()->modules->Codisto_Sync->version;
|
77 |
+
}
|
78 |
+
|
79 |
+
public function getTriggerMode()
|
80 |
+
{
|
81 |
+
return (string)Mage::getConfig()->getNode()->modules->Codisto_Sync->trigger_mode != 'false';
|
82 |
}
|
83 |
|
84 |
public function checkRequestHash($key, $server)
|
149 |
{
|
150 |
$createMerchant = false;
|
151 |
|
152 |
+
$lockFile;
|
153 |
+
|
154 |
+
try
|
155 |
+
{
|
156 |
+
$file = new Varien_Io_File();
|
157 |
+
$file->checkAndCreateFolder( Mage::getBaseDir('var') . '/codisto/', 0777 );
|
158 |
+
|
159 |
+
$lockFile = Mage::getBaseDir('var') . '/codisto/lock';
|
160 |
+
}
|
161 |
+
catch(Exception $e)
|
162 |
+
{
|
163 |
+
$lockFile = Mage::getBaseDir('var') . '/codisto-lock';
|
164 |
+
}
|
165 |
|
166 |
for($retry = 0;;$retry++)
|
167 |
{
|
373 |
|
374 |
public function canSyncIncrementally($syncDbPath, $storeId)
|
375 |
{
|
376 |
+
if(!$this->getTriggerMode())
|
377 |
+
return false;
|
378 |
|
379 |
+
$adapter = Mage::getModel('core/resource')->getConnection(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE);
|
380 |
|
381 |
+
$tablePrefix = Mage::getConfig()->getTablePrefix();
|
382 |
|
383 |
+
// change tables
|
384 |
+
$changeTableDefs = array(
|
385 |
+
'codisto_product_change' => 'CREATE TABLE `'.$tablePrefix.'codisto_product_change` (product_id int(10) unsigned NOT NULL PRIMARY KEY, stamp datetime NOT NULL)',
|
386 |
+
'codisto_order_change' => 'CREATE TABLE `'.$tablePrefix.'codisto_order_change` (order_id int(10) unsigned NOT NULL PRIMARY KEY, stamp datetime NOT NULL)',
|
387 |
+
'codisto_category_change' => 'CREATE TABLE `'.$tablePrefix.'codisto_category_change` (category_id int(10) unsigned NOT NULL PRIMARY KEY, stamp datetime NOT NULL)'
|
388 |
+
);
|
389 |
+
|
390 |
+
$changeTablesExist = true;
|
391 |
+
|
392 |
+
$changeTables = $adapter->fetchCol('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE \''.$tablePrefix.'codisto_%_change\'');
|
393 |
+
if(is_array($changeTables))
|
394 |
+
{
|
395 |
+
$changeTables = array_flip( $changeTables );
|
396 |
+
|
397 |
+
foreach($changeTableDefs as $table => $createStatement)
|
398 |
+
{
|
399 |
+
if(!isset($changeTables[$tablePrefix.$table]))
|
400 |
+
{
|
401 |
+
$adapter->query($changeTableDefs[$table]);
|
402 |
+
|
403 |
+
$changeTablesExist = false;
|
404 |
+
}
|
405 |
+
}
|
406 |
+
}
|
407 |
+
|
408 |
+
// trigger management
|
409 |
+
$stdCodistoProductChangeStmt = 'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = NEW.entity_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;';
|
410 |
+
$stdCodistoProductDeleteStmt = 'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = OLD.entity_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;';
|
411 |
+
$stdCodistoCategoryChangeStmt = 'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_category_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_category_change` SET category_id = NEW.entity_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE category_id = category_id, stamp = UTC_TIMESTAMP(); END IF;';
|
412 |
+
$stdCodistoCategoryDeleteStmt = 'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_category_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_category_change` SET category_id = OLD.entity_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE category_id = category_id, stamp = UTC_TIMESTAMP(); END IF;';
|
413 |
+
|
414 |
+
$triggerStaticRules = array(
|
415 |
+
'catalog_product_entity' => array( $stdCodistoProductChangeStmt, $stdCodistoProductChangeStmt, $stdCodistoProductDeleteStmt ),
|
416 |
+
'catalog_product_entity_datetime' => array( $stdCodistoProductChangeStmt, $stdCodistoProductChangeStmt, $stdCodistoProductDeleteStmt ),
|
417 |
+
'catalog_product_entity_decimal' => array( $stdCodistoProductChangeStmt, $stdCodistoProductChangeStmt, $stdCodistoProductDeleteStmt ),
|
418 |
+
'catalog_product_entity_gallery' => array( $stdCodistoProductChangeStmt, $stdCodistoProductChangeStmt, $stdCodistoProductDeleteStmt ),
|
419 |
+
'catalog_product_entity_group_price' => array( $stdCodistoProductChangeStmt, $stdCodistoProductChangeStmt, $stdCodistoProductDeleteStmt ),
|
420 |
+
'catalog_product_entity_int' => array( $stdCodistoProductChangeStmt, $stdCodistoProductChangeStmt, $stdCodistoProductDeleteStmt ),
|
421 |
+
'catalog_product_entity_media_gallery' => array( $stdCodistoProductChangeStmt, $stdCodistoProductChangeStmt, $stdCodistoProductDeleteStmt ),
|
422 |
+
'catalog_product_entity_text' => array( $stdCodistoProductChangeStmt, $stdCodistoProductChangeStmt, $stdCodistoProductDeleteStmt ),
|
423 |
+
'catalog_product_entity_varchar' => array( $stdCodistoProductChangeStmt, $stdCodistoProductChangeStmt, $stdCodistoProductDeleteStmt ),
|
424 |
+
'cataloginventory_stock_item' => array(
|
425 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = NEW.product_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;',
|
426 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = NEW.product_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;',
|
427 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = OLD.product_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;'
|
428 |
+
),
|
429 |
+
'cataloginventory_stock_status' => array(
|
430 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = NEW.product_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;',
|
431 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = NEW.product_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;',
|
432 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = OLD.product_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;'
|
433 |
+
),
|
434 |
+
'catalog_category_entity' => array( $stdCodistoCategoryChangeStmt, $stdCodistoCategoryChangeStmt, $stdCodistoCategoryDeleteStmt ),
|
435 |
+
'catalog_category_entity_datetime' => array( $stdCodistoCategoryChangeStmt, $stdCodistoCategoryChangeStmt, $stdCodistoCategoryDeleteStmt ),
|
436 |
+
'catalog_category_entity_decimal' => array( $stdCodistoCategoryChangeStmt, $stdCodistoCategoryChangeStmt, $stdCodistoCategoryDeleteStmt ),
|
437 |
+
'catalog_category_entity_int' => array( $stdCodistoCategoryChangeStmt, $stdCodistoCategoryChangeStmt, $stdCodistoCategoryDeleteStmt ),
|
438 |
+
'catalog_category_entity_text' => array( $stdCodistoCategoryChangeStmt, $stdCodistoCategoryChangeStmt, $stdCodistoCategoryDeleteStmt ),
|
439 |
+
'catalog_category_entity_varchar' => array( $stdCodistoCategoryChangeStmt, $stdCodistoCategoryChangeStmt, $stdCodistoCategoryDeleteStmt ),
|
440 |
+
'catalog_category_product' => array(
|
441 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = NEW.product_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;'.
|
442 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_category_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_category_change` SET category_id = NEW.category_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE category_id = category_id, stamp = UTC_TIMESTAMP(); END IF;',
|
443 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = NEW.product_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;'.
|
444 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_category_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_category_change` SET category_id = NEW.category_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE category_id = category_id, stamp = UTC_TIMESTAMP(); END IF;',
|
445 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_product_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_product_change` SET product_id = OLD.product_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE product_id = product_id, stamp = UTC_TIMESTAMP(); END IF;'.
|
446 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_category_change\') THEN INSERT INTO `'.$tablePrefix.'codisto_category_change` SET category_id = OLD.category_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE category_id = category_id, stamp = UTC_TIMESTAMP(); END IF;'
|
447 |
+
),
|
448 |
+
'sales_flat_order' => array(
|
449 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND COALESCE(NEW.codisto_orderid, \'\') != \'\' THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = NEW.entity_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;',
|
450 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND COALESCE(NEW.codisto_orderid, \'\') != \'\' THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = NEW.entity_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;',
|
451 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND COALESCE(OLD.codisto_orderid, \'\') != \'\' THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = OLD.entity_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;'
|
452 |
+
),
|
453 |
+
'sales_flat_invoice' => array(
|
454 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND EXISTS(SELECT 1 FROM `'.$tablePrefix.'sales_flat_order` WHERE entity_id = NEW.order_id AND COALESCE(codisto_orderid, \'\') != \'\') THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = NEW.order_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;',
|
455 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND EXISTS(SELECT 1 FROM `'.$tablePrefix.'sales_flat_order` WHERE entity_id = NEW.order_id AND COALESCE(codisto_orderid, \'\') != \'\') THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = NEW.order_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;',
|
456 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND EXISTS(SELECT 1 FROM `'.$tablePrefix.'sales_flat_order` WHERE entity_id = OLD.order_id AND COALESCE(codisto_orderid, \'\') != \'\') THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = OLD.order_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;'
|
457 |
+
),
|
458 |
+
'sales_flat_shipment' => array(
|
459 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND EXISTS(SELECT 1 FROM `'.$tablePrefix.'sales_flat_order` WHERE entity_id = NEW.order_id AND COALESCE(codisto_orderid, \'\') != \'\') THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = NEW.order_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;',
|
460 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND EXISTS(SELECT 1 FROM `'.$tablePrefix.'sales_flat_order` WHERE entity_id = NEW.order_id AND COALESCE(codisto_orderid, \'\') != \'\') THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = NEW.order_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;',
|
461 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND EXISTS(SELECT 1 FROM `'.$tablePrefix.'sales_flat_order` WHERE entity_id = OLD.order_id AND COALESCE(codisto_orderid, \'\') != \'\') THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = OLD.order_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;'
|
462 |
+
),
|
463 |
+
'sales_flat_shipment_track' => array(
|
464 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND EXISTS(SELECT 1 FROM `'.$tablePrefix.'sales_flat_order` WHERE entity_id = NEW.order_id AND COALESCE(codisto_orderid, \'\') != \'\') THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = NEW.order_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;',
|
465 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND EXISTS(SELECT 1 FROM `'.$tablePrefix.'sales_flat_order` WHERE entity_id = NEW.order_id AND COALESCE(codisto_orderid, \'\') != \'\') THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = NEW.order_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;',
|
466 |
+
'IF EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \''.$tablePrefix.'codisto_order_change\') AND EXISTS(SELECT 1 FROM `'.$tablePrefix.'sales_flat_order` WHERE entity_id = OLD.order_id AND COALESCE(codisto_orderid, \'\') != \'\') THEN INSERT INTO `'.$tablePrefix.'codisto_order_change` SET order_id = OLD.order_id, stamp = UTC_TIMESTAMP() ON DUPLICATE KEY UPDATE order_id = order_id, stamp = UTC_TIMESTAMP(); END IF;'
|
467 |
+
)
|
468 |
+
);
|
469 |
+
|
470 |
+
$triggerRules = array();
|
471 |
+
foreach($triggerStaticRules as $table => $statements)
|
472 |
+
{
|
473 |
+
$triggerRules[$tablePrefix.$table] = array( 'table' => $table, 'statements' => $statements );
|
474 |
+
}
|
475 |
+
|
476 |
+
$adapter->query('CREATE TEMPORARY TABLE `codisto_triggers` ( `table` varchar(100) NOT NULL PRIMARY KEY, `insert_statement` varchar(2000) NOT NULL, `update_statement` varchar(2000) NOT NULL, `delete_statement` varchar(2000) NOT NULL )');
|
477 |
+
foreach($triggerRules as $table => $tableData)
|
478 |
+
{
|
479 |
+
$adapter->insert('codisto_triggers', array( 'table' => $table, 'insert_statement' => $tableData['statements'][0], 'update_statement' => $tableData['statements'][1], 'delete_statement' => $tableData['statements'][2] ) );
|
480 |
+
}
|
481 |
+
|
482 |
+
$missingTriggers = $adapter->fetchAll(
|
483 |
+
'SELECT T.`table`, '.
|
484 |
+
'TYPE.`type`, '.
|
485 |
+
'CASE WHEN TRIGGER_NAME IS NULL THEN 0 ELSE -1 END AS `exists`, '.
|
486 |
+
'COALESCE(EXISTING.TRIGGER_CATALOG, \'\') AS `current_catalog`, '.
|
487 |
+
'COALESCE(EXISTING.TRIGGER_SCHEMA, \'\') AS `current_schema`, '.
|
488 |
+
'COALESCE(EXISTING.TRIGGER_NAME, \'\') AS `current_name`, '.
|
489 |
+
'COALESCE(EXISTING.ACTION_STATEMENT, \'\') AS `current_statement`, '.
|
490 |
+
'COALESCE(EXISTING.DEFINER, \'\') AS `current_definer`, '.
|
491 |
+
'COALESCE(EXISTING.SQL_MODE, \'\') AS `current_sqlmode` '.
|
492 |
+
'FROM `codisto_triggers` AS T '.
|
493 |
+
'CROSS JOIN (SELECT \'UPDATE\' AS `type` UNION ALL SELECT \'INSERT\' UNION ALL SELECT \'DELETE\') AS TYPE '.
|
494 |
+
'LEFT JOIN INFORMATION_SCHEMA.TRIGGERS AS EXISTING ON EXISTING.EVENT_OBJECT_TABLE = T.`table` AND EXISTING.ACTION_TIMING = \'AFTER\' AND EXISTING.EVENT_MANIPULATION = TYPE.`type` '.
|
495 |
+
'WHERE NOT EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TRIGGERS WHERE EVENT_OBJECT_TABLE = T.`table` AND ACTION_TIMING = \'AFTER\' AND EVENT_MANIPULATION = TYPE.`type` AND ACTION_STATEMENT LIKE CONCAT(\'%\', CASE WHEN TYPE.`type` = \'INSERT\' THEN T.`insert_statement` WHEN TYPE.`type` = \'UPDATE\' THEN T.`update_statement` WHEN TYPE.`type` = \'DELETE\' THEN T.`delete_statement` END, \'%\'))');
|
496 |
+
|
497 |
+
$changeTriggersExist = true;
|
498 |
+
|
499 |
+
if(count($missingTriggers) > 0)
|
500 |
+
{
|
501 |
+
$changeTriggersExist = false;
|
502 |
+
|
503 |
+
$triggerTypeMap = array( 'INSERT' => 0, 'UPDATE' => 1, 'DELETE' => 2 );
|
504 |
+
|
505 |
+
$existingTriggers = array();
|
506 |
+
foreach($missingTriggers as $trigger)
|
507 |
+
{
|
508 |
+
if(isset($trigger['current_name']) && $trigger['current_name'] &&
|
509 |
+
$trigger['current_statement'])
|
510 |
+
{
|
511 |
+
$existingTriggers[] = array(
|
512 |
+
'current_definer' => $trigger['current_definer'],
|
513 |
+
'current_schema' => $trigger['current_schema'],
|
514 |
+
'current_name' => $trigger['current_name'],
|
515 |
+
'current_statement' => $trigger['current_statement'],
|
516 |
+
'current_sqlmode' => $trigger['current_sqlmode'],
|
517 |
+
'type' => $trigger['type'],
|
518 |
+
'table' => $trigger['table']
|
519 |
+
);
|
520 |
+
}
|
521 |
+
}
|
522 |
+
|
523 |
+
if(!empty($existingTriggers))
|
524 |
+
{
|
525 |
+
$adapter->query('CREATE TABLE IF NOT EXISTS `'.$tablePrefix.'codisto_trigger_backup` (definer text NOT NULL, current_schema text NOT NULL, current_name text NOT NULL, current_statement text NOT NULL, type text NOT NULL, `table` text NOT NULL, stamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)');
|
526 |
+
|
527 |
+
foreach($existingTriggers as $trigger)
|
528 |
+
{
|
529 |
+
$adapter->insert($tablePrefix.'codisto_trigger_backup', array(
|
530 |
+
'definer' => $trigger['current_definer'],
|
531 |
+
'current_schema' => $trigger['current_schema'],
|
532 |
+
'current_name' => $trigger['current_name'],
|
533 |
+
'current_statement' => $trigger['current_statement'],
|
534 |
+
'type' => $trigger['type'],
|
535 |
+
'table' => $trigger['table']
|
536 |
+
));
|
537 |
+
}
|
538 |
+
}
|
539 |
+
|
540 |
+
foreach($missingTriggers as $trigger)
|
541 |
+
{
|
542 |
+
$triggerRule = $triggerRules[$trigger['table']];
|
543 |
+
|
544 |
+
$table = $triggerRule['table'];
|
545 |
+
$statement = $triggerRule['statements'][$triggerTypeMap[$trigger['type']]];
|
546 |
+
|
547 |
+
try
|
548 |
+
{
|
549 |
+
$final_statement = "\n/* start codisto change tracking trigger */\n".$statement."\n/* end codisto change tracking trigger */\n";
|
550 |
+
|
551 |
+
$adapter->query('DROP TRIGGER IF EXISTS codisto_'.$table.'_'.strtolower($trigger['type']));
|
552 |
+
$adapter->query('CREATE DEFINER = CURRENT_USER TRIGGER codisto_'.$table.'_'.strtolower($trigger['type']).' AFTER '.$trigger['type'].' ON `'.$trigger['table'].'`'."\n".'FOR EACH ROW BEGIN '.$final_statement.'END');
|
553 |
+
|
554 |
+
// TODO: loop on existing triggers for this class that match /* start codisto change tracking trigger */ and remove
|
555 |
+
}
|
556 |
+
catch(Exception $e)
|
557 |
+
{
|
558 |
+
if(method_exists($e, 'hasChainedException') &&
|
559 |
+
$e->hasChainedException() &&
|
560 |
+
$e->getChainedException() instanceof PDOException &&
|
561 |
+
is_array($e->getChainedException()->errorInfo) &&
|
562 |
+
$e->getChainedException()->errorInfo[1] == 1235)
|
563 |
+
{
|
564 |
+
// this version of mysql doesn't support multiple triggers so let's modify the existing trigger
|
565 |
+
|
566 |
+
$current_statement = preg_replace('/^BEGIN|END$/i', '', $trigger['current_statement']);
|
567 |
+
$cleaned_statement = preg_replace('/\s*\/\*\s+start\s+codisto\s+change\s+tracking\s+trigger\s+\*\/.*\/\*\s+end\s+codisto\s+change\s+tracking\s+trigger\s+\*\/\n?\s*/is', '', $current_statement);
|
568 |
+
$final_statement = preg_replace('/;\s*;/', ';', $cleaned_statement."\n/* start codisto change tracking trigger */\n".$statement)
|
569 |
+
."\n/* end codisto change tracking trigger */\n";
|
570 |
+
|
571 |
+
if(!preg_match('/^\s/', $final_statement))
|
572 |
+
{
|
573 |
+
$final_statement = "\n".$final_statement;
|
574 |
+
}
|
575 |
+
if(!preg_match('/\s$/', $final_statement))
|
576 |
+
{
|
577 |
+
$final_statement = $final_statement."\n";
|
578 |
+
}
|
579 |
+
|
580 |
+
$definer = $trigger['current_definer'];
|
581 |
+
if(strpos($definer, '@') !== false)
|
582 |
+
{
|
583 |
+
$definer = explode('@', $definer);
|
584 |
+
$definer[0] = '\''.$definer[0].'\'';
|
585 |
+
$definer[1] = '\''.$definer[1].'\'';
|
586 |
+
$definer = implode('@', $definer);
|
587 |
+
}
|
588 |
+
|
589 |
+
try
|
590 |
+
{
|
591 |
+
$adapter->query('SET @saved_sql_mode = @@sql_mode');
|
592 |
+
$adapter->query('SET sql_mode = \''.$trigger['current_sqlmode'].'\'');
|
593 |
+
$adapter->query('DROP TRIGGER `'.$trigger['current_schema'].'`.`'.$trigger['current_name'].'`');
|
594 |
+
$adapter->query('CREATE DEFINER = '.$definer.' TRIGGER `'.$trigger['current_name'].'` AFTER '.$trigger['type'].' ON `'.$trigger['table'].'`'."\n".' FOR EACH ROW BEGIN'.$final_statement.'END');
|
595 |
+
$adapter->query('SET sql_mode = @saved_sql_mode');
|
596 |
+
}
|
597 |
+
catch(Exception $e2)
|
598 |
+
{
|
599 |
+
try
|
600 |
+
{
|
601 |
+
$adapter->query('SET @saved_sql_mode = @@sql_mode');
|
602 |
+
$adapter->query('SET sql_mode = \''.$trigger['current_sqlmode'].'\'');
|
603 |
+
$adapter->query('CREATE DEFINER = '.$definer.' TRIGGER `'.$trigger['current_name'].'` AFTER '.$trigger['type'].' ON `'.$trigger['table'].'`'."\n".'FOR EACH ROW '.$trigger['current_statement']);
|
604 |
+
$adapter->query('SET sql_mode = @saved_sql_mode');
|
605 |
+
}
|
606 |
+
catch(Exception $e3)
|
607 |
+
{
|
608 |
+
throw new Exception($e2->getMessage().' '.$e3->getMessage());
|
609 |
+
}
|
610 |
+
|
611 |
+
throw $e2;
|
612 |
+
}
|
613 |
+
}
|
614 |
+
else
|
615 |
+
{
|
616 |
+
throw $e;
|
617 |
+
}
|
618 |
+
}
|
619 |
+
}
|
620 |
+
}
|
621 |
+
|
622 |
+
$adapter->query('DROP TABLE codisto_triggers');
|
623 |
+
|
624 |
+
// check sync db exists
|
625 |
+
$syncDbExists = false;
|
626 |
+
$syncDb = null;
|
627 |
+
|
628 |
+
try
|
629 |
+
{
|
630 |
+
$syncDb = new PDO('sqlite:' . $syncDbPath);
|
631 |
+
|
632 |
+
$this->prepareSqliteDatabase( $syncDb, 60 );
|
633 |
+
|
634 |
+
$qry = $syncDb->query('PRAGMA quick_check');
|
635 |
+
|
636 |
+
$checkResult = $qry->fetchColumn();
|
637 |
+
|
638 |
+
$qry->closeCursor();
|
639 |
+
|
640 |
+
if($checkResult == 'ok')
|
641 |
+
$syncDbExists = true;
|
642 |
+
}
|
643 |
+
catch(Exception $e)
|
644 |
+
{
|
645 |
+
|
646 |
+
}
|
647 |
+
|
648 |
+
// check sync db uuid and mage uuid
|
649 |
+
$changeToken = null;
|
650 |
+
try
|
651 |
+
{
|
652 |
+
$changeToken = $adapter->fetchOne('SELECT token FROM `'.$tablePrefix.'codisto_sync` WHERE store_id = '.(int)$storeId);
|
653 |
+
}
|
654 |
+
catch(Exception $e)
|
655 |
+
{
|
656 |
+
|
657 |
+
}
|
658 |
+
|
659 |
+
$syncToken = null;
|
660 |
+
if($syncDb)
|
661 |
+
{
|
662 |
+
$qry = null;
|
663 |
+
try
|
664 |
+
{
|
665 |
+
try
|
666 |
+
{
|
667 |
+
$qry = $syncDb->query('SELECT token FROM sync');
|
668 |
+
|
669 |
+
$syncToken = $qry->fetchColumn();
|
670 |
+
}
|
671 |
+
catch(Exception $e)
|
672 |
+
{
|
673 |
+
if($qry)
|
674 |
+
$qry->closeCursor();
|
675 |
+
}
|
676 |
+
}
|
677 |
+
catch(Exception $e)
|
678 |
+
{
|
679 |
+
|
680 |
+
}
|
681 |
+
}
|
682 |
+
|
683 |
+
return (!is_null($changeToken) && $changeToken != '') &&
|
684 |
+
($changeToken == $syncToken) &&
|
685 |
+
$changeTablesExist &&
|
686 |
+
$changeTriggersExist &&
|
687 |
+
$syncDbExists;
|
688 |
+
}
|
689 |
+
|
690 |
+
public function cleanSyncFolder()
|
691 |
+
{
|
692 |
+
$file = new Varien_Io_File();
|
693 |
+
|
694 |
+
$syncFolder = Mage::getBaseDir('var') . '/codisto/';
|
695 |
+
|
696 |
+
if($file->fileExists($syncFolder, false /* dirs as well */))
|
697 |
+
{
|
698 |
+
foreach(@glob($syncFolder.'sync-*', GLOB_NOESCAPE|GLOB_NOSORT) as $filePath)
|
699 |
+
{
|
700 |
+
if(preg_match('/-first-\d+\.db$/', $filePath) === 1 || preg_match('/\.db$/', $filePath) === 0)
|
701 |
+
{
|
702 |
+
if(@filemtime($filePath) < time() - 86400)
|
703 |
+
{
|
704 |
+
@unlink($filePath);
|
705 |
+
}
|
706 |
+
}
|
707 |
+
}
|
708 |
+
}
|
709 |
}
|
710 |
|
711 |
public function logExceptionCodisto(Exception $e, $endpoint)
|
782 |
return tempnam( $base_path , $path . '-' );
|
783 |
}
|
784 |
|
785 |
+
public function prepareSqliteDatabase($db, $timeout = 60, $pagesize = 65536)
|
786 |
{
|
787 |
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
788 |
$db->setAttribute(PDO::ATTR_TIMEOUT, $timeout);
|
app/code/community/Codisto/Sync/Model/Sync.php
CHANGED
@@ -198,7 +198,7 @@ class Codisto_Sync_Model_Sync
|
|
198 |
{
|
199 |
$db = new PDO('sqlite:' . $templateDb);
|
200 |
|
201 |
-
Mage::helper('codistosync')->prepareSqliteDatabase($db);
|
202 |
|
203 |
$files = $db->prepare('SELECT Name, Content FROM File');
|
204 |
$files->execute();
|
@@ -240,7 +240,7 @@ class Codisto_Sync_Model_Sync
|
|
240 |
{
|
241 |
$store = Mage::app()->getStore($storeId);
|
242 |
|
243 |
-
$db = $this->GetSyncDb($syncDb);
|
244 |
|
245 |
$insertCategory = $db->prepare('INSERT OR REPLACE INTO Category(ExternalReference, Name, ParentExternalReference, LastModified, Enabled, Sequence) VALUES(?,?,?,?,?,?)');
|
246 |
|
@@ -257,7 +257,7 @@ class Codisto_Sync_Model_Sync
|
|
257 |
|
258 |
public function DeleteCategory($syncDb, $id, $storeId)
|
259 |
{
|
260 |
-
$db = $this->GetSyncDb($syncDb);
|
261 |
|
262 |
$args = array();
|
263 |
$args[] = $id;
|
@@ -276,7 +276,7 @@ class Codisto_Sync_Model_Sync
|
|
276 |
{
|
277 |
$store = Mage::app()->getStore($storeId);
|
278 |
|
279 |
-
$db = $this->GetSyncDb($syncDb);
|
280 |
|
281 |
$insertCategoryProduct = $db->prepare('INSERT OR IGNORE INTO CategoryProduct(ProductExternalReference, CategoryExternalReference, Sequence) VALUES(?,?,?)');
|
282 |
$insertProduct = $db->prepare('INSERT INTO Product(ExternalReference, Type, Code, Name, Price, ListPrice, TaxClass, Description, Enabled, StockControl, StockLevel, Weight, InStore) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
@@ -397,7 +397,7 @@ class Codisto_Sync_Model_Sync
|
|
397 |
|
398 |
public function DeleteProduct($syncDb, $ids, $storeId)
|
399 |
{
|
400 |
-
$db = $this->GetSyncDb($syncDb);
|
401 |
|
402 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
403 |
|
@@ -1328,11 +1328,446 @@ class Codisto_Sync_Model_Sync
|
|
1328 |
$this->currentEntityId = $orderData['entity_id'];
|
1329 |
}
|
1330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1331 |
public function SyncChunk($syncDb, $simpleCount, $configurableCount, $storeId, $first)
|
1332 |
{
|
1333 |
$store = Mage::app()->getStore($storeId);
|
1334 |
|
1335 |
-
$db = $this->GetSyncDb($syncDb);
|
1336 |
|
1337 |
$insertCategory = $db->prepare('INSERT OR REPLACE INTO Category(ExternalReference, Name, ParentExternalReference, LastModified, Enabled, Sequence) VALUES(?,?,?,?,?,?)');
|
1338 |
$insertCategoryProduct = $db->prepare('INSERT OR IGNORE INTO CategoryProduct(ProductExternalReference, CategoryExternalReference, Sequence) VALUES(?,?,?)');
|
@@ -1676,14 +2111,25 @@ class Codisto_Sync_Model_Sync
|
|
1676 |
$db->exec('INSERT OR REPLACE INTO Progress (Sentinel, State, entity_id) VALUES (1, \'complete\', 0)');
|
1677 |
}
|
1678 |
|
1679 |
-
$db->exec('COMMIT TRANSACTION');
|
1680 |
-
|
1681 |
if((empty($this->productsProcessed) && empty($this->ordersProcessed)) || $first)
|
1682 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1683 |
return 'complete';
|
1684 |
}
|
1685 |
else
|
1686 |
{
|
|
|
|
|
1687 |
return 'pending';
|
1688 |
}
|
1689 |
}
|
@@ -1709,7 +2155,7 @@ class Codisto_Sync_Model_Sync
|
|
1709 |
|
1710 |
public function SyncStaticBlocks($syncDb, $storeId)
|
1711 |
{
|
1712 |
-
$db = $this->GetSyncDb($syncDb);
|
1713 |
|
1714 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
1715 |
|
@@ -1738,7 +2184,7 @@ class Codisto_Sync_Model_Sync
|
|
1738 |
|
1739 |
public function SyncTax($syncDb, $storeId)
|
1740 |
{
|
1741 |
-
$db = $this->GetSyncDb($syncDb);
|
1742 |
|
1743 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
1744 |
|
@@ -1860,7 +2306,7 @@ class Codisto_Sync_Model_Sync
|
|
1860 |
|
1861 |
public function SyncStores($syncDb, $storeId)
|
1862 |
{
|
1863 |
-
$db = $this->GetSyncDb($syncDb);
|
1864 |
|
1865 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
1866 |
$db->exec('DELETE FROM Store');
|
@@ -1925,7 +2371,7 @@ class Codisto_Sync_Model_Sync
|
|
1925 |
{
|
1926 |
$store = Mage::app()->getStore($storeId);
|
1927 |
|
1928 |
-
$db = $this->GetSyncDb($syncDb);
|
1929 |
|
1930 |
$insertOrders = $db->prepare('INSERT OR REPLACE INTO [Order] (ID, Status, PaymentDate, ShipmentDate, Carrier, TrackingNumber) VALUES (?, ?, ?, ?, ?, ?)');
|
1931 |
|
@@ -1953,11 +2399,11 @@ class Codisto_Sync_Model_Sync
|
|
1953 |
$db->exec('COMMIT TRANSACTION');
|
1954 |
}
|
1955 |
|
1956 |
-
private function GetSyncDb($syncDb)
|
1957 |
{
|
1958 |
$db = new PDO('sqlite:' . $syncDb);
|
1959 |
|
1960 |
-
Mage::helper('codistosync')->prepareSqliteDatabase($db);
|
1961 |
|
1962 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
1963 |
$db->exec('CREATE TABLE IF NOT EXISTS Progress(entity_id integer NOT NULL, State text NOT NULL, Sentinel integer NOT NULL PRIMARY KEY AUTOINCREMENT, CHECK(Sentinel=1))');
|
@@ -2149,7 +2595,7 @@ class Codisto_Sync_Model_Sync
|
|
2149 |
{
|
2150 |
$db = new PDO('sqlite:' . $templateDb);
|
2151 |
|
2152 |
-
Mage::helper('codistosync')->prepareSqliteDatabase($db);
|
2153 |
|
2154 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
2155 |
$db->exec('CREATE TABLE IF NOT EXISTS File(Name text NOT NULL PRIMARY KEY, Content blob NOT NULL, LastModified datetime NOT NULL, Changed bit NOT NULL DEFAULT -1)');
|
198 |
{
|
199 |
$db = new PDO('sqlite:' . $templateDb);
|
200 |
|
201 |
+
Mage::helper('codistosync')->prepareSqliteDatabase( $db, 60 );
|
202 |
|
203 |
$files = $db->prepare('SELECT Name, Content FROM File');
|
204 |
$files->execute();
|
240 |
{
|
241 |
$store = Mage::app()->getStore($storeId);
|
242 |
|
243 |
+
$db = $this->GetSyncDb($syncDb, 60 );
|
244 |
|
245 |
$insertCategory = $db->prepare('INSERT OR REPLACE INTO Category(ExternalReference, Name, ParentExternalReference, LastModified, Enabled, Sequence) VALUES(?,?,?,?,?,?)');
|
246 |
|
257 |
|
258 |
public function DeleteCategory($syncDb, $id, $storeId)
|
259 |
{
|
260 |
+
$db = $this->GetSyncDb($syncDb, 60 );
|
261 |
|
262 |
$args = array();
|
263 |
$args[] = $id;
|
276 |
{
|
277 |
$store = Mage::app()->getStore($storeId);
|
278 |
|
279 |
+
$db = $this->GetSyncDb($syncDb, 60 );
|
280 |
|
281 |
$insertCategoryProduct = $db->prepare('INSERT OR IGNORE INTO CategoryProduct(ProductExternalReference, CategoryExternalReference, Sequence) VALUES(?,?,?)');
|
282 |
$insertProduct = $db->prepare('INSERT INTO Product(ExternalReference, Type, Code, Name, Price, ListPrice, TaxClass, Description, Enabled, StockControl, StockLevel, Weight, InStore) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
397 |
|
398 |
public function DeleteProduct($syncDb, $ids, $storeId)
|
399 |
{
|
400 |
+
$db = $this->GetSyncDb($syncDb, 60 );
|
401 |
|
402 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
403 |
|
1328 |
$this->currentEntityId = $orderData['entity_id'];
|
1329 |
}
|
1330 |
|
1331 |
+
public function SyncIncrementalStores($storeId)
|
1332 |
+
{
|
1333 |
+
$helper = Mage::helper('codistosync');
|
1334 |
+
|
1335 |
+
$syncDbPath = $helper->getSyncPath('sync-'.$storeId.'.db');
|
1336 |
+
|
1337 |
+
$syncDb = null;
|
1338 |
+
|
1339 |
+
if(file_exists($syncDbPath))
|
1340 |
+
{
|
1341 |
+
$syncDb = $this->GetSyncDb($syncDbPath, 5 );
|
1342 |
+
}
|
1343 |
+
|
1344 |
+
return array( 'id' => $storeId, 'path' => $syncDbPath, 'db' => $syncDb );
|
1345 |
+
}
|
1346 |
+
|
1347 |
+
public function SyncIncremental($simpleCount, $configurableCount)
|
1348 |
+
{
|
1349 |
+
$coreResource = Mage::getSingleton('core/resource');
|
1350 |
+
$adapter = $coreResource->getConnection(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE);
|
1351 |
+
|
1352 |
+
$tablePrefix = Mage::getConfig()->getTablePrefix();
|
1353 |
+
|
1354 |
+
$storeName = $coreResource->getTableName('core/store');
|
1355 |
+
|
1356 |
+
$storeIds = array( 0 );
|
1357 |
+
|
1358 |
+
$defaultMerchantList = Mage::getStoreConfig('codisto/merchantid', 0);
|
1359 |
+
|
1360 |
+
$stores = $adapter->fetchCol('SELECT store_id FROM `'.$storeName.'`');
|
1361 |
+
|
1362 |
+
foreach($stores as $storeId)
|
1363 |
+
{
|
1364 |
+
$storeMerchantList = Mage::getStoreConfig('codisto/merchantid', $storeId);
|
1365 |
+
if($storeMerchantList && $storeMerchantList != $defaultMerchantList)
|
1366 |
+
{
|
1367 |
+
$storeIds[] = $storeId;
|
1368 |
+
}
|
1369 |
+
}
|
1370 |
+
|
1371 |
+
$stores = array_map( array($this, 'SyncIncrementalStores'), $storeIds );
|
1372 |
+
|
1373 |
+
$productUpdateEntries = $adapter->fetchPairs('SELECT product_id, stamp FROM `'.$tablePrefix.'codisto_product_change` ORDER BY product_id LIMIT '.(int)$simpleCount);
|
1374 |
+
$categoryUpdateEntries = $adapter->fetchPairs('SELECT category_id, stamp FROM `'.$tablePrefix.'codisto_category_change` ORDER BY category_id');
|
1375 |
+
$orderUpdateEntries = $adapter->fetchPairs('SELECT order_id, stamp FROM `'.$tablePrefix.'codisto_order_change` ORDER BY order_id LIMIT 1000');
|
1376 |
+
|
1377 |
+
if(empty($productUpdateEntries) &&
|
1378 |
+
empty($categoryUpdateEntries) &&
|
1379 |
+
empty($orderUpdateEntries))
|
1380 |
+
{
|
1381 |
+
return 'nochange';
|
1382 |
+
}
|
1383 |
+
|
1384 |
+
$productUpdateIds = array_keys($productUpdateEntries);
|
1385 |
+
$categoryUpdateIds = array_keys($categoryUpdateEntries);
|
1386 |
+
$orderUpdateIds = array_keys($orderUpdateEntries);
|
1387 |
+
|
1388 |
+
$coreResource = Mage::getSingleton('core/resource');
|
1389 |
+
|
1390 |
+
$catalogWebsiteName = $coreResource->getTableName('catalog/product_website');
|
1391 |
+
$storeName = $coreResource->getTableName('core/store');
|
1392 |
+
|
1393 |
+
$this->productsProcessed = array();
|
1394 |
+
$this->ordersProcessed = array();
|
1395 |
+
|
1396 |
+
foreach($stores as $store)
|
1397 |
+
{
|
1398 |
+
if($store['db'] != null)
|
1399 |
+
{
|
1400 |
+
$storeId = $store['id'];
|
1401 |
+
|
1402 |
+
if($storeId == 0)
|
1403 |
+
{
|
1404 |
+
// jump the storeid to first non admin store
|
1405 |
+
$stores = Mage::getModel('core/store')->getCollection()
|
1406 |
+
->addFieldToFilter('is_active', array('neq' => 0))
|
1407 |
+
->addFieldToFilter('store_id', array('gt' => 0))
|
1408 |
+
->setOrder('store_id', 'ASC');
|
1409 |
+
|
1410 |
+
if($stores->getSize() == 1)
|
1411 |
+
{
|
1412 |
+
$stores->setPageSize(1)->setCurPage(1);
|
1413 |
+
$firstStore = $stores->getFirstItem();
|
1414 |
+
if(is_object($firstStore) && $firstStore->getId())
|
1415 |
+
{
|
1416 |
+
$storeId = $firstStore->getId();
|
1417 |
+
}
|
1418 |
+
}
|
1419 |
+
}
|
1420 |
+
|
1421 |
+
$storeObject = Mage::app()->getStore($storeId);
|
1422 |
+
|
1423 |
+
Mage::app()->setCurrentStore($storeObject);
|
1424 |
+
|
1425 |
+
$db = $store['db'];
|
1426 |
+
|
1427 |
+
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
1428 |
+
|
1429 |
+
if(!empty($productUpdateIds))
|
1430 |
+
{
|
1431 |
+
$db->exec(
|
1432 |
+
'DELETE FROM Product WHERE ExternalReference IN ('.implode(',', $productUpdateIds).');'.
|
1433 |
+
'DELETE FROM ProductImage WHERE ProductExternalReference IN ('.implode(',', $productUpdateIds).');'.
|
1434 |
+
'DELETE FROM ProductHTML WHERE ProductExternalReference IN ('.implode(',', $productUpdateIds).');'.
|
1435 |
+
'DELETE FROM SKULink WHERE ProductExternalReference IN ('.implode(',', $productUpdateIds).');'.
|
1436 |
+
'DELETE FROM SKUMatrix WHERE ProductExternalReference IN ('.implode(',', $productUpdateIds).');'.
|
1437 |
+
'DELETE FROM SKU WHERE ProductExternalReference IN ('.implode(',', $productUpdateIds).');'.
|
1438 |
+
'DELETE FROM CategoryProduct WHERE ProductExternalReference IN ('.implode(',', $productUpdateIds).')'
|
1439 |
+
);
|
1440 |
+
|
1441 |
+
$insertCategoryProduct = $db->prepare('INSERT OR IGNORE INTO CategoryProduct(ProductExternalReference, CategoryExternalReference, Sequence) VALUES(?,?,?)');
|
1442 |
+
$insertProduct = $db->prepare('INSERT INTO Product(ExternalReference, Type, Code, Name, Price, ListPrice, TaxClass, Description, Enabled, StockControl, StockLevel, Weight, InStore) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
1443 |
+
$checkProduct = $db->prepare('SELECT CASE WHEN EXISTS(SELECT 1 FROM Product WHERE ExternalReference = ?) THEN 1 ELSE 0 END');
|
1444 |
+
$insertSKU = $db->prepare('INSERT OR IGNORE INTO SKU(ExternalReference, Code, ProductExternalReference, Name, StockControl, StockLevel, Price, Enabled, InStore) VALUES(?,?,?,?,?,?,?,?,?)');
|
1445 |
+
$insertSKULink = $db->prepare('INSERT OR REPLACE INTO SKULink (SKUExternalReference, ProductExternalReference, Price) VALUES (?, ?, ?)');
|
1446 |
+
$insertSKUMatrix = $db->prepare('INSERT INTO SKUMatrix(SKUExternalReference, ProductExternalReference, Code, OptionName, OptionValue, ProductOptionExternalReference, ProductOptionValueExternalReference) VALUES(?,?,?,?,?,?,?)');
|
1447 |
+
$insertImage = $db->prepare('INSERT INTO ProductImage(ProductExternalReference, URL, Tag, Sequence, Enabled) VALUES(?,?,?,?,?)');
|
1448 |
+
$insertProductOptionValue = $db->prepare('INSERT INTO ProductOptionValue (ExternalReference, Sequence) VALUES (?,?)');
|
1449 |
+
$insertProductHTML = $db->prepare('INSERT OR IGNORE INTO ProductHTML(ProductExternalReference, Tag, HTML) VALUES (?, ?, ?)');
|
1450 |
+
$clearAttribute = $db->prepare('DELETE FROM ProductAttributeValue WHERE ProductExternalReference = ?');
|
1451 |
+
$insertAttribute = $db->prepare('INSERT OR REPLACE INTO Attribute(ID, Code, Label, Type, Input) VALUES (?, ?, ?, ?, ?)');
|
1452 |
+
$insertAttributeGroup = $db->prepare('INSERT OR REPLACE INTO AttributeGroup(ID, Name) VALUES(?, ?)');
|
1453 |
+
$insertAttributeGroupMap = $db->prepare('INSERT OR IGNORE INTO AttributeGroupMap(GroupID, AttributeID) VALUES(?,?)');
|
1454 |
+
$insertProductAttribute = $db->prepare('INSERT OR IGNORE INTO ProductAttributeValue(ProductExternalReference, AttributeID, Value) VALUES (?, ?, ?)');
|
1455 |
+
$clearProductQuestion = $db->prepare('DELETE FROM ProductQuestionAnswer WHERE ProductQuestionExternalReference IN (SELECT ExternalReference FROM ProductQuestion WHERE ProductExternalReference = ?1); DELETE FROM ProductQuestion WHERE ProductExternalReference = ?1');
|
1456 |
+
$insertProductQuestion = $db->prepare('INSERT OR REPLACE INTO ProductQuestion(ExternalReference, ProductExternalReference, Name, Type, Sequence) VALUES (?, ?, ?, ?, ?)');
|
1457 |
+
$insertProductAnswer = $db->prepare('INSERT INTO ProductQuestionAnswer(ProductQuestionExternalReference, Value, PriceModifier, SKUModifier, Sequence) VALUES (?, ?, ?, ?, ?)');
|
1458 |
+
|
1459 |
+
// Simple Products not participating as configurable skus
|
1460 |
+
$simpleProducts = $this->getProductCollection()
|
1461 |
+
->addAttributeToSelect(array('entity_id', 'sku', 'name', 'image', 'description', 'short_description', 'price', 'special_price', 'special_from_date', 'special_to_date', 'status', 'tax_class_id', 'weight'), 'left')
|
1462 |
+
->addAttributeToFilter('type_id', array('eq' => 'simple'))
|
1463 |
+
->addAttributeToFilter('entity_id', array('in' => $productUpdateIds) );
|
1464 |
+
$simpleProducts->getSelect()
|
1465 |
+
->columns(array('codisto_in_store' => new Zend_Db_Expr('CASE WHEN `e`.entity_id IN (SELECT product_id FROM `'.$catalogWebsiteName.'` WHERE website_id IN (SELECT website_id FROM `'.$storeName.'` WHERE store_id = '.$storeId.' OR EXISTS(SELECT 1 FROM `'.$storeName.'` WHERE store_id = '.$storeId.' AND website_id = 0))) THEN -1 ELSE 0 END')));
|
1466 |
+
|
1467 |
+
Mage::getSingleton('core/resource_iterator')->walk($simpleProducts->getSelect(), array(array($this, 'SyncSimpleProductData')),
|
1468 |
+
array(
|
1469 |
+
'type' => 'simple',
|
1470 |
+
'db' => $db,
|
1471 |
+
'preparedStatement' => $insertProduct,
|
1472 |
+
'preparedcategoryproductStatement' => $insertCategoryProduct,
|
1473 |
+
'preparedimageStatement' => $insertImage,
|
1474 |
+
'preparedproducthtmlStatement' => $insertProductHTML,
|
1475 |
+
'preparedclearattributeStatement' => $clearAttribute,
|
1476 |
+
'preparedattributeStatement' => $insertAttribute,
|
1477 |
+
'preparedattributegroupStatement' => $insertAttributeGroup,
|
1478 |
+
'preparedattributegroupmapStatement' => $insertAttributeGroupMap,
|
1479 |
+
'preparedproductattributeStatement' => $insertProductAttribute,
|
1480 |
+
'preparedclearproductquestionStatement' => $clearProductQuestion,
|
1481 |
+
'preparedproductquestionStatement' => $insertProductQuestion,
|
1482 |
+
'preparedproductanswerStatement' => $insertProductAnswer,
|
1483 |
+
'store' => $storeObject ));
|
1484 |
+
|
1485 |
+
// Configurable products
|
1486 |
+
$configurableProducts = $this->getProductCollection()
|
1487 |
+
->addAttributeToSelect(array('entity_id', 'sku', 'name', 'image', 'description', 'short_description', 'price', 'special_price', 'special_from_date', 'special_to_date', 'status', 'tax_class_id', 'weight'), 'left')
|
1488 |
+
->addAttributeToFilter('type_id', array('eq' => 'configurable'))
|
1489 |
+
->addAttributeToFilter('entity_id', array('in' => $productUpdateIds));
|
1490 |
+
$configurableProducts->getSelect()
|
1491 |
+
->columns(array('codisto_in_store' => new Zend_Db_Expr('CASE WHEN `e`.entity_id IN (SELECT product_id FROM `'.$catalogWebsiteName.'` WHERE website_id IN (SELECT website_id FROM `'.$storeName.'` WHERE store_id = '.$storeId.' OR EXISTS(SELECT 1 FROM `'.$storeName.'` WHERE store_id = '.$storeId.' AND website_id = 0))) THEN -1 ELSE 0 END')));
|
1492 |
+
|
1493 |
+
Mage::getSingleton('core/resource_iterator')->walk($configurableProducts->getSelect(), array(array($this, 'SyncConfigurableProductData')),
|
1494 |
+
array(
|
1495 |
+
'type' => 'configurable',
|
1496 |
+
'db' => $db,
|
1497 |
+
'preparedStatement' => $insertProduct,
|
1498 |
+
'preparedskuStatement' => $insertSKU,
|
1499 |
+
'preparedskulinkStatement' => $insertSKULink,
|
1500 |
+
'preparedskumatrixStatement' => $insertSKUMatrix,
|
1501 |
+
'preparedcategoryproductStatement' => $insertCategoryProduct,
|
1502 |
+
'preparedimageStatement' => $insertImage,
|
1503 |
+
'preparedproducthtmlStatement' => $insertProductHTML,
|
1504 |
+
'preparedclearattributeStatement' => $clearAttribute,
|
1505 |
+
'preparedattributeStatement' => $insertAttribute,
|
1506 |
+
'preparedattributegroupStatement' => $insertAttributeGroup,
|
1507 |
+
'preparedattributegroupmapStatement' => $insertAttributeGroupMap,
|
1508 |
+
'preparedproductattributeStatement' => $insertProductAttribute,
|
1509 |
+
'preparedclearproductquestionStatement' => $clearProductQuestion,
|
1510 |
+
'preparedproductquestionStatement' => $insertProductQuestion,
|
1511 |
+
'preparedproductanswerStatement' => $insertProductAnswer,
|
1512 |
+
'store' => $storeObject )
|
1513 |
+
);
|
1514 |
+
|
1515 |
+
// Grouped products
|
1516 |
+
$groupedProducts = $this->getProductCollection()
|
1517 |
+
->addAttributeToSelect(array('entity_id', 'sku', 'name', 'image', 'description', 'short_description', 'price', 'special_price', 'special_from_date', 'special_to_date', 'status', 'tax_class_id', 'weight'), 'left')
|
1518 |
+
->addAttributeToFilter('type_id', array('eq' => 'grouped'))
|
1519 |
+
->addAttributeToFilter('entity_id', array('in' => $productUpdateIds ));
|
1520 |
+
|
1521 |
+
$groupedProducts->getSelect()
|
1522 |
+
->columns(array('codisto_in_store' => new Zend_Db_Expr('CASE WHEN `e`.entity_id IN (SELECT product_id FROM `'.$catalogWebsiteName.'` WHERE website_id IN (SELECT website_id FROM `'.$storeName.'` WHERE store_id = '.$storeId.' OR EXISTS(SELECT 1 FROM `'.$storeName.'` WHERE store_id = '.$storeId.' AND website_id = 0))) THEN -1 ELSE 0 END')));
|
1523 |
+
|
1524 |
+
Mage::getSingleton('core/resource_iterator')->walk($groupedProducts->getSelect(), array(array($this, 'SyncGroupedProductData')),
|
1525 |
+
array(
|
1526 |
+
'type' => 'grouped',
|
1527 |
+
'db' => $db,
|
1528 |
+
'preparedStatement' => $insertProduct,
|
1529 |
+
'preparedskuStatement' => $insertSKU,
|
1530 |
+
'preparedskulinkStatement' => $insertSKULink,
|
1531 |
+
'preparedskumatrixStatement' => $insertSKUMatrix,
|
1532 |
+
'preparedcategoryproductStatement' => $insertCategoryProduct,
|
1533 |
+
'preparedimageStatement' => $insertImage,
|
1534 |
+
'preparedproducthtmlStatement' => $insertProductHTML,
|
1535 |
+
'preparedclearattributeStatement' => $clearAttribute,
|
1536 |
+
'preparedattributeStatement' => $insertAttribute,
|
1537 |
+
'preparedattributegroupStatement' => $insertAttributeGroup,
|
1538 |
+
'preparedattributegroupmapStatement' => $insertAttributeGroupMap,
|
1539 |
+
'preparedproductattributeStatement' => $insertProductAttribute,
|
1540 |
+
'preparedclearproductquestionStatement' => $clearProductQuestion,
|
1541 |
+
'preparedproductquestionStatement' => $insertProductQuestion,
|
1542 |
+
'preparedproductanswerStatement' => $insertProductAnswer,
|
1543 |
+
'store' => $storeObject )
|
1544 |
+
);
|
1545 |
+
}
|
1546 |
+
|
1547 |
+
if(!empty($categoryUpdateIds))
|
1548 |
+
{
|
1549 |
+
$insertCategory = $db->prepare('INSERT OR REPLACE INTO Category(ExternalReference, Name, ParentExternalReference, LastModified, Enabled, Sequence) VALUES(?,?,?,?,?,?)');
|
1550 |
+
|
1551 |
+
// Categories
|
1552 |
+
$categories = Mage::getModel('catalog/category', array('disable_flat' => true))->getCollection()
|
1553 |
+
->addAttributeToSelect(array('name', 'image', 'is_active', 'updated_at', 'parent_id', 'position'), 'left')
|
1554 |
+
->addAttributeToFilter('entity_id', array('in' => $categoryUpdateIds ));
|
1555 |
+
|
1556 |
+
Mage::getSingleton('core/resource_iterator')->walk($categories->getSelect(), array(array($this, 'SyncCategoryData')), array( 'db' => $db, 'preparedStatement' => $insertCategory, 'store' => $storeObject ));
|
1557 |
+
}
|
1558 |
+
|
1559 |
+
if(!empty($orderUpdateIds))
|
1560 |
+
{
|
1561 |
+
$insertOrders = $db->prepare('INSERT OR REPLACE INTO [Order] (ID, Status, PaymentDate, ShipmentDate, Carrier, TrackingNumber) VALUES (?, ?, ?, ?, ?, ?)');
|
1562 |
+
|
1563 |
+
$orderStoreId = $storeId;
|
1564 |
+
if($storeId == 0)
|
1565 |
+
{
|
1566 |
+
$firstStore = Mage::getModel('core/store')->getCollection()
|
1567 |
+
->addFieldToFilter('is_active', array('neq' => 0))
|
1568 |
+
->addFieldToFilter('store_id', array( 'gt' => 0))
|
1569 |
+
->setOrder('store_id', 'ASC');
|
1570 |
+
$firstStore->setPageSize(1)->setCurPage(1);
|
1571 |
+
$orderStoreId = $firstStore->getFirstItem()->getId();
|
1572 |
+
}
|
1573 |
+
|
1574 |
+
$invoiceName = $coreResource->getTableName('sales/invoice');
|
1575 |
+
$shipmentName = $coreResource->getTableName('sales/shipment');
|
1576 |
+
$shipmentTrackName = $coreResource->getTableName('sales/shipment_track');
|
1577 |
+
|
1578 |
+
$ts = Mage::getModel('core/date')->gmtTimestamp();
|
1579 |
+
$ts -= 7776000; // 90 days
|
1580 |
+
|
1581 |
+
$orders = Mage::getModel('sales/order')->getCollection()
|
1582 |
+
->addFieldToSelect(array('codisto_orderid', 'status'))
|
1583 |
+
->addAttributeToFilter('entity_id', array('in' => $orderUpdateIds ))
|
1584 |
+
->addAttributeToFilter('main_table.store_id', array('eq' => $orderStoreId ))
|
1585 |
+
->addAttributeToFilter('main_table.updated_at', array('gteq' => date('Y-m-d H:i:s', $ts)))
|
1586 |
+
->addAttributeToFilter('main_table.codisto_orderid', array('notnull' => true));
|
1587 |
+
$orders->getSelect()->joinLeft( array('i' => $invoiceName), 'i.order_id = main_table.entity_id AND i.state = 2', array('pay_date' => 'MIN(i.created_at)'));
|
1588 |
+
$orders->getSelect()->joinLeft( array('s' => $shipmentName), 's.order_id = main_table.entity_id', array('ship_date' => 'MIN(s.created_at)'));
|
1589 |
+
$orders->getSelect()->joinLeft( array('t' => $shipmentTrackName), 't.order_id = main_table.entity_id', array('carrier' => 'GROUP_CONCAT(COALESCE(t.title, \'\') SEPARATOR \',\')', 'track_number' => 'GROUP_CONCAT(COALESCE(t.track_number, \'\') SEPARATOR \',\')'));
|
1590 |
+
$orders->getSelect()->group(array('main_table.entity_id', 'main_table.codisto_orderid', 'main_table.status'));
|
1591 |
+
$orders->setOrder('entity_id', 'ASC');
|
1592 |
+
|
1593 |
+
Mage::getSingleton('core/resource_iterator')->walk($orders->getSelect(), array(array($this, 'SyncOrderData')),
|
1594 |
+
array(
|
1595 |
+
'db' => $db,
|
1596 |
+
'preparedStatement' => $insertOrders,
|
1597 |
+
'store' => $storeObject )
|
1598 |
+
);
|
1599 |
+
}
|
1600 |
+
|
1601 |
+
$uniqueId = uniqid();
|
1602 |
+
|
1603 |
+
$adapter->beginTransaction();
|
1604 |
+
try
|
1605 |
+
{
|
1606 |
+
$adapter->query('REPLACE INTO `'.$tablePrefix.'codisto_sync` ( store_id, token ) VALUES ('.$storeId.', \''.$uniqueId.'\')');
|
1607 |
+
}
|
1608 |
+
catch(Exception $e)
|
1609 |
+
{
|
1610 |
+
$adapter->query('CREATE TABLE `'.$tablePrefix.'codisto_sync` (store_id smallint(5) unsigned PRIMARY KEY NOT NULL, token varchar(20) NOT NULL)');
|
1611 |
+
$adapter->insert($tablePrefix.'codisto_sync', array( 'token' => $uniqueId, 'store_id' => $storeId ));
|
1612 |
+
}
|
1613 |
+
$adapter->commit();
|
1614 |
+
|
1615 |
+
$db->exec('CREATE TABLE IF NOT EXISTS Sync (token text NOT NULL, sentinel NOT NULL PRIMARY KEY DEFAULT 1, CHECK(sentinel = 1))');
|
1616 |
+
$db->exec('INSERT OR REPLACE INTO Sync (token) VALUES (\''.$uniqueId.'\')');
|
1617 |
+
|
1618 |
+
if(!empty($productUpdateIds))
|
1619 |
+
{
|
1620 |
+
$db->exec('CREATE TABLE IF NOT EXISTS ProductChange (ExternalReference text NOT NULL PRIMARY KEY, stamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP)');
|
1621 |
+
foreach($productUpdateIds as $updateId)
|
1622 |
+
{
|
1623 |
+
$db->exec('INSERT OR REPLACE INTO ProductChange (ExternalReference) VALUES ('.$updateId.')');
|
1624 |
+
}
|
1625 |
+
}
|
1626 |
+
|
1627 |
+
if(!empty($categoryUpdateIds))
|
1628 |
+
{
|
1629 |
+
$db->exec('CREATE TABLE IF NOT EXISTS CategoryChange (ExternalReference text NOT NULL PRIMARY KEY, stamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP)');
|
1630 |
+
foreach($categoryUpdateIds as $updateId)
|
1631 |
+
{
|
1632 |
+
$db->exec('INSERT OR REPLACE INTO CategoryChange (ExternalReference) VALUES ('.$updateId.')');
|
1633 |
+
}
|
1634 |
+
}
|
1635 |
+
|
1636 |
+
if(!empty($orderUpdateIds))
|
1637 |
+
{
|
1638 |
+
$db->exec('CREATE TABLE IF NOT EXISTS OrderChange (ExternalReference text NOT NULL PRIMARY KEY, stamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP)');
|
1639 |
+
foreach($orderUpdateIds as $updateId)
|
1640 |
+
{
|
1641 |
+
$db->exec('INSERT OR REPLACE INTO OrderChange (ExternalReference) VALUES ('.$updateId.')');
|
1642 |
+
}
|
1643 |
+
}
|
1644 |
+
|
1645 |
+
$db->exec('COMMIT TRANSACTION');
|
1646 |
+
}
|
1647 |
+
}
|
1648 |
+
|
1649 |
+
if(!empty($productUpdateEntries))
|
1650 |
+
{
|
1651 |
+
$adapter->query('CREATE TEMPORARY TABLE tmp_codisto_change (product_id int(10) unsigned, stamp datetime)');
|
1652 |
+
foreach($productUpdateEntries as $product_id => $stamp)
|
1653 |
+
{
|
1654 |
+
$adapter->insert('tmp_codisto_change', array( 'product_id' => $product_id, 'stamp' => $stamp ) );
|
1655 |
+
}
|
1656 |
+
$adapter->query('DELETE FROM `'.$tablePrefix.'codisto_product_change` '.
|
1657 |
+
'WHERE EXISTS ('.
|
1658 |
+
'SELECT 1 FROM tmp_codisto_change '.
|
1659 |
+
'WHERE product_id = `'.$tablePrefix.'codisto_product_change`.product_id AND '.
|
1660 |
+
'stamp = `'.$tablePrefix.'codisto_product_change`.stamp'.
|
1661 |
+
')');
|
1662 |
+
$adapter->query('DROP TABLE tmp_codisto_change');
|
1663 |
+
}
|
1664 |
+
|
1665 |
+
if(!empty($categoryUpdateEntries))
|
1666 |
+
{
|
1667 |
+
$adapter->query('CREATE TEMPORARY TABLE tmp_codisto_change (category_id int(10) unsigned, stamp datetime)');
|
1668 |
+
foreach($categoryUpdateEntries as $category_id => $stamp)
|
1669 |
+
{
|
1670 |
+
$adapter->insert('tmp_codisto_change', array( 'category_id' => $category_id, 'stamp' => $stamp ) );
|
1671 |
+
}
|
1672 |
+
$adapter->query('DELETE FROM `'.$tablePrefix.'codisto_category_change` '.
|
1673 |
+
'WHERE EXISTS ('.
|
1674 |
+
'SELECT 1 FROM tmp_codisto_change '.
|
1675 |
+
'WHERE category_id = `'.$tablePrefix.'codisto_category_change`.category_id AND '.
|
1676 |
+
'stamp = `'.$tablePrefix.'codisto_category_change`.stamp'.
|
1677 |
+
')');
|
1678 |
+
$adapter->query('DROP TABLE tmp_codisto_change');
|
1679 |
+
}
|
1680 |
+
|
1681 |
+
if(!empty($orderUpdateEntries))
|
1682 |
+
{
|
1683 |
+
$adapter->query('CREATE TEMPORARY TABLE tmp_codisto_change (order_id int(10) unsigned, stamp datetime)');
|
1684 |
+
foreach($orderUpdateEntries as $order_id => $stamp)
|
1685 |
+
{
|
1686 |
+
$adapter->insert('tmp_codisto_change', array( 'order_id' => $order_id, 'stamp' => $stamp ) );
|
1687 |
+
}
|
1688 |
+
$adapter->query('DELETE FROM `'.$tablePrefix.'codisto_order_change` '.
|
1689 |
+
'WHERE EXISTS ('.
|
1690 |
+
'SELECT 1 FROM tmp_codisto_change '.
|
1691 |
+
'WHERE order_id = `'.$tablePrefix.'codisto_order_change`.order_id AND '.
|
1692 |
+
'stamp = `'.$tablePrefix.'codisto_order_change`.stamp'.
|
1693 |
+
')');
|
1694 |
+
$adapter->query('DROP TABLE tmp_codisto_change');
|
1695 |
+
}
|
1696 |
+
|
1697 |
+
return $adapter->fetchOne('SELECT CASE WHEN '.
|
1698 |
+
'EXISTS(SELECT 1 FROM `'.$tablePrefix.'codisto_product_change`) OR '.
|
1699 |
+
'EXISTS(SELECT 1 FROM `'.$tablePrefix.'codisto_category_change`) OR '.
|
1700 |
+
'EXISTS(SELECT 1 FROM `'.$tablePrefix.'codisto_order_change`) '.
|
1701 |
+
'THEN \'pending\' ELSE \'complete\' END');
|
1702 |
+
}
|
1703 |
+
|
1704 |
+
public function SyncChangeComplete($syncDb, $changeDb, $storeId)
|
1705 |
+
{
|
1706 |
+
$db = $this->GetSyncDb($syncDb, 5 );
|
1707 |
+
|
1708 |
+
$db->exec('ATTACH DATABASE \''.$changeDb.'\' AS ChangeDb');
|
1709 |
+
|
1710 |
+
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
1711 |
+
|
1712 |
+
$qry = $db->query('SELECT CASE WHEN '.
|
1713 |
+
'EXISTS(SELECT 1 FROM sqlite_master WHERE type COLLATE NOCASE = \'TABLE\' AND name = \'ProductChange\') AND '.
|
1714 |
+
'EXISTS(SELECT 1 FROM ChangeDb.sqlite_master WHERE type COLLATE NOCASE = \'TABLE\' AND name = \'ProductChangeProcessed\') '.
|
1715 |
+
'THEN -1 ELSE 0 END');
|
1716 |
+
$processProductChange = $qry->fetchColumn();
|
1717 |
+
$qry->closeCursor();
|
1718 |
+
|
1719 |
+
$qry = $db->query('SELECT CASE WHEN '.
|
1720 |
+
'EXISTS(SELECT 1 FROM sqlite_master WHERE type COLLATE NOCASE = \'TABLE\' AND name = \'CategoryChange\') AND '.
|
1721 |
+
'EXISTS(SELECT 1 FROM ChangeDb.sqlite_master WHERE type COLLATE NOCASE = \'TABLE\' AND name = \'CategoryChangeProcessed\') '.
|
1722 |
+
'THEN -1 ELSE 0 END');
|
1723 |
+
$processCategoryChange = $qry->fetchColumn();
|
1724 |
+
$qry->closeCursor();
|
1725 |
+
|
1726 |
+
$qry = $db->query('SELECT CASE WHEN '.
|
1727 |
+
'EXISTS(SELECT 1 FROM sqlite_master WHERE type COLLATE NOCASE = \'TABLE\' AND name = \'OrderChange\') AND '.
|
1728 |
+
'EXISTS(SELECT 1 FROM ChangeDb.sqlite_master WHERE type COLLATE NOCASE = \'TABLE\' AND name = \'OrderChangeProcessed\') '.
|
1729 |
+
'THEN -1 ELSE 0 END');
|
1730 |
+
$processOrderChange = $qry->fetchColumn();
|
1731 |
+
$qry->closeCursor();
|
1732 |
+
|
1733 |
+
if($processProductChange)
|
1734 |
+
{
|
1735 |
+
$db->exec('DELETE FROM ProductChange '.
|
1736 |
+
'WHERE EXISTS('.
|
1737 |
+
'SELECT 1 FROM ProductChangeProcessed '.
|
1738 |
+
'WHERE ExternalReference = ProductChange.ExternalReference AND '.
|
1739 |
+
'stamp = ProductChange.stamp'.
|
1740 |
+
')');
|
1741 |
+
}
|
1742 |
+
|
1743 |
+
if($processCategoryChange)
|
1744 |
+
{
|
1745 |
+
$db->exec('DELETE FROM CategoryChange '.
|
1746 |
+
'WHERE EXISTS('.
|
1747 |
+
'SELECT 1 FROM CategoryChangeProcessed '.
|
1748 |
+
'WHERE ExternalReference = CategoryChange.ExternalReference AND '.
|
1749 |
+
'stamp = CategoryChange.stamp'.
|
1750 |
+
')');
|
1751 |
+
}
|
1752 |
+
|
1753 |
+
if($processOrderChange)
|
1754 |
+
{
|
1755 |
+
$db->exec('DELETE FROM OrderChange '.
|
1756 |
+
'WHERE EXISTS('.
|
1757 |
+
'SELECT 1 FROM OrderChangeProcessed '.
|
1758 |
+
'WHERE ExternalReference = OrderChange.ExternalReference AND '.
|
1759 |
+
'stamp = OrderChange.stamp'.
|
1760 |
+
')');
|
1761 |
+
}
|
1762 |
+
|
1763 |
+
$db->exec('COMMIT');
|
1764 |
+
}
|
1765 |
+
|
1766 |
public function SyncChunk($syncDb, $simpleCount, $configurableCount, $storeId, $first)
|
1767 |
{
|
1768 |
$store = Mage::app()->getStore($storeId);
|
1769 |
|
1770 |
+
$db = $this->GetSyncDb($syncDb, 5 );
|
1771 |
|
1772 |
$insertCategory = $db->prepare('INSERT OR REPLACE INTO Category(ExternalReference, Name, ParentExternalReference, LastModified, Enabled, Sequence) VALUES(?,?,?,?,?,?)');
|
1773 |
$insertCategoryProduct = $db->prepare('INSERT OR IGNORE INTO CategoryProduct(ProductExternalReference, CategoryExternalReference, Sequence) VALUES(?,?,?)');
|
2111 |
$db->exec('INSERT OR REPLACE INTO Progress (Sentinel, State, entity_id) VALUES (1, \'complete\', 0)');
|
2112 |
}
|
2113 |
|
|
|
|
|
2114 |
if((empty($this->productsProcessed) && empty($this->ordersProcessed)) || $first)
|
2115 |
{
|
2116 |
+
$uniqueId = uniqid();
|
2117 |
+
|
2118 |
+
$adapter = $coreResource->getConnection(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE);
|
2119 |
+
|
2120 |
+
$adapter->query('CREATE TABLE IF NOT EXISTS `'.$tablePrefix.'codisto_sync` (store_id smallint(5) unsigned PRIMARY KEY NOT NULL, token varchar(20) NOT NULL)');
|
2121 |
+
$adapter->query('REPLACE INTO `'.$tablePrefix.'codisto_sync` ( store_id, token ) VALUES ('.$storeId.', \''.$uniqueId.'\')');
|
2122 |
+
|
2123 |
+
$db->exec('CREATE TABLE IF NOT EXISTS Sync (token text NOT NULL, sentinel NOT NULL PRIMARY KEY DEFAULT 1, CHECK(sentinel = 1))');
|
2124 |
+
$db->exec('INSERT OR REPLACE INTO Sync (token) VALUES (\''.$uniqueId.'\')');
|
2125 |
+
$db->exec('COMMIT TRANSACTION');
|
2126 |
+
|
2127 |
return 'complete';
|
2128 |
}
|
2129 |
else
|
2130 |
{
|
2131 |
+
$db->exec('COMMIT TRANSACTION');
|
2132 |
+
|
2133 |
return 'pending';
|
2134 |
}
|
2135 |
}
|
2155 |
|
2156 |
public function SyncStaticBlocks($syncDb, $storeId)
|
2157 |
{
|
2158 |
+
$db = $this->GetSyncDb($syncDb, 5 );
|
2159 |
|
2160 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
2161 |
|
2184 |
|
2185 |
public function SyncTax($syncDb, $storeId)
|
2186 |
{
|
2187 |
+
$db = $this->GetSyncDb($syncDb, 5 );
|
2188 |
|
2189 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
2190 |
|
2306 |
|
2307 |
public function SyncStores($syncDb, $storeId)
|
2308 |
{
|
2309 |
+
$db = $this->GetSyncDb($syncDb, 5 );
|
2310 |
|
2311 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
2312 |
$db->exec('DELETE FROM Store');
|
2371 |
{
|
2372 |
$store = Mage::app()->getStore($storeId);
|
2373 |
|
2374 |
+
$db = $this->GetSyncDb($syncDb, 5 );
|
2375 |
|
2376 |
$insertOrders = $db->prepare('INSERT OR REPLACE INTO [Order] (ID, Status, PaymentDate, ShipmentDate, Carrier, TrackingNumber) VALUES (?, ?, ?, ?, ?, ?)');
|
2377 |
|
2399 |
$db->exec('COMMIT TRANSACTION');
|
2400 |
}
|
2401 |
|
2402 |
+
private function GetSyncDb($syncDb, $timeout = 60)
|
2403 |
{
|
2404 |
$db = new PDO('sqlite:' . $syncDb);
|
2405 |
|
2406 |
+
Mage::helper('codistosync')->prepareSqliteDatabase( $db, $timeout );
|
2407 |
|
2408 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
2409 |
$db->exec('CREATE TABLE IF NOT EXISTS Progress(entity_id integer NOT NULL, State text NOT NULL, Sentinel integer NOT NULL PRIMARY KEY AUTOINCREMENT, CHECK(Sentinel=1))');
|
2595 |
{
|
2596 |
$db = new PDO('sqlite:' . $templateDb);
|
2597 |
|
2598 |
+
Mage::helper('codistosync')->prepareSqliteDatabase( $db, 60 );
|
2599 |
|
2600 |
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
2601 |
$db->exec('CREATE TABLE IF NOT EXISTS File(Name text NOT NULL PRIMARY KEY, Content blob NOT NULL, LastModified datetime NOT NULL, Changed bit NOT NULL DEFAULT -1)');
|
app/code/community/Codisto/Sync/controllers/IndexController.php
CHANGED
@@ -565,9 +565,10 @@ class Codisto_Sync_IndexController extends Mage_Core_Controller_Front_Action
|
|
565 |
$order->setCustomer($quote->getCustomer());
|
566 |
$order->setCodistoOrderid($ordercontent->orderid);
|
567 |
|
568 |
-
if(preg_match('/\{ordernumber\}/', $ordernumberformat))
|
569 |
{
|
570 |
$incrementId = preg_replace('/\{ordernumber\}/', (string)$order->getIncrementId(), $ordernumberformat);
|
|
|
571 |
$order->setIncrementId($incrementId);
|
572 |
}
|
573 |
else
|
565 |
$order->setCustomer($quote->getCustomer());
|
566 |
$order->setCodistoOrderid($ordercontent->orderid);
|
567 |
|
568 |
+
if(preg_match('/\{ordernumber\}|\{ebaysalesrecordnumber\}/', $ordernumberformat))
|
569 |
{
|
570 |
$incrementId = preg_replace('/\{ordernumber\}/', (string)$order->getIncrementId(), $ordernumberformat);
|
571 |
+
$incrementId = preg_replace('/\{ebaysalesrecordnumber\}/', $ebaysalesrecordnumber, $incrementId);
|
572 |
$order->setIncrementId($incrementId);
|
573 |
}
|
574 |
else
|
app/code/community/Codisto/Sync/controllers/SyncController.php
CHANGED
@@ -37,7 +37,6 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
37 |
|
38 |
public function indexAction()
|
39 |
{
|
40 |
-
|
41 |
set_time_limit(0);
|
42 |
|
43 |
@ini_set('zlib.output_compression', 'Off');
|
@@ -118,7 +117,7 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
118 |
|
119 |
$db = new PDO('sqlite:' . $tmpDb);
|
120 |
|
121 |
-
$helper->prepareSqliteDatabase($db);
|
122 |
|
123 |
$db->exec('ATTACH DATABASE \''.$syncDb.'\' AS SyncDB');
|
124 |
|
@@ -191,7 +190,7 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
191 |
|
192 |
$db = new PDO('sqlite:' . $tmpDb);
|
193 |
|
194 |
-
$helper->prepareSqliteDatabase($db);
|
195 |
|
196 |
$db->exec('ATTACH DATABASE \''.$syncDb.'\' AS SyncDB');
|
197 |
|
@@ -334,14 +333,19 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
334 |
if(!$configurableCount || !is_numeric($configurableCount))
|
335 |
$configurableCount = $this->defaultConfigurableCount;
|
336 |
|
337 |
-
|
338 |
$simpleCount = (int)$request->getQuery('simplecount');
|
339 |
if(!$simpleCount || !is_numeric($simpleCount))
|
340 |
$simpleCount = $this->defaultSimpleCount;
|
341 |
|
|
|
|
|
|
|
|
|
342 |
|
343 |
-
$
|
344 |
-
|
|
|
|
|
345 |
|
346 |
if($result == 'complete')
|
347 |
{
|
@@ -352,7 +356,8 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
352 |
{
|
353 |
try
|
354 |
{
|
355 |
-
$indexer
|
|
|
356 |
break;
|
357 |
}
|
358 |
catch(Exception $e)
|
@@ -387,6 +392,15 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
387 |
}
|
388 |
die;
|
389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
case 'EXECUTECHUNK':
|
391 |
|
392 |
if($this->checkHash($helper, $server, $storeId))
|
@@ -465,7 +479,8 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
465 |
{
|
466 |
try
|
467 |
{
|
468 |
-
$indexer
|
|
|
469 |
break;
|
470 |
}
|
471 |
catch(Exception $e)
|
@@ -477,6 +492,14 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
477 |
continue;
|
478 |
}
|
479 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
480 |
}
|
481 |
|
482 |
$this->sendPlainResponse($response, 200, 'OK', $result);
|
@@ -484,8 +507,19 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
484 |
}
|
485 |
catch(Exception $e)
|
486 |
{
|
487 |
-
|
488 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
489 |
}
|
490 |
}
|
491 |
else
|
@@ -545,7 +579,7 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
545 |
|
546 |
$db = new PDO('sqlite:' . $tmpDb);
|
547 |
|
548 |
-
$helper->prepareSqliteDatabase($db);
|
549 |
|
550 |
$db->exec('ATTACH DATABASE \''.$syncDb.'\' AS SyncDB');
|
551 |
|
@@ -590,7 +624,7 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
590 |
|
591 |
$db = new PDO('sqlite:' . $tmpDb);
|
592 |
|
593 |
-
$helper->prepareSqliteDatabase($db);
|
594 |
|
595 |
$db->exec('ATTACH DATABASE \''.$syncDb.'\' AS SyncDB');
|
596 |
|
@@ -666,7 +700,7 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
666 |
|
667 |
$db = new PDO('sqlite:' . $tmpDb);
|
668 |
|
669 |
-
$helper->prepareSqliteDatabase($db);
|
670 |
|
671 |
$db->exec('ATTACH DATABASE \''.$syncDb.'\' AS SyncDB');
|
672 |
|
@@ -754,7 +788,7 @@ class Codisto_Sync_SyncController extends Mage_Core_Controller_Front_Action
|
|
754 |
|
755 |
$db = new PDO('sqlite:' . $tmpDb);
|
756 |
|
757 |
-
$helper->prepareSqliteDatabase($db,
|
758 |
|
759 |
$db->exec('ATTACH DATABASE \''.$templateDb.'\' AS Source');
|
760 |
$db->exec('CREATE TABLE File AS SELECT * FROM Source.File WHERE Changed != 0');
|
37 |
|
38 |
public function indexAction()
|
39 |
{
|
|
|
40 |
set_time_limit(0);
|
41 |
|
42 |
@ini_set('zlib.output_compression', 'Off');
|
117 |
|
118 |
$db = new PDO('sqlite:' . $tmpDb);
|
119 |
|
120 |
+
$helper->prepareSqliteDatabase($db, 60 );
|
121 |
|
122 |
$db->exec('ATTACH DATABASE \''.$syncDb.'\' AS SyncDB');
|
123 |
|
190 |
|
191 |
$db = new PDO('sqlite:' . $tmpDb);
|
192 |
|
193 |
+
$helper->prepareSqliteDatabase( $db, 60 );
|
194 |
|
195 |
$db->exec('ATTACH DATABASE \''.$syncDb.'\' AS SyncDB');
|
196 |
|
333 |
if(!$configurableCount || !is_numeric($configurableCount))
|
334 |
$configurableCount = $this->defaultConfigurableCount;
|
335 |
|
|
|
336 |
$simpleCount = (int)$request->getQuery('simplecount');
|
337 |
if(!$simpleCount || !is_numeric($simpleCount))
|
338 |
$simpleCount = $this->defaultSimpleCount;
|
339 |
|
340 |
+
if($configurableCount > 0)
|
341 |
+
{
|
342 |
+
$result = $syncObject->SyncChunk($syncDb, 0, $configurableCount, $storeId, true);
|
343 |
+
}
|
344 |
|
345 |
+
if($simpleCount > 0)
|
346 |
+
{
|
347 |
+
$result = $syncObject->SyncChunk($syncDb, $simpleCount, 0, $storeId, true);
|
348 |
+
}
|
349 |
|
350 |
if($result == 'complete')
|
351 |
{
|
356 |
{
|
357 |
try
|
358 |
{
|
359 |
+
if($indexer)
|
360 |
+
$indexer->changeStatus(Mage_Index_Model_Process::STATUS_PENDING);
|
361 |
break;
|
362 |
}
|
363 |
catch(Exception $e)
|
392 |
}
|
393 |
die;
|
394 |
|
395 |
+
case 'EXECUTEINCREMENT':
|
396 |
+
|
397 |
+
if(!$helper->getTriggerMode())
|
398 |
+
{
|
399 |
+
$this->sendPlainResponse($response, 400, 'Bad Request', 'No Action');
|
400 |
+
$response->sendResponse();
|
401 |
+
die;
|
402 |
+
}
|
403 |
+
|
404 |
case 'EXECUTECHUNK':
|
405 |
|
406 |
if($this->checkHash($helper, $server, $storeId))
|
479 |
{
|
480 |
try
|
481 |
{
|
482 |
+
if($indexer)
|
483 |
+
$indexer->changeStatus(Mage_Index_Model_Process::STATUS_PENDING);
|
484 |
break;
|
485 |
}
|
486 |
catch(Exception $e)
|
492 |
continue;
|
493 |
}
|
494 |
}
|
495 |
+
|
496 |
+
try
|
497 |
+
{
|
498 |
+
$helper->cleanSyncFolder();
|
499 |
+
}
|
500 |
+
catch(Exception $e)
|
501 |
+
{
|
502 |
+
}
|
503 |
}
|
504 |
|
505 |
$this->sendPlainResponse($response, 200, 'OK', $result);
|
507 |
}
|
508 |
catch(Exception $e)
|
509 |
{
|
510 |
+
if(property_exists($e, 'errorInfo') &&
|
511 |
+
$e->errorInfo[0] == 'HY000' &&
|
512 |
+
$e->errorInfo[1] == 5 &&
|
513 |
+
$e->errorInfo[2] == 'database is locked')
|
514 |
+
{
|
515 |
+
$this->sendPlainResponse($response, 200, 'OK', 'throttle');
|
516 |
+
$response->sendResponse();
|
517 |
+
}
|
518 |
+
else
|
519 |
+
{
|
520 |
+
$this->sendExceptionError($response, $e);
|
521 |
+
$response->sendResponse();
|
522 |
+
}
|
523 |
}
|
524 |
}
|
525 |
else
|
579 |
|
580 |
$db = new PDO('sqlite:' . $tmpDb);
|
581 |
|
582 |
+
$helper->prepareSqliteDatabase( $db, 60 );
|
583 |
|
584 |
$db->exec('ATTACH DATABASE \''.$syncDb.'\' AS SyncDB');
|
585 |
|
624 |
|
625 |
$db = new PDO('sqlite:' . $tmpDb);
|
626 |
|
627 |
+
$helper->prepareSqliteDatabase( $db, 60 );
|
628 |
|
629 |
$db->exec('ATTACH DATABASE \''.$syncDb.'\' AS SyncDB');
|
630 |
|
700 |
|
701 |
$db = new PDO('sqlite:' . $tmpDb);
|
702 |
|
703 |
+
$helper->prepareSqliteDatabase( $db, 60 );
|
704 |
|
705 |
$db->exec('ATTACH DATABASE \''.$syncDb.'\' AS SyncDB');
|
706 |
|
788 |
|
789 |
$db = new PDO('sqlite:' . $tmpDb);
|
790 |
|
791 |
+
$helper->prepareSqliteDatabase( $db, 60, 4096 );
|
792 |
|
793 |
$db->exec('ATTACH DATABASE \''.$templateDb.'\' AS Source');
|
794 |
$db->exec('CREATE TABLE File AS SELECT * FROM Source.File WHERE Changed != 0');
|
app/code/community/Codisto/Sync/data/codisto_setup/{data-install-1.90.6.php → data-install-1.90.7.php}
RENAMED
File without changes
|
app/code/community/Codisto/Sync/etc/config.xml
CHANGED
@@ -23,7 +23,7 @@
|
|
23 |
<config>
|
24 |
<modules>
|
25 |
<Codisto_Sync>
|
26 |
-
<version>1.90.
|
27 |
<depends>
|
28 |
<Mage_Payment/>
|
29 |
</depends>
|
23 |
<config>
|
24 |
<modules>
|
25 |
<Codisto_Sync>
|
26 |
+
<version>1.90.7</version>
|
27 |
<depends>
|
28 |
<Mage_Payment/>
|
29 |
</depends>
|
app/code/community/Codisto/Sync/sql/codisto_setup/{mysql4-install-1.90.6.php → mysql4-install-1.90.7.php}
RENAMED
File without changes
|
package.xml
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
-
<package><name>codistoconnect</name><version>1.90.
|
1 |
<?xml version="1.0"?>
|
2 |
+
<package><name>codistoconnect</name><version>1.90.7</version><stability>stable</stability><license>OSL-3.0</license><channel>community</channel><extends></extends><summary>Fastest, Easiest eBay listing</summary><description>CodistoConnect enables you to list on eBay in the simplest way possible with maximum performance</description><notes></notes><authors><author><name>Codisto</name><user>Codisto</user><email>hello@codisto.com</email></author></authors><date>2016-08-04</date><time>0:28:27</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="app"><dir name="design"><dir name="ebay"><file name="README" hash="8a3f3351f68ccde9f161cdbe3960392f"/></dir></dir><dir name="code"><dir name="community"><dir name="Codisto"><dir name="Sync"><dir name="Helper"><file name="CmsContent.php" hash="f00b4523d681c60c660089d0de0f2e03"/><file name="Data.php" hash="e5db211cdecaace51453f276e3e27268"/><file name="Signal.php" hash="b624f962056ceffae9c3160ed3e5655e"/></dir><dir name="controllers"><file name="CodistoController.php" hash="4992c5f9d6d2f7422f409f0321b0e455"/><file name="IndexController.php" hash="4c0eed777c4959cd500c3e034b46ef75"/><file name="SyncController.php" hash="f859203597e4f49e9107f77a6ce40d7f"/></dir><dir name="Controller"><file name="Router.php" hash="6e5ab9b0012590acf986459b5acec54c"/></dir><dir name="Test"><file name="README" hash="8299e52f9198536ff5fd3fb42f4a29d8"/><dir name="Config"><file name="AdminHtml.php" hash="6ee6404e52ed6376ad41b7556f265c32"/><file name="Config.php" hash="2e9023fcbab484d03936394934f44f13"/><dir name="Config"><dir name="expectations"><file name="testCodistoCoreConfig.yaml" hash="4a4e07f62981139ff6eb8a63420cbf0d"/></dir></dir></dir><dir name="Controllers"><file name="CodistoController.php" hash="a2be4faeac73ff1847c0d7dc4fbdc0e0"/><file name="IndexController.php" hash="f7252fae8d2f7b67397ae56524db49d1"/><file name="SyncController.php" hash="33436e4935631488073765d723a82ff7"/></dir><dir name="Controller"><file name="Router.php" hash="8afc0dca269dd0977ff6b3ac6802d0ee"/></dir><dir name="Model"><file name="Paymentmethod.php" hash="862365909073ffbba057f6f152933826"/><file name="Sync.php" hash="10a38bbb62260208a8b1529e762b7b75"/></dir></dir><dir name="sql"><dir name="codisto_setup"><file name="mysql4-install-1.90.7.php" hash="6d07d4e22ae5d907df1f4389c3a829d4"/></dir></dir><dir name="data"><dir name="codisto_setup"><file name="data-install-1.90.7.php" hash="a42cf5f15b68ac92d4c207bed8472c7d"/></dir></dir><dir name="Block"><file name="PaymentInfo.php" hash="7aa15fed37766d20d9d5a7d707aff80d"/></dir><dir name="Ebaypayment"><dir name="Model"><file name="Paymentmethod.php" hash="480787461a5b952a739f20a752bffb5d"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="4ef592c4047f610b6943758fa4fd43a6"/><file name="config.xml" hash="b707e7bbc503594a70b05dcf818a848d"/></dir><dir name="Model"><file name="Observer.php" hash="8b309ae85f2bf696e97ff6777c1d64f2"/><file name="Sync.php" hash="d1abd4ce04b7b965be1aa1c630465580"/><dir name="Indexer"><file name="Ebay.php" hash="556b1aabc7c3202f31a2e6c250e7d590"/></dir><dir name="Resource"><dir name="Mysql4"><file name="Setup.php" hash="6a6664ea18d93bcdd0f45530caa56244"/></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Codisto_Sync.xml" hash="a791bc2a9302d085eb29edf77421f525"/></dir></dir></dir></target></contents></package>
|