Révision 59ae487e
Ajouté par Assos Assos il y a presque 7 ans
drupal7/sites/all/modules/file_entity/file_entity.module | ||
---|---|---|
1794 | 1794 |
* access conditions are added for field values belonging to files only. |
1795 | 1795 |
*/ |
1796 | 1796 |
function file_entity_query_entity_field_access_alter(QueryAlterableInterface $query) { |
1797 |
//_file_entity_query_file_entity_access_alter($query, 'entity');
|
|
1797 |
_file_entity_query_file_entity_access_alter($query, 'entity'); |
|
1798 | 1798 |
} |
1799 | 1799 |
|
1800 | 1800 |
/** |
... | ... | |
1822 | 1822 |
|
1823 | 1823 |
$tables = $query->getTables(); |
1824 | 1824 |
$base_table = $query->getMetaData('base_table'); |
1825 |
// Do not use the base table for general entity queries unless this is |
|
1826 |
// querying the file_managed table directly. |
|
1827 |
if ($base_table && $type == 'entity' && $base_table != 'file_managed') { |
|
1828 |
$base_table = ''; |
|
1829 |
} |
|
1830 |
|
|
1825 | 1831 |
// If no base table is specified explicitly, search for one. |
1826 | 1832 |
if (!$base_table) { |
1827 | 1833 |
$fallback = ''; |
... | ... | |
1853 | 1859 |
$fallback = $table; |
1854 | 1860 |
} |
1855 | 1861 |
} |
1862 |
elseif (isset($schema['fields']['entity_id']) && isset($schema['fields']['entity_type']) && isset($schema['fields']['deleted']) && isset($schema['fields']['delta'])) { |
|
1863 |
// The table is a field data table, use it as fallback. |
|
1864 |
$base_table = $table; |
|
1865 |
} |
|
1856 | 1866 |
} |
1857 | 1867 |
} |
1858 | 1868 |
} |
... | ... | |
1863 | 1873 |
$base_table = $fallback; |
1864 | 1874 |
} |
1865 | 1875 |
else { |
1876 |
// Ignore this query as it was a general field query and no |
|
1877 |
// relationships were found to the file_managed table. |
|
1878 |
if ($type == 'entity') { |
|
1879 |
return; |
|
1880 |
} |
|
1866 | 1881 |
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.')); |
1867 | 1882 |
} |
1868 | 1883 |
} |
... | ... | |
1925 | 1940 |
} |
1926 | 1941 |
} |
1927 | 1942 |
|
1928 |
if ($subquery_conditions->count()) { |
|
1943 |
// If there is no subquery conditions, the query is likely for file usage. |
|
1944 |
// Or user can only access public files. |
|
1945 |
// If there are subquery conditions then add them to the subquery. |
|
1946 |
if ($subquery_conditions->count() >= 1) { |
|
1929 | 1947 |
$subquery->condition($subquery_conditions); |
1948 |
} |
|
1930 | 1949 |
|
1931 |
$field = 'fid';
|
|
1932 |
// Now handle entities.
|
|
1933 |
if ($type == 'entity') {
|
|
1934 |
// Set a common alias for entities.
|
|
1935 |
$base_alias = $falias;
|
|
1936 |
$field = 'entity_id';
|
|
1937 |
}
|
|
1938 |
$subquery->where("$falias.$field = fm_access.fid");
|
|
1950 |
$field = 'fid'; |
|
1951 |
// Now handle entities. |
|
1952 |
if ($type == 'entity') { |
|
1953 |
// Set a common alias for entities. |
|
1954 |
$base_alias = $falias; |
|
1955 |
$field = ($falias == 'file_managed' ? 'fid' : 'entity_id');
|
|
1956 |
} |
|
1957 |
$subquery->where("$falias.$field = fm_access.fid"); |
|
1939 | 1958 |
|
1940 |
// For an entity query, attach the subquery to entity conditions. |
|
1941 |
if ($type == 'entity') { |
|
1942 |
$file_conditions->exists($subquery); |
|
1943 |
} |
|
1944 |
// Otherwise attach it to the node query itself. |
|
1945 |
elseif ($table == 'file_managed') { |
|
1946 |
// Fix for https://drupal.org/node/2073085 |
|
1947 |
$db_or = db_or(); |
|
1948 |
$db_or->exists($subquery); |
|
1949 |
$db_or->isNull($falias . '.' . $field); |
|
1950 |
$query->condition($db_or); |
|
1951 |
} |
|
1952 |
else { |
|
1953 |
$query->exists($subquery); |
|
1954 |
} |
|
1959 |
// For an entity query, attach the subquery to entity conditions. |
|
1960 |
if ($type == 'entity') { |
|
1961 |
$file_conditions->exists($subquery); |
|
1962 |
} |
|
1963 |
// Otherwise attach it to the node query itself. |
|
1964 |
elseif ($table == 'file_managed') { |
|
1965 |
// Fix for https://drupal.org/node/2073085 |
|
1966 |
$db_or = db_or(); |
|
1967 |
$db_or->exists($subquery); |
|
1968 |
$db_or->isNull($falias . '.' . $field); |
|
1969 |
$query->condition($db_or); |
|
1970 |
} |
|
1971 |
else { |
|
1972 |
$query->exists($subquery); |
|
1955 | 1973 |
} |
1956 | 1974 |
} |
1957 | 1975 |
} |
... | ... | |
1959 | 1977 |
if ($type == 'entity' && $file_conditions->count()) { |
1960 | 1978 |
// All the file access conditions are only for field values belonging to |
1961 | 1979 |
// files. |
1962 |
$file_conditions->condition("$base_alias.entity_type", 'file'); |
|
1963 |
$or = db_or(); |
|
1964 |
$or->condition($file_conditions); |
|
1965 |
// If the field value belongs to a non-file entity type then this function |
|
1966 |
// does not do anything with it. |
|
1967 |
$or->condition("$base_alias.entity_type", 'file', '<>'); |
|
1968 |
// Add the compiled set of rules to the query. |
|
1969 |
$query->condition($or); |
|
1980 |
if ($base_alias !== 'file_managed') { |
|
1981 |
$file_conditions->condition("$base_alias.entity_type", 'file'); |
|
1982 |
$or = db_or(); |
|
1983 |
$or->condition($file_conditions); |
|
1984 |
// If the field value belongs to a non-file entity type then this function |
|
1985 |
// does not do anything with it. |
|
1986 |
$or->condition("$base_alias.entity_type", 'file', '<>'); |
|
1987 |
// Add the compiled set of rules to the query. |
|
1988 |
$query->condition($or); |
|
1989 |
} |
|
1990 |
else { |
|
1991 |
$query->condition($file_conditions); |
|
1992 |
} |
|
1970 | 1993 |
} |
1971 | 1994 |
} |
1972 | 1995 |
|
... | ... | |
2479 | 2502 |
} |
2480 | 2503 |
|
2481 | 2504 |
function file_entity_file_get_mimetype_type($file) { |
2505 |
if (is_array($file)) { |
|
2506 |
$file = (object) $file; |
|
2507 |
} |
|
2482 | 2508 |
list($type, $subtype) = explode('/', $file->filemime, 2); |
2483 | 2509 |
return $type; |
2484 | 2510 |
} |
... | ... | |
2600 | 2626 |
$pipe['variable'][] = "pathauto_file_{$file_type}_pattern"; |
2601 | 2627 |
} |
2602 | 2628 |
} |
2629 |
|
Formats disponibles : Unified diff
Weekly update of contrib modules