Esempio n. 1
0
 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 setUp()
 {
     parent::setUp();
     ActiveRecordModel::executeUpdate('DELETE FROM EavField');
     ActiveRecordModel::executeUpdate('DELETE FROM EavObject');
     ActiveRecordModel::executeUpdate('DELETE FROM Manufacturer');
 }
Esempio n. 3
0
 public static function deleteByID($className, $id, $foreignKeyName)
 {
     $inst = ActiveRecordModel::getInstanceById($className, $id, ActiveRecordModel::LOAD_DATA);
     $inst->getOwner()->load();
     $inst->deleteImageFiles();
     // check if main image is being deleted
     $owner = $inst->getOwner();
     $owner->load(array(get_class($inst)));
     if ($owner->defaultImage->get()->getID() == $id) {
         // set next image (by position) as the main image
         $f = new ARSelectFilter();
         $cond = new EqualsCond(new ARFieldHandle(get_class($inst), $foreignKeyName), $owner->getID());
         $cond->addAND(new NotEqualsCond(new ARFieldHandle(get_class($inst), 'ID'), $inst->getID()));
         $f->setCondition($cond);
         $f->setOrder(new ARFieldHandle(get_class($inst), 'position'));
         $f->setLimit(1);
         $newDefaultImage = ActiveRecordModel::getRecordSet(get_class($inst), $f);
         if ($newDefaultImage->size() > 0) {
             $owner->defaultImage->set($newDefaultImage->get(0));
             $owner->save();
         }
     }
     ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=0');
     ActiveRecordModel::executeUpdate('UPDATE ' . $className . ' SET ' . $foreignKeyName . '=NULL , protectedFields="|' . $foreignKeyName . '|" WHERE ID=' . $id);
     //return parent::deleteByID($className, $id);
 }
Esempio n. 4
0
 public function tearDown()
 {
     ActiveRecordModel::executeUpdate('DROP TABLE LoadReferenceParent');
     ActiveRecordModel::executeUpdate('DROP TABLE LoadReferenceChild');
     ActiveRecordModel::executeUpdate('DROP TABLE LoadReferenceSuper');
     return parent::tearDown();
 }
Esempio n. 5
0
 public function setUp()
 {
     parent::setUp();
     $this->controller = new EavFieldController(self::getApplication());
     ActiveRecordModel::executeUpdate('DELETE FROM EavField');
     ActiveRecordModel::executeUpdate('DELETE FROM EavFieldGroup');
 }
Esempio n. 6
0
 public function setUp()
 {
     parent::setUp();
     ActiveRecordModel::executeUpdate('DELETE FROM EavField');
     $this->controller = new UserController(self::getApplication());
     $this->initOrder();
     $this->controller->setOrder($this->order);
     $this->controller->setUser($this->user);
 }
Esempio n. 7
0
 public function delete()
 {
     if (ActiveRecordModel::getApplication()->getConfig()->get('CLONE_STORE_TYPE') == 'CLONE_STORE_MASTER') {
         return parent::delete();
     } else {
         ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=0');
         ActiveRecordModel::executeUpdate('UPDATE ' . __CLASS__ . ' SET productID=NULL, variationID=NULL, protectedFields="|productID||variationID|" WHERE ID=' . $this->getID());
     }
 }
Esempio n. 8
0
 protected function initOrder()
 {
     // set up currency
     $this->setUpCurrency();
     $this->usd->decimalCount->set(2);
     $this->usd->clearRoundingRules();
     $this->usd->save();
     // initialize order
     ActiveRecordModel::executeUpdate('DELETE FROM User WHERE email="*****@*****.**"');
     $user = User::getNewInstance('*****@*****.**');
     $user->save();
     $this->user = $user;
     $address = UserAddress::getNewInstance();
     $address->countryID->set('US');
     $state = State::getInstanceById(1, State::LOAD_DATA);
     $address->state->set(State::getInstanceById(1));
     $address->postalCode->set(90210);
     $address->save();
     $billing = BillingAddress::getNewInstance($user, $address);
     $billing->save();
     $address = clone $address;
     $address->save();
     $shipping = ShippingAddress::getNewInstance($user, $address);
     $shipping->save();
     $this->order = CustomerOrder::getNewInstance($user);
     $this->order->shippingAddress->set($shipping->userAddress->get());
     $this->order->billingAddress->set($billing->userAddress->get());
     // set up products
     $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test1');
     $product->save();
     $product->setPrice('USD', 100);
     $product->stockCount->set(20);
     $product->isEnabled->set(1);
     $product->save();
     $this->products[] = $product;
     $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test2');
     $product->save();
     $product->setPrice('USD', 200);
     $product->stockCount->set(20);
     $product->isEnabled->set(1);
     $product->save();
     $this->products[] = $product;
     $product = Product::getNewInstance(Category::getInstanceById(Category::ROOT_ID), 'test3');
     $product->save();
     $product->setPrice('USD', 400);
     $product->isSeparateShipment->set(true);
     $product->stockCount->set(20);
     $product->isEnabled->set(1);
     $product->save();
     $this->products[] = $product;
 }
Esempio n. 9
0
 public static function bulkAddIndex($list)
 {
     $chunks = array();
     while ($item = array_pop($list)) {
         $locale = array_key_exists('locale', $item['meta']) ? $item['meta']['locale'] : null;
         if ($locale && strlen($locale)) {
             $locale = '0x' . bin2hex($locale);
         } else {
             $locale = 'NULL';
         }
         $chunks[] = sprintf('(%s, %s, %s, %s, %s)', '0x' . bin2hex($item['value']), $locale, array_key_exists('section', $item) ? '0x' . bin2hex($item['section']) : 'NULL', '0x' . bin2hex(serialize($item['meta'])), array_key_exists('sort', $item) && is_numeric($item['sort']) ? intval($item['sort'], 10) : 'NULL');
     }
     ActiveRecordModel::executeUpdate('INSERT INTO ' . __CLASS__ . '(value, locale, section, meta, sort) VALUES ' . implode(',', $chunks));
 }
Esempio n. 10
0
 public function setUp()
 {
     parent::setUp();
     ActiveRecordModel::executeUpdate('DELETE FROM Tax');
     ActiveRecordModel::executeUpdate('DELETE FROM TaxRate');
     ActiveRecordModel::executeUpdate('DELETE FROM Currency');
     ActiveRecordModel::executeUpdate('DELETE FROM DiscountCondition');
     ActiveRecordModel::executeUpdate('DELETE FROM DiscountAction');
     ActiveRecordModel::executeUpdate('DELETE FROM DeliveryZone');
     ActiveRecordModel::executeUpdate('DELETE FROM ShippingService');
     BusinessRuleController::clearCache();
     $this->initOrder();
     $this->config->setRuntime('DELIVERY_TAX', '');
 }
Esempio n. 11
0
 public function import()
 {
     $this->application->setDevMode(true);
     ignore_user_abort(true);
     ini_set('memory_limit', '512M');
     set_time_limit(0);
     if ($this->request->get('password') != $this->config->get('CLONE_STORE_API_KEY')) {
         return new RawResponse('Wrong password');
     }
     ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=0;');
     ActiveRecord::getLogger()->setLogFileName(null);
     $dir = $this->getFileDir();
     //if (ob_get_length())
     //{
     ob_flush();
     ob_end_clean();
     //}
     //echo str_repeat('FLUSH ', 10000);
     foreach (scandir($dir) as $file) {
         if (strlen($file) < 3) {
             continue;
         }
         $path = $dir . $file;
         if (substr($file, -4) == '.sql') {
             $f = fopen($path, 'r');
             $prev = '';
             while (!feof($f)) {
                 $s = $prev . fread($f, 1024 * 1024);
                 if (!feof($f)) {
                     $pos = strrpos($s, ";\n");
                     $prev = substr($s, $pos + 1);
                     $s = substr($s, 0, $pos);
                 }
                 Installer::loadDatabaseDump($s, true);
             }
         } else {
             $this->untar($path, ClassLoader::getRealPath('public.upload.'));
         }
         unlink($path);
     }
     $this->user->allowBackendAccess();
     $c = new ProductImageController($this->application);
     $c->resizeImages();
     Category::reindex();
     Category::recalculateProductsCount();
 }
Esempio n. 12
0
 private function getIdOffsets()
 {
     $file = $this->getOffsetsFile();
     if (!file_exists($file)) {
         $offsets = array();
         $types = $this->getRecordTypes();
         unset($types[array_search('Language', $types)]);
         unset($types[array_search('ProductRelationship', $types)]);
         foreach ($types as $type) {
             $f = new ARSelectFilter();
             $f->setOrder(new ARFieldHandle($type, 'ID'), 'DESC');
             $f->setLimit(1);
             $record = array_shift(ActiveRecordModel::getRecordSetArray($type, $f));
             if (!$record) {
                 $record['ID'] = 0;
             }
             $offsets[$type] = $record['ID'];
             try {
                 ActiveRecordModel::executeUpdate('ALTER TABLE ' . $type . ' AUTO_INCREMENT = ' . ($offsets[$type] + 1));
             } catch (Exception $e) {
                 // we don't care much if it didn't work (won't work with MySQL <5.0.3)
             }
         }
         file_put_contents($file, '<?php return ' . var_export($offsets, true) . '; ?>');
     }
     return include $file;
 }
Esempio n. 13
0
 public function tearDown()
 {
     ActiveRecordModel::executeUpdate('DROP TABLE SerializedModel');
     return parent::tearDown();
 }
Esempio n. 14
0
 public function testDoubleRatingsByIPWithTimeDifference()
 {
     $_SERVER['REMOTE_ADDR'] = '255.255.255.254';
     self::getApplication()->getConfig()->set('RATING_SAME_IP_TIME', 24);
     $this->request->set('rating_', 4);
     $this->request->set('ajax', 'true');
     // first rating
     $this->assertRatingError(false);
     ActiveRecordModel::executeUpdate('UPDATE ProductRating SET dateCreated="1997-01-01"');
     $this->assertRatingError(false);
     // vote again - get error
     $this->assertRatingError();
     // no time difference - vote as much as you want
     self::getApplication()->getConfig()->set('RATING_SAME_IP_TIME', 0);
     $this->assertRatingError(false);
 }
Esempio n. 15
0
 public function setUp()
 {
     parent::setUp();
     ActiveRecordModel::executeUpdate('DELETE FROM ProductRatingType');
 }
Esempio n. 16
0
 protected function copyDatabase($from, $to)
 {
     $this->flush(__LINE__);
     try {
         ActiveRecordModel::executeUpdate('DROP DATABASE ' . $to);
     } catch (SQLException $e) {
         var_dump($e->getMessage());
     }
     $this->flush(__LINE__);
     ActiveRecordModel::executeUpdate('CREATE DATABASE ' . $to);
     $this->flush(__LINE__);
     $dbAuth = '--user='******'user'];
     if (!empty($this->dbLogin['pass'])) {
         $dbAuth .= ' --password=\'' . $this->dbLogin['pass'] . "'";
     }
     $tmpPath = ClassLoader::getRealPath('cache.') . 'dump.sql';
     //$r = exec('mysqldump ' . $dbAuth . ' ' . $from . ' | mysql ' . $dbAuth . ' ' . $to, $a, $ret);
     exec('/bin/bash /home/galssess/www/copy.sh ' . $from . ' ' . $to, $a, $ret);
     //var_dump($a, $ret);
     /*
     $r = exec('mysqldump -v --force ' . $dbAuth . ' ' . $from . ' > ' . $tmpPath, $a, $ret);
     
     var_dump('mysqldump -v ' . $dbAuth . ' ' . $from . ' > ' . $tmpPath);
     var_dump($a);
     $this->flush(__line__);
     exec('mysql ' . $dbAuth . ' ' . $to . ' < ' . $tmpPath, $a);
     var_dump('mysql ' . $dbAuth . ' ' . $to . ' < ' . $tmpPath);
     */
     $this->flush(__LINE__);
     //		unlink($tmpPath);
     $this->flush(__LINE__);
 }
Esempio n. 17
0
 public function setUp()
 {
     parent::setUp();
     ActiveRecordModel::executeUpdate('DELETE FROM EavField');
 }