Feature #89100

Disable reference TO excluded tableName in sys_refindex

Added by Claus Harup 14 days ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Backend API
Target version:
-
Start date:
2019-09-06
Due date:
% Done:

0%

PHP Version:
7.2
Tags:
Complexity:
Sprint Focus:

Description

When adding a signal to tell RefeferenceIndex.php to exclude a given tableName:

namespace MyVendor\MyExtension\Slot;

class ReferenceIndexSlot {

   /**
    * Exclude tables from ReferenceIndex which cannot contain a reference
    *
    * @param string $tableName Name of the table
    * @param bool &$excludeTable Reference to a boolean whether to exclude the table from ReferenceIndex or not
    */
   public function shouldExcludeTableFromReferenceIndex($tableName, &$excludeTable) {
      if ($tableName === 'tx_myextension_mytable') {
         $excludeTable = true;
      }
   }

}

.... the RefeferenceIndex.php still creates sys_refindexes TO 'tx_myextension_mytable'.

Suggestion in RefeferenceIndex.php:

    ....
    foreach ($relations as &$relation) {
        if (!is_array($relation)) {
            continue;
        }

        //If a tableName is disabled from sys_refindex remove the reference TO it too

        if ($this->shouldExcludeTableFromReferenceIndex($relation['ref_table'])) {
            continue;
        }

        $relation['hash'] = md5(implode('///', $relation) . '///' . $this->hashVersion);
        // First, check if already indexed and if so, unset that row (so in the end we know which rows to remove!)
        if (isset($currentRelationHashes[$relation['hash']])) {
            unset($currentRelationHashes[$relation['hash']]);
            $result['keptNodes']++;
            $relation['_ACTION'] = 'KEPT';
        } else {
            // If new, add it:
            if (!$testOnly) {
                $connection->insert('sys_refindex', $relation);
            }
            $result['addedNodes']++;
            $relation['_ACTION'] = 'ADDED';
        }
    }
    ....

Also available in: Atom PDF