class TemporaryFilesUsagesSensorPlugin in Monitoring 8
Monitors temporary files usages.
Plugin annotation
@SensorPlugin(
id = "temporary_files_usages",
label = @Translation("Used temporary files"),
description = @Translation("Reports temporary files that are still being used."),
addable = FALSE
)
Hierarchy
- class \Drupal\monitoring\SensorPlugin\SensorPluginBase implements SensorPluginInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\monitoring\SensorPlugin\DatabaseAggregatorSensorPluginBase
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin implements ExtendedInfoSensorPluginInterface uses DependencyTrait
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\TemporaryFilesUsagesSensorPlugin
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin implements ExtendedInfoSensorPluginInterface uses DependencyTrait
- class \Drupal\monitoring\SensorPlugin\DatabaseAggregatorSensorPluginBase
Expanded class hierarchy of TemporaryFilesUsagesSensorPlugin
File
- src/
Plugin/ monitoring/ SensorPlugin/ TemporaryFilesUsagesSensorPlugin.php, line 21
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginView source
class TemporaryFilesUsagesSensorPlugin extends DatabaseAggregatorSensorPlugin {
/**
* {@inheritdoc}
*/
protected $configurableConditions = FALSE;
/**
* {@inheritdoc}
*/
protected $configurableTable = FALSE;
/**
* {@inheritdoc}
*/
protected $configurableVerboseOutput = FALSE;
/**
* {@inheritdoc}
*/
protected function getQuery() {
$query = parent::getQuery();
$query
->innerJoin('file_usage', 'fu', 'fu.fid = file_managed.fid');
$query
->groupBy('file_managed.fid');
return $query;
}
/**
* {@inheritdoc}
*/
protected function getAggregateQuery() {
$query = parent::getAggregateQuery();
$query
->innerJoin('file_usage', 'fu', 'fu.fid = file_managed.fid');
return $query;
}
/**
* {@inheritdoc}
*/
protected function addAggregateExpression(SelectInterface $select) {
$select
->addExpression('COUNT(DISTINCT file_managed.fid)', 'records_count');
}
/**
* {@inheritdoc}
*/
public function buildTableHeader($rows = []) {
return [
t('ID'),
t('Filename'),
t('Usages'),
t('Status'),
];
}
/**
* {@inheritdoc}
*/
protected function buildTableRows(array $results) {
$entity_type_manager = \Drupal::entityTypeManager();
$rows = [];
foreach ($results as $delta => $row) {
$types = [];
$fid = $row->fid;
$file = File::load($fid);
/** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */
$file_usage = \Drupal::service('file.usage');
// List usages for the file.
foreach ($file_usage
->listUsage($file) as $usages) {
foreach ($usages as $type => $usage) {
foreach ($usage as $id => $value) {
// Check if the entity type has a definition for this type.
if ($entity_type_manager
->hasDefinition($type)) {
$entity = $entity_type_manager
->getStorage($type)
->load($id);
// Create the link.
if ($entity && $entity
->hasLinkTemplate('canonical')) {
$types[] = $entity
->toLink()
->toRenderable();
}
else {
$types[] = [
'#markup' => t('Missing @type/@id', [
'@type' => $type,
'@id' => $id,
]),
];
}
}
else {
$types[] = [
'#markup' => $type . '/' . $id,
];
}
// Separate the files usages list with a comma.
$types[] = [
'#markup' => ', ',
];
}
}
}
// If there are usages, format the rows to be rendered.
if (!empty($types)) {
// Delete the last unnecessary comma.
array_pop($types);
$filename = Link::fromTextAndUrl($file
->getFilename(), Url::fromUri(file_create_url($file
->getFileUri())));
$status = Link::createFromRoute('Make permanent', 'monitoring.make_file_permanent', [
'monitoring_sensor_config' => $this->sensorConfig
->id(),
'file' => $fid,
]);
$rows[] = [
'fid' => $fid,
'filename' => $filename,
'usages' => render($types),
'status' => $status,
];
}
}
return $rows;
}
/**
* {@inheritDoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['aggregation']['#access'] = FALSE;
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DatabaseAggregatorSensorPlugin:: |
protected | property | The arguments of the executed query. | |
DatabaseAggregatorSensorPlugin:: |
protected | property | The fetched object from the query result. | |
DatabaseAggregatorSensorPlugin:: |
protected | property | The arguments of the executed query. | |
DatabaseAggregatorSensorPlugin:: |
protected | property | The query string of the executed query. | |
DatabaseAggregatorSensorPlugin:: |
public | function | Add row to table when pressing 'Add another condition' and rebuild. | |
DatabaseAggregatorSensorPlugin:: |
public | function | Adds another field to the keys table when pressing 'Add another key'. | |
DatabaseAggregatorSensorPlugin:: |
public | function |
Calculates dependencies for the configured plugin. Overrides SensorPluginBase:: |
|
DatabaseAggregatorSensorPlugin:: |
public | function | Returns the updated 'conditions' fieldset for replacement by ajax. | |
DatabaseAggregatorSensorPlugin:: |
public | function | Returns the updated 'output_table' fieldset for replacement by ajax. | |
DatabaseAggregatorSensorPlugin:: |
protected | function | Provides list of operators for conditions. | |
DatabaseAggregatorSensorPlugin:: |
public | function |
Default configuration for a sensor. Overrides DatabaseAggregatorSensorPluginBase:: |
2 |
DatabaseAggregatorSensorPlugin:: |
protected | function | Builds history query over one db table. | |
DatabaseAggregatorSensorPlugin:: |
protected | function | Get the timestamp of the oldest entry that fits owr conditions. | |
DatabaseAggregatorSensorPlugin:: |
public | function |
Provide additional info about sensor call. Overrides ExtendedInfoSensorPluginInterface:: |
3 |
DatabaseAggregatorSensorPlugin:: |
public | function |
Runs the sensor, updating $sensor_result. Overrides SensorPluginInterface:: |
6 |
DatabaseAggregatorSensorPlugin:: |
public | function |
Form submission handler. Overrides DatabaseAggregatorSensorPluginBase:: |
|
DatabaseAggregatorSensorPlugin:: |
protected | function | Translates the string operators to SQL equivalents. | |
DatabaseAggregatorSensorPlugin:: |
public | function |
Form validation handler. Overrides SensorPluginBase:: |
|
DatabaseAggregatorSensorPlugin:: |
public | function | Adds history verbose output to the render array $output. | 1 |
DatabaseAggregatorSensorPlugin:: |
public | function | Adds unaggregated verbose output to the render array $output. | 1 |
DatabaseAggregatorSensorPluginBase:: |
protected | property | Allows plugins to control if a timestamp field can be configured. | 2 |
DatabaseAggregatorSensorPluginBase:: |
protected | property |
Allows plugins to control if the value type can be configured. Overrides SensorPluginBase:: |
|
DatabaseAggregatorSensorPluginBase:: |
protected | function | Gets conditions to be used in the select query. | |
DatabaseAggregatorSensorPluginBase:: |
protected | function | Gets the time field. | |
DatabaseAggregatorSensorPluginBase:: |
protected | function | Returns time interval options. | |
DatabaseAggregatorSensorPluginBase:: |
protected | function | Gets the time interval value. | |
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
SensorPluginBase:: |
protected | property | The plugin implementation definition. | |
SensorPluginBase:: |
protected | property | The plugin_id. | |
SensorPluginBase:: |
protected | property | Current sensor config object. | |
SensorPluginBase:: |
protected | property | ||
SensorPluginBase:: |
public | function |
Service setter. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public static | function |
Creates an instance of the sensor with config. Overrides SensorPluginInterface:: |
7 |
SensorPluginBase:: |
public | function |
Configurable value type. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets sensor name (not the label). Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
@todo: Replace with injection Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Determines if sensor is enabled. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
function | Instantiates a sensor object. | 8 | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TemporaryFilesUsagesSensorPlugin:: |
protected | property |
Allows plugins to control if the conditions table should be shown. Overrides DatabaseAggregatorSensorPlugin:: |
|
TemporaryFilesUsagesSensorPlugin:: |
protected | property |
Allows plugins to control if the table can be configured. Overrides DatabaseAggregatorSensorPlugin:: |
|
TemporaryFilesUsagesSensorPlugin:: |
protected | property |
Allows plugins to control if the verbose output table should be shown. Overrides DatabaseAggregatorSensorPlugin:: |
|
TemporaryFilesUsagesSensorPlugin:: |
protected | function |
Adds the aggregate expression to the select query. Overrides DatabaseAggregatorSensorPlugin:: |
|
TemporaryFilesUsagesSensorPlugin:: |
public | function |
Adds UI for variables table, conditions and keys. Overrides DatabaseAggregatorSensorPlugin:: |
|
TemporaryFilesUsagesSensorPlugin:: |
public | function |
Builds the header for a table based on rows. Overrides DatabaseAggregatorSensorPlugin:: |
|
TemporaryFilesUsagesSensorPlugin:: |
protected | function |
Builds the rows of a table. Overrides DatabaseAggregatorSensorPlugin:: |
|
TemporaryFilesUsagesSensorPlugin:: |
protected | function |
Builds simple aggregate query over one db table. Overrides DatabaseAggregatorSensorPlugin:: |
|
TemporaryFilesUsagesSensorPlugin:: |
protected | function |
Builds the query for verbose output. Overrides DatabaseAggregatorSensorPlugin:: |