【问题标题】:Akeneo categories bug, I do not hope for an answer, I hope for a little clearanceAkeneo分类bug,不希望有答案,希望稍微通关
【发布时间】:2020-08-28 10:53:27
【问题描述】:

所以我遇到了这个问题,我已经从供应商自动将产品导入到 akeneo,在尝试升级代码的性能时我破坏了一些东西,现在我遇到了子类别的问题,无法从产品中访问它们,一些供应商运行良好,一些窃听。现在整整一周我都在尝试连接现在发生的事情我遇到了这个类别表

我不确定lftrgt 的列是什么意思,这不是我第一次看到它们,但从未真正弄清楚它们的作用。只是坚持也许这可以帮助我调试东西

【问题讨论】:

    标签: categories akeneo pim


    【解决方案1】:

    这是一个嵌套集模型,它是一种在关系数据库中表示嵌套集(也称为树或层次结构)的技术。

    您可以找到有关此型号的更多信息here

    【讨论】:

      【解决方案2】:

      对于遇到完全相同问题的人,由于某种原因嵌套集已完全关闭。

      在做任何事情之前,请备份您的数据库!

      在另一个帖子的帮助下:How to repair a corrupted MPTT tree (nested set) in the database using SQL?

      更改了 sql 以使用 Akeneo 类别:

      将此过程添加到您的数据库中:

      DROP PROCEDURE IF EXISTS tree_recover;
      
      DELIMITER //
      
      CREATE PROCEDURE tree_recover ()
      MODIFIES SQL DATA
      BEGIN
      
          DECLARE currentId, currentParentId  CHAR(36);
          DECLARE currentLeft                 INT;
          DECLARE startId                     INT DEFAULT 1;
      
          # Determines the max size for MEMORY tables.
          SET max_heap_table_size = 1024 * 1024 * 512;
      
          START TRANSACTION;
      
          # Temporary MEMORY table to do all the heavy lifting in,
          # otherwise performance is simply abysmal.
          CREATE TABLE `tmp_tree` (
              `id`        int(36) NOT NULL,
              `parent_id` int(36),
              `lft`       int(11) unsigned,
              `rgt`      int(11)  unsigned,
              PRIMARY KEY      (`id`),
              INDEX USING HASH (`parent_id`),
              INDEX USING HASH (`lft`),
              INDEX USING HASH (`rgt`)
          ) ENGINE = MEMORY
          SELECT `id`,
                 `parent_id`,
                 `lft`,
                 `rgt`
          FROM   `pim_catalog_category`;
      
      # Leveling the playing field.
      UPDATE  `tmp_tree`
      SET     `lft`  = 0,
              `rgt` = 0;
      # Establishing starting numbers for all root elements.
      WHILE EXISTS (SELECT * FROM `tmp_tree` WHERE `parent_id` IS NULL AND `lft` = 0 AND `rgt` = 0 LIMIT 1) DO
      
      
              UPDATE `tmp_tree`
              SET    `lft`  = startId,
                     `rgt` = startId + 1
              WHERE  `parent_id` IS NULL
                AND  `lft`       = 0
                AND  `rgt`      = 0
              LIMIT  1;
      
              SET startId = startId + 2;
      
          END WHILE;
      
          # Switching the indexes for the lft/rgt columns to B-Trees to speed up the next section, which uses range queries.
          DROP INDEX `lft`  ON `tmp_tree`;
          DROP INDEX `rgt` ON `tmp_tree`;
          CREATE INDEX `lft`  USING BTREE ON `tmp_tree` (`lft`);
          CREATE INDEX `rgt` USING BTREE ON `tmp_tree` (`rgt`);
      
          # Numbering all child elements
          WHILE EXISTS (SELECT * FROM `tmp_tree` WHERE `lft` = 0 LIMIT 1) DO
      
              # Picking an unprocessed element which has a processed parent.
              SELECT     `tmp_tree`.`id`
                INTO     currentId
              FROM       `tmp_tree`
              INNER JOIN `tmp_tree` AS `parents`
                      ON `tmp_tree`.`parent_id` = `parents`.`id`
              WHERE      `tmp_tree`.`lft` = 0
                AND      `parents`.`lft`  <> 0
              LIMIT      1;
      
              # Finding the element's parent.
              SELECT  `parent_id`
                INTO  currentParentId
              FROM    `tmp_tree`
              WHERE   `id` = currentId;
      
              # Finding the parent's lft value.
              SELECT  `lft`
                INTO  currentLeft
              FROM    `tmp_tree`
              WHERE   `id` = currentParentId;
      
              # Shifting all elements to the right of the current element 2 to the right.
              UPDATE `tmp_tree`
              SET    `rgt` = `rgt` + 2
              WHERE  `rgt` > currentLeft;
      
              UPDATE `tmp_tree`
              SET    `lft` = `lft` + 2
              WHERE  `lft` > currentLeft;
      
              # Setting lft and rgt values for current element.
              UPDATE `tmp_tree`
              SET    `lft`  = currentLeft + 1,
                     `rgt` = currentLeft + 2
              WHERE  `id`   = currentId;
      
          END WHILE;
      
          # Writing calculated values back to physical table.
          UPDATE `pim_catalog_category`, `tmp_tree`
          SET    `pim_catalog_category`.`lft`  = `tmp_tree`.`lft`,
                 `pim_catalog_category`.`rgt` = `tmp_tree`.`rgt`
          WHERE  `pim_catalog_category`.`id`   = `tmp_tree`.`id`;
      
          COMMIT;
      
          DROP TABLE `tmp_tree`;
      
      END//
      
      DELIMITER ;
      

      然后调用它:

      CALL tree_recover;
      

      在您的 Akeneo 数据库中

      此命令可能需要几分钟到几天的时间,具体取决于您拥有的类别数

      注意:通过执行此命令,新的 lft 和 rgt 计算值会在该过程完成后立即提交。

      【讨论】:

        猜你喜欢
        • 2010-09-09
        • 2011-06-07
        • 1970-01-01
        • 2018-11-30
        • 2013-10-13
        • 1970-01-01
        • 1970-01-01
        • 2018-12-10
        • 1970-01-01
        相关资源
        最近更新 更多