Example #1
0
 public function __construct(LiveCart $application, $database)
 {
     ini_set('memory_limit', '1700M');
     set_time_limit(0);
     error_reporting(E_ALL);
     ini_set('display_errors', 'On');
     Category::reindex();
     Category::recalculateProductsCount();
     $this->flush(__LINE__);
     $this->application = $application;
     $this->database = $database;
     $this->dbLogin = $this->getDBLogin();
     $this->importDatabase = $database . '_import';
     $this->flush(__LINE__);
     $this->timestamp = new ARSerializableDateTime(array_pop(array_pop(ActiveRecordModel::getDataBySQL('SELECT NOW()'))));
     $this->createSnapshot();
     $this->flush(__LINE__);
     foreach (ActiveRecordModel::getDataBySQL('SHOW TABLES IN ' . $database) as $table) {
         $table = array_shift($table);
         if (!in_array($table, self::$ignoredTables)) {
             $this->tables[] = $table;
         }
     }
     $this->flush(__LINE__);
 }
Example #2
0
 public function testCreateCategory()
 {
     Category::reindex();
     $this->root->reload();
     // Get root node info, before it is modified
     $rootLft = $this->root->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME);
     $rootRgt = $this->root->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME);
     $rootID = $this->root->getID();
     // Create new category
     $newCategory = Category::getNewInstance($this->root);
     $newCategory->setValueByLang("name", 'en', 'TEST ' . rand(1, 1000));
     $newCategory->save();
     $this->assertTrue($newCategory->isExistingRecord());
     // Check if rgt and lft fields are calculated properly
     $this->root->reload();
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), $rootRgt);
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), $rootRgt + 1);
     $this->assertEqual($this->root->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), 1);
     $this->assertEqual($this->root->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), $rootRgt + 2);
     // Check parrent id
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::PARENT_NODE_FIELD_NAME)->getID(), $rootID);
     // Reload and check again
     $this->root->reload();
     $newCategory->reload();
     // Check
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), $rootRgt);
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), $rootRgt + 1);
     $this->assertEqual($this->root->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), 1);
     $this->assertEqual($this->root->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), $rootRgt + 2);
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::PARENT_NODE_FIELD_NAME)->getID(), $rootID);
 }
Example #3
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();
 }
Example #4
0
 /**
  * Reorder category node
  *
  * @role !category.sort
  */
 public function reorder()
 {
     $targetNode = Category::getInstanceByID((int) $this->request->get("id"));
     $parentNode = Category::getInstanceByID((int) $this->request->get("parentId"));
     try {
         if ($direction = $this->request->get("direction", false)) {
             if (ActiveTreeNode::DIRECTION_LEFT == $direction) {
                 $targetNode->moveLeft(false);
             }
             if (ActiveTreeNode::DIRECTION_RIGHT == $direction) {
                 $targetNode->moveRight(false);
             }
         } else {
             $targetNode->moveTo($parentNode);
         }
         Category::reindex();
         Category::recalculateProductsCount();
         return new JSONResponse(false, 'success', $this->translate('_categories_tree_was_reordered'));
     } catch (Exception $e) {
         return new JSONResponse(false, 'failure', $this->translate('_unable_to_reorder_categories_tree'));
     }
     return new JSONResponse($status);
 }
Example #5
0
 /**
  * Reorder category node
  *
  * @role !category.sort
  */
 public function move()
 {
     $targetNode = Category::getInstanceByID((int) $this->request->get("id"));
     $parentNode = Category::getInstanceByID((int) $this->request->get("parent"));
     $next = $this->request->get("next") ? Category::getInstanceByID((int) $this->request->get("next")) : null;
     try {
         $targetNode->moveTo($parentNode, $next);
         Category::reindex();
         Category::recalculateProductsCount();
         return new JSONResponse(false, 'success', $this->translate('_categories_tree_was_reordered'));
     } catch (Exception $e) {
         return new JSONResponse(false, 'failure', $this->translate('_unable_to_reorder_categories_tree'));
     }
 }