Projet

Général

Profil

Révision 082b75eb

Ajouté par Assos Assos il y a environ 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/file_entity/file_entity.module
1818 1818
 * access conditions are added for field values belonging to files only.
1819 1819
 */
1820 1820
function file_entity_query_entity_field_access_alter(QueryAlterableInterface $query) {
1821
  _file_entity_query_file_entity_access_alter($query, 'entity');
1821
  //_file_entity_query_file_entity_access_alter($query, 'entity');
1822 1822
}
1823 1823

  
1824 1824
/**
......
1856 1856

  
1857 1857
  $tables = $query->getTables();
1858 1858
  $base_table = $query->getMetaData('base_table');
1859
  // Do not use the base table for general entity queries unless this is
1860
  // querying the file_managed table directly.
1861
  if ($base_table && $type == 'entity' && $base_table != 'file_managed') {
1862
    $base_table = '';
1863
  }
1864

  
1865 1859
  // If no base table is specified explicitly, search for one.
1866 1860
  if (!$base_table) {
1867 1861
    $fallback = '';
......
1893 1887
              $fallback = $table;
1894 1888
            }
1895 1889
          }
1896
          elseif (isset($schema['fields']['entity_id']) && isset($schema['fields']['entity_type']) && isset($schema['fields']['deleted']) && isset($schema['fields']['delta'])) {
1897
            // The table is a field data table, use it as fallback.
1898
            $base_table = $table;
1899
          }
1900 1890
        }
1901 1891
      }
1902 1892
    }
......
1907 1897
        $base_table = $fallback;
1908 1898
      }
1909 1899
      else {
1910
        // Ignore this query as it was a general field query and no
1911
        // relationships were found to the file_managed table.
1912
        if ($type == 'entity') {
1913
          return;
1914
        }
1915 1900
        throw new Exception(t('Query tagged for file access but there is no fid. Add foreign keys to file_managed.fid in schema to fix.'));
1916 1901
      }
1917 1902
    }
......
1974 1959
        }
1975 1960
      }
1976 1961

  
1977
      // If there is no subquery conditions, the query is likely for file usage.
1978
      // Or user can only access public files.
1979
      // If there are subquery conditions then add them to the subquery.
1980
      if ($subquery_conditions->count() >= 1) {
1962
      if ($subquery_conditions->count()) {
1981 1963
        $subquery->condition($subquery_conditions);
1982
      }
1983 1964

  
1984
      $field = 'fid';
1985
      // Now handle entities.
1986
      if ($type == 'entity') {
1987
        // Set a common alias for entities.
1988
        $base_alias = $falias;
1989
        $field = ($falias == 'file_managed' ? 'fid' : 'entity_id');
1990
      }
1991
      $subquery->where("$falias.$field = fm_access.fid");
1965
        $field = 'fid';
1966
        // Now handle entities.
1967
        if ($type == 'entity') {
1968
          // Set a common alias for entities.
1969
          $base_alias = $falias;
1970
          $field = 'entity_id';
1971
        }
1972
        $subquery->where("$falias.$field = fm_access.fid");
1992 1973

  
1993
      // For an entity query, attach the subquery to entity conditions.
1994
      if ($type == 'entity') {
1995
        $file_conditions->exists($subquery);
1996
      }
1997
      // Otherwise attach it to the node query itself.
1998
      elseif ($table == 'file_managed') {
1999
        // Fix for https://drupal.org/node/2073085
2000
        $db_or = db_or();
2001
        $db_or->exists($subquery);
2002
        $db_or->isNull($falias . '.' . $field);
2003
        $query->condition($db_or);
2004
      }
2005
      else {
2006
        $query->exists($subquery);
1974
        // For an entity query, attach the subquery to entity conditions.
1975
        if ($type == 'entity') {
1976
          $file_conditions->exists($subquery);
1977
        }
1978
        // Otherwise attach it to the node query itself.
1979
        elseif ($table == 'file_managed') {
1980
          // Fix for https://drupal.org/node/2073085
1981
          $db_or = db_or();
1982
          $db_or->exists($subquery);
1983
          $db_or->isNull($falias . '.' . $field);
1984
          $query->condition($db_or);
1985
        }
1986
        else {
1987
          $query->exists($subquery);
1988
        }
2007 1989
      }
2008 1990
    }
2009 1991
  }
......
2011 1993
  if ($type == 'entity' && $file_conditions->count()) {
2012 1994
    // All the file access conditions are only for field values belonging to
2013 1995
    // files.
2014
    if ($base_alias !== 'file_managed') {
2015
      $file_conditions->condition("$base_alias.entity_type", 'file');
2016
      $or = db_or();
2017
      $or->condition($file_conditions);
2018
      // If the field value belongs to a non-file entity type then this function
2019
      // does not do anything with it.
2020
      $or->condition("$base_alias.entity_type", 'file', '<>');
2021
      // Add the compiled set of rules to the query.
2022
      $query->condition($or);
2023
    }
2024
    else {
2025
      $query->condition($file_conditions);
2026
    }
1996
    $file_conditions->condition("$base_alias.entity_type", 'file');
1997
    $or = db_or();
1998
    $or->condition($file_conditions);
1999
    // If the field value belongs to a non-file entity type then this function
2000
    // does not do anything with it.
2001
    $or->condition("$base_alias.entity_type", 'file', '<>');
2002
    // Add the compiled set of rules to the query.
2003
    $query->condition($or);
2027 2004
  }
2028 2005
}
2029 2006

  

Formats disponibles : Unified diff