public function setUp() { parent::setUp(); ActiveRecordModel::executeUpdate('DELETE FROM ClonedStore'); $this->usd = ActiveRecordModel::getNewInstance('Currency'); $this->usd->setID('ZZZ'); $this->usd->save(ActiveRecord::PERFORM_INSERT); @unlink(ClonedStoreUpdater::getTimestampFile()); @unlink(ClonedStoreUpdater::getIDFile()); // create stores for ($k = 0; $k <= 0; $k++) { $this->stores[$k] = ClonedStore::getNewInstance(); $this->stores[$k]->domain->set($k); $this->stores[$k]->save(); echo $this->stores[$k]->lastImport->get(); } // create categories $root = Category::getRootNode(); for ($k = 0; $k <= 5; $k++) { $this->categories[] = $this->createCategory($root, $k); } $this->categories['1.1'] = $this->createCategory($this->categories[1], '1.1'); $this->categories['1.2'] = $this->createCategory($this->categories[1], '1.2'); $this->categories['1.2.1'] = $this->createCategory($this->categories['1.2'], '1.2.1'); $this->categories['1.2.2'] = $this->createCategory($this->categories['1.2'], '1.2.2'); usleep(1500000); }
public function process() { if (ActiveRecordModel::getApplication()->getConfig()->get('CLONE_STORE_TYPE') == 'CLONE_STORE_MASTER') { return; } if (!ClonedStoreUpdater::isTableSynced(get_class($this->object))) { return; } $protectedFields = array(); foreach ($this->object->getSchema()->getFieldList() as $fieldName => $field) { $val = $this->object->getFieldValue($fieldName); $isModified = $this->object->getField($fieldName)->isModified(); if ($isModified && $val) { if (is_array($val)) { // empty serialized array if (!array_filter($val)) { continue; } $initial = $this->object->getField($fieldName)->getInitialValue(); if (is_array($initial)) { foreach ($val as $key => $value) { $val[$key] = strip_tags($value); } foreach ($initial as $key => $value) { $initial[$key] = strip_tags($value); } if (!array_diff($val, $initial)) { continue; } } } $protectedFields[] = $fieldName; } } if ('SpecificationStringValue' == get_class($this->object) && $this->object->value->isModified()) { $protectedFields[] = 'value'; } if (!$protectedFields) { return; } $f = new ARUpdateFilter(); foreach ($protectedFields as $key => $field) { $f->addModifier('protectedFields' . str_repeat(' ', $key), new ARExpressionHandle('IF(LOCATE("|' . $field . '|", protectedFields) > 0, protectedFields, CONCAT(COALESCE(protectedFields, ""), "|' . $field . '|"))')); } $this->object->updateFilter = $f; }
public function sync() { if ($this->config->get('CLONE_STORE_TYPE') != 'CLONE_STORE_MASTER') { return new RawResponse('Synchronization is only allowed from the master store'); } ob_clean(); ob_end_clean(); ?> <html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> window.waitForCompletion = function() { jQuery.ajax('status').always(function(data) { var res = jQuery.parseJSON(data.responseText); jQuery.each(res, function(key, value) { if (value) { jQuery('#store_' + key).removeClass('processing').addClass('done'); } }); if (!res.ready) { window.setTimeout(window.waitForCompletion, 2000); } else { jQuery('#main').removeClass('processing').addClass('done').html('Update completed!'); } }); }; </script> <style type="text/css"> .processing { padding-left: 25px; background-image: url(../public/image/indicator.gif); background-position: left center; background-repeat: no-repeat; } .done { color: green; } </style> </head> <body> <?php //echo str_repeat('<!-- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ->', 100); flush(); echo '<h2 id="main" class="processing">Initializing update</h2>'; flush(); set_time_limit(0); error_reporting(E_ALL); ini_set('display_errors', 1); $updater = new ClonedStoreUpdater($this->application, 'galssess_snapshot'); flush(); if ($id = $this->request->get('id')) { $select = select(eq(f('ClonedStore.ID'), $id)); } else { $select = select(); } if ($this->request->get('override')) { $updater->setOverride(); } $updater->syncAll($select); //echo str_repeat('<!-- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ->', 100); flush(); foreach (ActiveRecord::getRecordSet('ClonedStore', $select) as $key => $store) { echo '<h2 class="processing" id="store_' . $store->getID() . '">' . $store->domain->get() . '</h2>'; echo '<div>Uploading data</div>'; flush(); $store->pushData(); echo '<div>Starting update</div>'; $store->initUpdate(); flush(); if (2 == $key) { //break; } } ?> <script type="text/javascript"> window.waitForCompletion(); </script> </body></html> <?php }