public function FancyFileDeleteOrphanFileFilter::query in Fancy File Delete 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/views/filter/FancyFileDeleteOrphanFileFilter.php \Drupal\fancy_file_delete\Plugin\views\filter\FancyFileDeleteOrphanFileFilter::query()
Add this filter to the query.
Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.
Overrides FilterPluginBase::query
File
- src/
Plugin/ views/ filter/ FancyFileDeleteOrphanFileFilter.php, line 71
Class
- FancyFileDeleteOrphanFileFilter
- Fancy File Delete Orphan Files Views Settings.
Namespace
Drupal\fancy_file_delete\Plugin\views\filterCode
public function query() {
$table = $this
->ensureMyTable();
$query = "SELECT fm.* FROM {file_managed} AS fm LEFT OUTER JOIN {file_usage}\n AS fu ON (fm.fid = fu.fid) LEFT OUTER JOIN {node} AS n ON (fu.id = n.nid)\n WHERE fu.type = 'node' AND n.nid IS NULL";
$results = $this->database
->query($query)
->fetchAll();
if (isset($results) && count($results) > 0) {
foreach ($results as $result) {
$files[] = $result->fid;
}
$this->query
->addWhere($this->options['group'], $table . '.fid', $files, 'IN');
}
else {
// No Results, return NULL, carry on.
$this->query
->addWhere($this->options['group'], $table . '.fid', NULL, '=');
}
}