createSqlRestrictionFromRule() public static méthode

Example: rule = ['field' => ['value'], 'other_field' => ['with_prefix*']] output = (field = "value" AND other_field LIKE "with_prefix%")
public static createSqlRestrictionFromRule ( $rule ) : string
$rule array
Résultat string
function vp_save_frequently_written_entities($rules)
{
    global $versionPressContainer;
    /**
     * @var DbSchemaInfo $dbSchemaInfo
     * @var Database $database
     * @var WpdbMirrorBridge $wpdbMirrorBridge
     * @var StorageFactory $storageFactory
     */
    $dbSchemaInfo = $versionPressContainer->resolve(VersionPressServices::DB_SCHEMA);
    $database = $versionPressContainer->resolve(VersionPressServices::DATABASE);
    $wpdbMirrorBridge = $versionPressContainer->resolve(VersionPressServices::WPDB_MIRROR_BRIDGE);
    $storageFactory = $versionPressContainer->resolve(VersionPressServices::STORAGE_FACTORY);
    foreach ($rules as $entityName => $rulesWithInterval) {
        $storageFactory->getStorage($entityName)->ignoreFrequentlyWrittenEntities = false;
        $table = $dbSchemaInfo->getPrefixedTableName($entityName);
        foreach ($rulesWithInterval as $ruleAndInterval) {
            $restriction = QueryLanguageUtils::createSqlRestrictionFromRule($ruleAndInterval['rule']);
            $sql = "SELECT * FROM {$table} WHERE {$restriction}";
            $results = $database->get_results($sql, ARRAY_A);
            foreach ($results as $data) {
                $wpdbMirrorBridge->update($table, $data, $data);
            }
        }
    }
}
 private function deleteEntitiesWhichAreNotInStorage()
 {
     if ($this->isSelectiveSynchronization) {
         $savedVpIds = array_column($this->entities, $this->entityInfo->vpidColumnName);
         $vpIdsToSynchronize = array_column($this->entitiesToSynchronize, 'vp_id');
         if ($this->entityInfo->hasNaturalVpid) {
             $sql = "SELECT `{$this->idColumnName}` FROM {$this->prefixedTableName} ";
             $sql .= sprintf("WHERE {$this->idColumnName} IN (\"%s\") ", join('", "', $vpIdsToSynchronize));
             $sql .= sprintf("AND {$this->idColumnName} NOT IN (\"%s\")", join('", "', $savedVpIds));
         } else {
             $sql = sprintf('SELECT id FROM %s WHERE `table` = "%s" ', $this->database->vp_id, $this->tableName);
             $sql .= sprintf('AND HEX(vp_id) IN ("%s") ', join('", "', $vpIdsToSynchronize));
             $sql .= sprintf('AND HEX(vp_id) NOT IN ("%s")', join('", "', $savedVpIds));
         }
         $ids = $this->database->get_col($sql);
     } else {
         $allVpids = array_column($this->entities, $this->entityInfo->vpidColumnName);
         if ($this->entityInfo->hasNaturalVpid) {
             $rules = $this->entityInfo->getRulesForIgnoredEntities();
             $restrictionForIgnoredEntities = join(' OR ', array_map(function ($rule) {
                 $restrictionPart = QueryLanguageUtils::createSqlRestrictionFromRule($rule);
                 return "({$restrictionPart})";
             }, $rules));
             $sql = "SELECT `{$this->idColumnName}` FROM {$this->prefixedTableName} WHERE NOT ({$restrictionForIgnoredEntities})";
             if (count($allVpids) > 0) {
                 $sql .= " AND `{$this->idColumnName}` NOT IN (\"" . join('", "', $allVpids) . "\")";
             }
         } else {
             $sql = "SELECT id FROM {$this->database->vp_id} WHERE `table` = \"{$this->tableName}\"" . (count($allVpids) > 0 ? "AND HEX(vp_id) NOT IN (\"" . join('", "', $allVpids) . "\")" : "");
         }
         $ids = $this->database->get_col($sql);
     }
     $this->deletedIds = $ids;
     if (count($ids) == 0) {
         return;
     }
     $idsString = join("', '", $ids);
     $this->database->query("DELETE FROM {$this->prefixedTableName} WHERE {$this->idColumnName} IN ('{$idsString}')");
     $this->database->query("DELETE FROM {$this->database->vp_id} WHERE `table` = \"{$this->tableName}\" AND id IN ('{$idsString}')");
 }
 /**
  * @test
  * @dataProvider ruleAndQueryProvider
  */
 public function queryLanguageUtilsGeneratesCorrectSqlRestriction($rule, $expectedRestriction)
 {
     $restriction = QueryLanguageUtils::createSqlRestrictionFromRule($rule);
     $this->assertEquals($expectedRestriction, $restriction);
 }